
Null variable while calling cmpstr

Jakub
Hello,
I am loading some data using this function:
LoadWave/J/M/Q/D/A=wave/K=0/L={0,1,0,0,0} outputPaths string wave3
then I try to use the wave3 string here:
if (cmpstr(wave3[6],"dCm [mg/m³]")) threshold=10 elseif (cmpstr(wave3[6],"dCn [p/cm³]")) threshold=1000 endif
but this results in the debugger stropping the code execution with an error "attempt to use a null string variable" at the if statement. Why the wave3 variable is null and how to solve this issue? Is this perhaps because I use a reference?
Thank you.
If "wave3" is a text wave, i.e. contains string content, you'll need to reference it with: wave/T wave3
July 26, 2022 at 08:19 am - Permalink
Also, you should make sure your if-statements does as intended. Cmpstr() gives 0 for an exact match, so what you are writing is essentially 'if no match do this'. Maybe you mean if (cmpstr(...) == 0)?
July 26, 2022 at 09:33 am - Permalink
You defined a string named "wave3" but never assigned a value to the string; it *is* null.
Are you expecting wave3 to initialize itself from the preceding LoadWave command? That's not how it works.
Maybe you are missing something like:
But I have no idea what you are trying to do with:
if you have "wave3" as the *value* of a local string variable *named* "wave3" (which is unnecessarily obscure), the single character wave3[6] is blank ("") because "wave3" has only 5 characters in it.
And a single character will never compare equal to "dCm [mg/m³]".
Also, a string equality test is
July 26, 2022 at 01:40 pm - Permalink