Data AcQuisition And Real-Time Analysis
Scope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
The following is from the Daqarta Help system:



Spectrum Analyzer

Signal Generator

(Absolutely FREE!)


Pitch Tracker


DaqMusiq Generator
(Free Music... Forever!)

Engine Simulator

LCR Meter

Remote Operation

DC Measurements

True RMS Voltmeter

Sound Level Meter

Frequency Counter
    Spectral Event

    MHz Frequencies

Data Logger

Waveform Averager


Post-Stimulus Time
Histogram (PSTH)

THD Meter

IMD Meter

Precision Phase Meter

Pulse Meter

Macro System

Multi-Trace Arrays

Trigger Controls


Spectral Peak Track

Spectrum Limit Testing

Direct-to-Disk Recording



Frequency response

Distortion measurement

Speech and music

Microphone calibration

Loudspeaker test

Auditory phenomena

Musical instrument tuning

Animal sound

Evoked potentials

Rotating machinery


Product test

Contact us about
your application!

Macro Loops

Macros: WHILE, WEND, LoopBreak

Daqarta offers two general approaches to creating repeating macros: WHILE/WEND loops and invoked macro loops.


A WHILE/WEND loop is essentially an {\b IF} structure where the WHILE statement replaces the IF , and WEND replaces ENDIF. (There is no ELSE equivalent.) If the WHILE test is true, all the commands up to WEND are run, just like a normal IF/ENDIF. But then the WHILE test is run again and the process repeats. If the WHILE test is false, or becomes false on any pass, the commands are skipped and execution continues after the WEND.

WHILE and WEND (like IF and ENDIF) are regarded as macro prefixes, so each needs to be followed by a period.

As an example, the following uses a WHILE/WEND loop to create a simple 10-second countdown timer:

        Msg="Seconds remaining = " + A

In this example the A macro variable is initialized to 10, then the WHILE statement tests to see if A is above zero. If so, a message is displayed showing that value, followed by a delay of one second. Then A is decremented by one and the WHILE is repeated. Important: If you don't initialize this variable, or don't decrement it inside the loop, then it is easy to get stuck in a very long or even infinite loop. (If that happens, hit the Cancel button in the Macro Dialog.)

There is no requirement for a pre-defined number of counts; the WHILE can test for any arbitrary condition. You could repeat a set of operations until a certain key is pressed, or until a measured value exceeded a certain threshold, or until the result of some calculation converged to within a specified error limit.

You can also exit a WHILE loop early, based on a separate test or calculation within the loop itself that results in a LoopBreak=2 command.

Sometimes you may want an infinite loop which runs until cancelled manually, or until a LoopBreak=2 is given. You can do this by making the WHILE condition always true, such as WHILE.0=0.

WHILE loops can in principle contain nests up to 16 levels deeper (more indented) than the main WHILE. However, please note that this total includes invoked loops (see below), each of which acts as another level.

You can have an arbitrary number of WHILE statements at each level.

Invoked Macro Loops:

Invoked loops are easiest if you already have a named macro and want another macro to invoke it a certain number of times. Normally, a macro runs another macro by putting an '@' in front of it, so if you had a macro called _MyCount you could invoke it with:


If you want to run it 10 times, you would use:


So the WHILE/WEND countdown timer shown above could be implemented by creating a macro named _MyCount that consisted of all the commands between the WHILE and WEND. Then to invoke the timer from another macro, you would use:


If you later need a countdown with a different duration, just set A to the desired number of seconds and invoke again the same way.

Note that there is no testing going on here; the value or expression after the equal sign is evaluated only once, and that determines the number of times the @ macro is run. For example, if you used:


The counter would still start at 10, but only count down to 6. Similarly, if you set the value after the equal larger than A, the counter could run to negative numbers.

Macros can include other macros that are themselves run as loops. These can be nested up 16 levels deep, with an arbitrary number of invoked macro loops at any level. (Note, however, that this total includes WHILE loops, each of which counts as a separate level if nested.)

Invoked macro loops can be exited early, on the basis of some test within the looped macro that results in a LoopBreak=1 command. For example, suppose you want to run _MyMacro up to 20 times, using @_MyMacro=20. Each time, _MyMacro will itself run another macro called _MyTest that collects some data and saves it to a file.

After each _MyTest finishes, _MyMacro must increment the Left Stream 0 Tone Frequency by 500 Hz using a preset frequency step size. However, you want to allow _MyMacro to be started from any arbitrary frequency, but never to go above 5000 Hz.

The definition of _MyMacro would look like:


If for some reason you want to keep track of how many times _MyMacro actually runs, you can include a command that increments a macro variable which you can then test with later IF statements, or display in a message or a Field.

The current loop counter is returned by reading LoopBreak as a variable. This value will count to zero down from the requested number of loop passes.

See also Macro Overview


Questions? Comments? Contact us!

We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2017 by Interstellar Research
All rights reserved