Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Posts
    11

    Can a Session Variable have multiple values?

    I want to have a Session variable that has multiple values that can be read from a script. Can this be done? I could always create my own separator and parse it out but I want to find the easiest way...

    Related question... Can the combobox or listbox choices be populated via Script? I need to present a list of choices to the user and these choices are not known until the user runs the program and script determines the valid values?

    thanks,

    Howard

  2. #2
    Join Date
    Jun 2005
    Posts
    470
    you can always change the value of a session variable, but I doubt you can have an array as a session variable. Not sure though.
    Why not normal variables?

    As for filling list/combo boxes with a script, that's possible.
    See for example the help file about DlgListBox.AddItem or .InsertItem

  3. #3
    Join Date
    Jul 2009
    Posts
    11
    Quote Originally Posted by pww View Post
    you can always change the value of a session variable, but I doubt you can have an array as a session variable. Not sure though.
    Why not normal variables?

    As for filling list/combo boxes with a script, that's possible.
    See for example the help file about DlgListBox.AddItem or .InsertItem
    I want to be able to have a session variable that has a variable number of version numbers (like 6.5,5.0,4.0). Then I need to parse these into a table (array). I got something going in script to do the parsing but was hoping there was a more native way to do this. Such as:

    Suppose I had a session variable called %versions% and then in code I could declare a table like:

    sessionvar = get the value of the session variable...
    myversions = { .. sessionvar .. }

    Is there some way to evaluate the string as code at runtime?

    Howard

  4. #4
    Join Date
    Jun 2005
    Posts
    470
    I think it should be done with some scripting, don't see a direct way.
    If versions are like 6.5,5.0,4.0, a simple way would be to replace comma with CR+LF, save to txt file and read that file to a table with TextFile.ReadToTable()

    BTW it's amazing that there is no built-in function to create a table from a string but only from a txt file, and that it's not possible to specify another separator.

  5. #5
    Join Date
    Jul 2009
    Posts
    11
    ok, thanks, I just parsed the string into an array.

    I agree, a way to split a string into a table would be great...

    Howard

  6. #6
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Quote Originally Posted by pww View Post
    BTW it's amazing that there is no built-in function to create a table from a string but only from a txt file, and that it's not possible to specify another separator.
    Well, we have DelimitedStringToTable() for this, kindly made by the Indigo Rose staff...

    Code:
    --[[
    Function: DelimitedStringToTable
    Purpose: Breaks up a string given a delimiter into a table
    Arguments: DelimitedString - The string to parse
               Delimiter - The delimiter
    Returns: A numerically indexed table with the string elements
    Example:
    
    string = "Brett,Mark,Darryl,Lorne,Adam";
    tbResults = DelimitedStringToTable(string,",");
    for i, name in tbResults do
        Dialog.Message("Name",name);
    end
    
    ]]--
    function DelimitedStringToTable(DelimitedString, Delimiter)
    	tbReturn = {};
    	local strWorking;
    	local nPos = nil;
    	local strData;
    	local nTableIndex = 1;
    	local nDelimiterLength = String.Length(Delimiter);
    	
    	if(nDelimiterLength < 1)then
    		tbReturn[nTableIndex] = DelimitedString;
    		return tbReturn;
    	end
    	
    	strWorking = DelimitedString;
    	nPos = String.Find(strWorking,Delimiter);
    	while(nPos ~= -1)do
    		strData = String.Left(strWorking,nPos-1);
    		tbReturn[nTableIndex] = strData;
    		nTableIndex = nTableIndex + 1;
    		local nLength = String.Length(strWorking);
    		strWorking = String.Right(strWorking,nLength - (nPos + (nDelimiterLength-1)));
    		nPos = String.Find(strWorking,Delimiter);
    	end
    	if(strWorking ~= "")then
    		tbReturn[nTableIndex] = strWorking;
    	end
    	
    	return tbReturn;
    end
    
    --[[
    Function: TableToDelimitedString
    Purpose: Makes a table into a delimited string
    Arguments: Table - The table to make into a string
               Delimiter - The delimiter
    Returns: A delimited string of the table elements
    Example:
    
    tbNames = {};
    tbNames[1] = "Brett";
    tbNames[2] = "Mark";
    tbNames[3] = "Darryl";
    tbNames[4] = "Lorne";
    tbNames[5] = "Adam";
    
    strOutput = TableToDelimitedString(tbNames,",");
    Dialog.Message("Result",strOutput);
    
    ]]--
    function TableToDelimitedString(Table, Delimiter)
    	strReturn = "";
    	for i, item in Table do
    		strReturn = strReturn..item..Delimiter;
    	end
    	strReturn = String.TrimRight(strReturn,Delimiter);
    	return strReturn;
    end
    Ulrich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts