Array Builder Macro

Array Builder Macro

2
NewbieNewbie
2

    Aug 22, 2005#1

    I occasionally have to build array definitions for VBA in the form
    Array(1) = "Some Text"
    Array(2) = "Some More Text"
    and so forth.

    I wrote the following macro to help me do this. It assumes the current document contains the text you want in quotes, on separate lines. As in:

    Some Text
    Some More Text
    Yet Another Line

    The macro creates an empty file, sticks one blank line in it for each line in the current document, then uses the ColumnInsertNum to generate the array indices. It then repeats back through the current document, modifying the lines as appropriate. It quits when it reaches the end of the array indices file.

    I suspect the execution time of this macro would be large if the files were large, but I typically use this on files of 30 lines or so, so it's not too bad.

    It will work with numbers - just use search and replace to remove the quotes.

    The macro is:

    =======================

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    NewFile
    PreviousDocument
    Top
    Loop
    IfEof
    ExitLoop
    EndIf
    NextDocument
    InsertLine
    PreviousDocument
    Key DOWN ARROW
    EndLoop
    Top
    NextDocument
    Top
    ColumnInsertNum 1 1
    PreviousDocument
    Loop
    NextDocument
    Top
    IfEof
    CloseFile NoSave
    ExitLoop
    EndIf
    SelectLine
    Cut
    PreviousDocument
    "Array("
    Paste
    Key BACKSPACE
    ") = ""
    Key END
    """
    Key DOWN ARROW
    Key HOME
    EndLoop

    =======================

    Have fun....

    Bob

    1
    NewbieNewbie
    1

      May 22, 2009#2

      Thanks for sharing this handy script. This is exactly what I came to the forum to find, and for the same purpose even.