none
Execute a variable assignment RRS feed

  • Question

  • Hello

    starting from  arraylines such as 

    Field[4] = "Box=Input;Info=OutputFile;action=D:\small-basic\Myfile"

    I need the variable "outputfile" equal to "D:\small-basic\Myfile" to be passed  to subroutines

    so starting from the array-line I need to encode something as 

    OutputFile="D:\small-basic\Myfile"

    I don't know but I thought composing and executing a command from inside sb isn't possible.

    Another question is redirection such as in ksh "cmd< dir>output" , etc.

    thanks

    Monday, February 11, 2019 8:41 PM

Answers

  • What you have is a 2D array.

    First note that \ is a special character when defining arrays as strings, it is an 'escape' character.  Also = and ; are special characters.

    To see how escape characters work create the arrays using [] notation.

    In your case:

    Field[4] = "Box=Input;Info=OutputFile;action=D:\small-basic\Myfile"
    TextWindow.WriteLine(Field[4]["action"])

    gives:

    D:small-basicMyfile

    which is not what yo want.  To get \ in an array it needs to be 'escaped' properly.

    Try the following - note \\ to espacpe the \ character:

    Field[4] = "Box=Input;Info=OutputFile;action=D:\\small-basic\\Myfile"
    TextWindow.WriteLine(Field[4]["action"])

    Or, assign using [] notation.

    Field[4]["action"]= "D:\small-basic\Myfile"
    TextWindow.WriteLine(Field[4]["action"])

    Or even use / which works in paths, but is not a special character for SB array strings

    Field[4] = "Box=Input;Info=OutputFile;action=D:/small-basic/Myfile"
    TextWindow.WriteLine(Field[4]["action"])

    Monday, February 11, 2019 9:05 PM
    Moderator