Unable to execute Function within Macro

I have an existing Macro that I'm trying to modify to fit my purposes. As part of that, I've written a Function that will determine whether there are any unit conversions necessary to get my waves into SI units, and then create a new wave in the proper units. I've written this function into my Macro, and it works fine when I run it separately, but it doesn't do anything when written as a line in my Macro.

The general format is:

Macro MacroName([variables])
[define variables]
               Function ConvertToSIUnits(w, loopnumber)
               [create new waves in SI units]
               End
     Do
          ConvertToSIUnits ("wavename", loopnumber)
          [calculations on created waves]
     While [loopnumber still makes sense]
End


I've tested the Function on its own in the Command Window with actual waves and numbers, and it works fine. Enter exactly the same code into the Macro, and it no longer works, and throws no error messages. Once I get this working I'd like to generalize so the number can be replaced by i, a loop variable.


Why dont you define your function outside your macro?
what surprises me is that your function is defined in a macro. I never do like this. I dont have igor at hand so I can not test it. If this function defination way works, it would be realy great: one can create functions in run time!
The reason I wanted to define the function within the macro is because the macro can't run without the function. The function creates the wave that the macro uses in its calculations. The function needs to be run in each loop because each wave needs to be created in the correct units.

Hope that helps.
Neurons wrote:
The reason I wanted to define the function within the macro is because the macro can't run without the function. The function creates the wave that the macro uses in its calculations. The function needs to be run in each loop because each wave needs to be created in the correct units.

Hope that helps.

define the function outside macro, call the function in the loop in the macro. you can pass the wave you want to recalculate to the function by wave reference. in macro, you can reference wave just using wave names.
You can not define a function in a macro or in another function. Igor does not supported nested procedure definitions.

With rare exceptions (mostly recreation macros), you should not use macros at all. For details, execute:
DisplayHelpTopic "Macros"