Null variable while calling cmpstr

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 

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)?

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:

 

LoadWave/J/M/Q/D/A=wave/K=0/L={0,1,0,0,0} outputPaths
String wave3 = StringFromList(3,S_waveNames) // expecting S_waveNames to be "wave0;wave1;wave2;wave3;"

But I have no idea what you are trying to do with:

if (cmpstr(wave3[6],"dCm [mg/m³]"))

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

if (CmpStr(wave3,"dCm [mg/m³]") == 0 ) // == 0 means the texts are not lexically different
    ... do something because they're equal
endif