none
Any other suggestion? please bear with me RRS feed

  • Question

  • Hi all

    I am sorry, i spent a lot of time trying to have the code Doug suggested but in vain this code does not handle the iterating of characters properly, it considers a space as a character and it joins the characters to each other in the iteration lines (not a wished thing) :

    Dim i As Long, j As Long
    Dim rng As Range
    Dim str As String
    Set rng = ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range
    rng.End = rng.End - 1
    For i = 2 To rng.Characters.Count + 1
        str = ""
        If rng.Characters.Count Mod 2 = 1 Then
            For j = rng.Characters.Count To rng.Characters.Count / 2 + 1 Step -1
                str = str & rng.Characters(j) & rng.Characters(rng.Characters.Count - j + 1)
            Next j
            str = str & rng.Characters(Int(rng.Characters.Count / 2) + 1)
        Else
            For j = rng.Characters.Count To rng.Characters.Count / 2 + 1 Step -1
                str = str & rng.Characters(j) & rng.Characters(rng.Characters.Count - j + 1)
            Next j
        End If
        rng = rng & vbCr & str
        Set rng = ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range
        rng.End = rng.End - 1
    Next i


    More important i could only have work once and could not have it work since, so there is something missing i spent a lot of time but could not figure out the bug,

    Can anybody help correct the code or suggest a new formula, would be greatly appreciated

    thanks 

    Thursday, September 22, 2011 10:19 PM

Answers

  • Try this version:

    Sub TestME()
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        Dim rng As Range
        Dim str As String
        Dim Cycles As Integer
        Dim myLen As Integer

        Set rng = ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range
        rng.End = rng.End - 1

        Cycles = (rng.Characters.Count + 1) \ 2
        myLen = rng.Characters.Count
        For k = 1 To Cycles
            str = ""
            For i = 1 To Cycles Step 2
                j = myLen - i + 1
                If i < j Then
                    str = str & rng.Characters(j) & " " & rng.Characters(i) & " "
                End If
                If i = j Then
                    str = str & rng.Characters(j) & " "
                End If
            Next i
            str = Left(str, Len(str) - 1)
            rng = rng & vbCr & str
            Set rng = ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range
            rng.End = rng.End - 1
        Next k
    End Sub


    HTH, Bernie
    Friday, September 23, 2011 2:23 PM

All replies

  • Try this version:

    Sub TestME()
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        Dim rng As Range
        Dim str As String
        Dim Cycles As Integer
        Dim myLen As Integer

        Set rng = ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range
        rng.End = rng.End - 1

        Cycles = (rng.Characters.Count + 1) \ 2
        myLen = rng.Characters.Count
        For k = 1 To Cycles
            str = ""
            For i = 1 To Cycles Step 2
                j = myLen - i + 1
                If i < j Then
                    str = str & rng.Characters(j) & " " & rng.Characters(i) & " "
                End If
                If i = j Then
                    str = str & rng.Characters(j) & " "
                End If
            Next i
            str = Left(str, Len(str) - 1)
            rng = rng & vbCr & str
            Set rng = ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range
            rng.End = rng.End - 1
        Next k
    End Sub


    HTH, Bernie
    Friday, September 23, 2011 2:23 PM
  • Hi Bernie

    Thank you for your input

    Well i placed the code in VB Editor, saved it in the code page and started the Macro but nothing happened

    I noticed then when i select the area below the paragraph i see the engine tried to do something but no text to be seen 

    I thank you for your contribution

    cheers 

     


    • Edited by Hosny BA Saturday, September 24, 2011 5:49 PM
    Saturday, September 24, 2011 5:49 PM
  • Yuor last paragraph cannot have any text (spaces) or carriage returns, line-breaks, or page -breaks after it. Place your cursor to the right of the last character, and press Delete repeatedly to clear those extra items.

     


    HTH, Bernie
    Saturday, September 24, 2011 9:37 PM
  • Hi Bernie,

    Thank you Sir for pointing the fact i have to press Delete after placing the cursor next to last character. Now i could have the code Doug posted in the other thread thanks to your advice.

    Even though i forgot to mention that i always separate the characters before beginning the iteration in order to have neat clear lines. I noticed that the code you posted starts good in the first instance but during the iteration it gets confused because your code inserts a space between characters (very good thing) but at the same the macro starts treating the newly created space in iterating lines as a character? thus loosing the appropriate order of iteration

    I saw in the older thread that Doug posted a new reply where he modified the code, haven't tried yet ... 

    Since, each time i type the input (first paragraph) than i insert a space between all characters, what would be the best method to use in the input text to keep the initial characters spaced and the iteration lines too, "indent" may be?

      I will test the new code posted by Doug recently and let you know,

    Again thank you Sir for your help

     

    Hosny BA
    Monday, September 26, 2011 9:32 PM