"Can't use $ in this way in a function"

Hi all, undergrad student here doing summer physics research work. I'm trying to load a wave so that I can index it and use it in < and > comparisons. The wave is initialized under the
Function SwWave(a bunch of parameters)
Wave PositiveWave, NegativeWave

I use Sprintf to make strings that correspond to two wave names. The strings are called PosWavename and NegWavename and correspond to data waves that I have.
Before doing the comparisons, I try to set the value of these waves equal to the waves defined earlier as PositiveWave and Negative Wave

PositiveWave=$PosWavename
NegativeWave=$NegWavename

It fails at this point and gives me the error, "Can't use $ in this way in a function". If anyone has any knowledge that could help I'd greatly appreciate it.

Also attached the file, just in case my barebones description wasn't enough.
SeparatingPeaksByFolder.ipf (3.3 KB)
Note: You can use the <igor> and </igor> tags to show code in your posting. See http://www.igorexchange.com/node/3221#comment-1

Your code has statements like this:
SVAR PosFilename, NegFilename, PosLowWave, PosMediumWave, PosLargeWave, NegLowWave, NegMediumWave, NegLargeWave
Wave PositiveWave,NegativeWave
Sprintf PosWavename "%s%-5.3f", PosWavePrefix, Temperature[h] // Your code does not contain the needed String PosWavename statement to create a local string
...
PositiveWave=$PosWavename


It is important to remember that a WAVE statement is BOTH a declaration AND an assignment, so

String PosWavename
Sprintf PosWavename "%s%-5.3f", PosWavePrefix, Temperature[h]
...
Wave PositiveWave
PostiveWave= $PosWavename // wrong, Igor thinks you're trying to modify the CONTENTS of a global wave named PositiveWave

is different than:
String PosWavename
Sprintf PosWavename "%s%-5.3f", PosWavePrefix, Temperature[h]
...
Wave PostiveWave= $PosWavename // right, Igor understands you're creating a local reference to a global wave using the name stored in the local PosWavename string.


And I'm not a big fan of passing parameters into a function through global strings like SVAR; that's what function parameter arguments are for.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
thanks jim, i had a similar problem, and your answer is great because it explains the reasoning behind the syntax.