First, why not something like the following:
` Place this in the initialisation part of your program
global ImageIndex as integer = 0
` Function can be placed anywhere
function IMAGE(Src as string)
inc ImageIndex
load image Src, ImageIndex
endfunction ImageIndex
Alternatively, if you still want to do it like you have in your pseudo code:
function IMAGE(Src as string)
if ImageIndexInitialised = 0
global ImageIndexInitialised = 1
global ImageIndex = 1
else
inc ImageIndex
endif
load image Src, ImageIndex
endfunction ImageIndex
That may look a little weird, as the ImageIndexInitialised is used before you declare it, but you need to take into account DBPro's 2-phase variable initialisation.
During the compile, all global variables are allocated space, and are set to either zero for numbers, or the empty string for strings. When you run the program, the values are still set to zero, until the flow of execution actually runs through the variable declaration.
So at program start, ImageIndexInitialised is set to zero. When the program first reaches this line:
if ImageIndexInitialised = 0
the comparison succeeds and passed into the first part of the IF statement.
The next line then sets the variable to 1:
global ImageIndexInitialised = 1
The next time the IF statement is reached, the comparison will fail and drop into the ELSE section of the IF statement.
All variables work in this way, most importantly so do DIM statements - the array doesn't have any storage allocated to it until you run through the DIM statement at runtime.
Hopefully I haven't confused you, but I get the impression you aren't really a total beginner in programming in general