locked
Can anybody else help please! RRS feed

  • Question

  • Hi all

    Last week i posted a question asking help for the right code for a macro to iterate characters of a text in word document, Doug was kind enough to post a code but it did not work anybody else please help?

    Basically what i want the macro to perform is to iterate the characters of a paragraph ( the paragraph and its length is not always the same), also note the characters are always spaced from each other. The order of iteration the Macro should execute is to take the last character of the previous paragraph (text) and place it in the first position, then the first character goes in position 2, the before last character goes in 3 rd position and the second character goes to position 4 and so on ...

    Whenever the order of the first paragraph reoccurs that's the end of iteration, i mean like this:
    T H I S I S T H E I N P U T
    T T U H P I N S I I E S H T
    T T H T S U E H I P I I S N
    N T S T I H I T P S I U H E
    .........
    ..........

    T H I S I S T H E I N P U T
    ---------------------
    (end)

    Any help will be greatly appreciated!

     

    Thank you

     

    • Moved by Kee Poppy Friday, September 30, 2011 3:03 AM (From:Visual Basic General)
    Thursday, September 22, 2011 5:29 PM

Answers

  • I 'll try to see what i can do with the psudocode you posted


    You may have a little difficulty doing that, because VBA does not support queues.  If you ask your question in a more appropriate forum you are more likely to get responses that are suitable for the environment you are coding in.

    But in any case your description of the problem you experienced using the code already provided does not correspond with the response you have provideed in your original thread. Dealing with two separate discussions about how to fix the errors in the same bit of code is pretty much guaranteed to create confusion.


    • Edited by Acamar Friday, September 23, 2011 12:00 AM sp
    • Proposed as answer by Frank L. Smith Friday, September 23, 2011 12:04 AM
    • Marked as answer by danishani Tuesday, January 31, 2012 5:26 PM
    Thursday, September 22, 2011 11:59 PM
  • This forum deals with VB.NET; it looks like you want a forum that deals with VBA, for example

    http://social.msdn.microsoft.com/forums/en/isvvba/threads

    --
    Andrew

    • Proposed as answer by John Anthony Oliver Thursday, September 22, 2011 8:35 PM
    • Marked as answer by danishani Tuesday, January 31, 2012 5:26 PM
    Thursday, September 22, 2011 7:11 PM

All replies

  • Are you tring to do this directly in Word or are you trying to use Visual Basic.NET to automate word and perform this task?
    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    Thursday, September 22, 2011 5:53 PM
  • My first instinct is to use a Queue of characters.

    Read in the input line, split on spaces, and then insert each character into a queue.  Once you've done that, here is some psudocode:

    for i = 0 to characterCount

      queue.enqueue(queue.dequeue())

      //print out queue to screen

    next

    Thursday, September 22, 2011 5:57 PM
  • Hi kleinma

    Yes i am doing this in word since i am using word to enter the text, no i am not using Visual Basic.Net

    I use option : Tools > Macros ... and would like to paste the right code straight into the VB Editor

    Thanks

    Thursday, September 22, 2011 6:58 PM
  • Hello servy42

    Thank you for your insight , but to be honest my VBA programming skill is nearly zero, 

    I mean if it was a matter of a simple Macro which will insert a text that's not too complicated but the Macro i am talking about involves variants and ranges ... that is the reason i am asking for help

    I 'll try to see what i can do with the psudocode you posted

    Doug posted this code :

     

    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

    And copied and paste it to VB Editor but whenever i run the Macro nothing happens, i only had it once running with a small text but could not have it to work since. I noticed that this code is missing few things, for instance it considers a space a character, then it attaches characters to each other and does not execute the proper iterating of characters ...alas

     

    Thank you


    • Edited by Hosny BA Thursday, September 22, 2011 7:15 PM
    Thursday, September 22, 2011 7:05 PM
  • This forum deals with VB.NET; it looks like you want a forum that deals with VBA, for example

    http://social.msdn.microsoft.com/forums/en/isvvba/threads

    --
    Andrew

    • Proposed as answer by John Anthony Oliver Thursday, September 22, 2011 8:35 PM
    • Marked as answer by danishani Tuesday, January 31, 2012 5:26 PM
    Thursday, September 22, 2011 7:11 PM
  • I 'll try to see what i can do with the psudocode you posted


    You may have a little difficulty doing that, because VBA does not support queues.  If you ask your question in a more appropriate forum you are more likely to get responses that are suitable for the environment you are coding in.

    But in any case your description of the problem you experienced using the code already provided does not correspond with the response you have provideed in your original thread. Dealing with two separate discussions about how to fix the errors in the same bit of code is pretty much guaranteed to create confusion.


    • Edited by Acamar Friday, September 23, 2011 12:00 AM sp
    • Proposed as answer by Frank L. Smith Friday, September 23, 2011 12:04 AM
    • Marked as answer by danishani Tuesday, January 31, 2012 5:26 PM
    Thursday, September 22, 2011 11:59 PM