How do I call for a user defined string from a different function?
I don't have much experience with programming but I have been looking all over the place on how to use a user-defined string variable in another function. I have made the variable global and have tried several methods to call for it and I keep getting the error "While executing a user function, the following error occurred: attempt to use a null string variable."
The program prompts the user to enter the sample name in the first function as soon as you start the program. I took that string variable and defined it as a new global string.
string sampleName, ADC, Rwave, Cwave, Vwave, Twave, Analysis, Wstats, folderName
variable sampleThickness, workingDiameter, scalar, n, jumper, i
NewDataFolder/O/S Sample
LoadInFile()
....
Prompt sampleName, "Enter sample name"
DoPrompt "Sample Name", sampleName
string/G gSampleName = sampleName
I am now making a function to call within a macro for each time I create a new graph, and I want it to take that sampleName and reuse it in the title. When I run this macro I get the error and the title shows up with everything correct, except it doesn't include the sample name.
string voltageStep
SVAR gSampleName=gSampleName
Prompt voltageStep, "Enter voltage value"
DoPrompt "Voltage Value", voltageStep
String titleText
sprintf titleText, "%s Conductivity at %s V (Baked, Log-Log)", gSampleName, voltageStep
TextBox/A=MT/E/C/N=Title/F=0 titleText
End
When I check the data browser, it shows that "gSampleName" does equal the variable that the user defines, so I don't know why it is saying the variable is "null" when it isn't, so I must be calling it wrong. Anyone know what the problem could be?
And is case this might be relevent, LoadInFile() is
LoadWave/G/W
End
Hi,
One thing I would check is to see if gSampleName is in the active directory. I see a NewDataFolder command in the function where it is defined.
If for some reason the current directory is switched it will not find it.
Andy
June 18, 2021 at 12:08 pm - Permalink
In reply to Hi, One thing I would check… by hegedus
THANK YOU! I don't understand all of this very well but I immediately knew what I needed to do once you said that.
All I did was change it to
and now it works great! Thanks!
June 18, 2021 at 12:32 pm - Permalink
Good my work here is done.
Andy
June 18, 2021 at 12:42 pm - Permalink
@hegedus And you can ride off into the sunset!
June 18, 2021 at 05:12 pm - Permalink