PDA

View Full Version : Can a Session Variable have multiple values?



howardtlcc
08-28-2009, 01:52 PM
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

pww
08-29-2009, 10:39 AM
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

howardtlcc
09-01-2009, 10:13 AM
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

pww
09-01-2009, 03:43 PM
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.

howardtlcc
09-01-2009, 03:52 PM
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

Ulrich
09-01-2009, 05:37 PM
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...



--[[
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