Q: About "DoPrompt" with variable numbers of parameters
yaohualiu
For examples:
I have a string contains a list of wave names, like "wave0; wave1; wave2;". For each wave, I want an input from the user. The interface will be much simple if I can do DoPrompt for all the waves at a single window. I firstly tried to use Prompt in a "For, Endfor" Loop and pass a data point of one wave to each Prompt, however it does not work. I.e. I can not do thing like this // Prompt INPUTWAVE[index], "input a numer" //
I also tried to make a string variable, // STRING Localstring="input"+index // and want to claim a numerical variable with the name same as the string content (inside the loop). In this way , I can pass the numerical variable to PROMPT. However it do not allow me to do so.
Below is a FAILED example"
Function test(datawavelist)
String datawavelist
Variable waveindex
String CMD="DoPrompt \"Please Input \" "
For (waveindex=0; waveindex < itemsinlist(DataWaveList); waveindex +=1)
string Input = "input"+num2str(waveindex)
Variable $Input //ERROR
// Igor does not allow me to do this. A string can not be a variable name. Do not know how to do this.
String Promptcmd
Sprintf Promptcmd, "Prompt %s, \"Input for Data Wave %s\" ", Input, stringfromlist(waveindex, Datawavelist)
Execute Promptcmd //ERROR
// Here is the problem, the variable is not claimed"
String subcmd
sprintf subcmd, ", %s", Input
CMD += subcmd
Endfor
Execute CMD
End
String wl // list of waves
if( strlen(wl) == 0 )
return -1
endif
Variable nw= ItemsInList(wl)
if( nw > 3 )
abort "too many items"
endif
Variable var1, var2, var3
Prompt var1,"enter var 1"
Prompt var2,"enter var 2"
Prompt var3,"enter var 3"
switch( nw )
case 1:
DoPrompt "enter something",var1
break
case 2:
DoPrompt "enter something",var1, var2
break
case 3:
DoPrompt "enter something",var1, var2, var3
break
endswitch
print var1,var2,var3
end
August 3, 2009 at 01:53 pm - Permalink
This is nice, however has a very clear limitation. The maximum number of items is fixed. It may cause a trouble if the number of the waves varys from 1 to 100. :-)
I need someway to create variables in a LOOP and these variables have the memory of in which loop they are created, basing on their name. That is why I tried to pass a data point of a Wave to the PROMPT cmd.
August 3, 2009 at 02:21 pm - Permalink
True, but keep in mind that DoPrompt itself can only be used to prompt the user for up to 10 variables. So if you really have up to 100 waves what you want to do isn't possible using DoPrompt. I think you would need to make a panel (perhaps with a list box) instead.
August 3, 2009 at 03:00 pm - Permalink
How about prompting for a string list and then parsing ...
variable nv
string pStr = "", iStr = "", hStr = "Use semicolons to separate your input values. Too many or too few will continue to prompt."
sprintf pStr, "Input %d numeric values using semicolon separation :", nv
prompt iStr, pStr
do
DoPrompt/HELP=hStr "Input Values", iStr
if (V_flag==1)
iStr = ""
break
endif
if (ItemsInList(iStr)==nv)
break
endif
DoAlert 0, "Inconsistent number of input values!"
while(1)
return iStr
end
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
August 3, 2009 at 03:33 pm - Permalink