Hello everyone I just joined the forum today even though I'm using DBPro for over 3 years now. The reason that I joined is that I could post this snippet. It shows a way to return multiple variables from a function with the use of pointers. I found out how to do this when I was learning how to use functions in C. In C you can use the "&"-symbol to return the adress of a variable. Unfortenately you can't do this in DBPro, so I had to use
the make memory command since that does return a adress in memory. How the rest of the code works is explained in the code snippet.
`Store memory adresses in a and b.
a = make memory(4)
b = make memory(4)
`Give a the value 2 and b the value 3.
*a = 2
*b = 3
`Show the values on screen.
print "a:",*a
print "b:",*b
`Swap the values of a and b.
swap(a,b)
`Show on screen that the values have
`indeed been changed.
print "a:",*a
print "b:",*b
wait key
end
function swap(r1,r2)
`The trick of the function is that the r1 and r2
`variables are the adresses of a and b. Wich means
`that *a = *r1 and *b = *r2. t is just a temporary
`variable.
t = *r1
*r1 = *r2
*r2 = t
endfunction
I hope that a lott of you will find this code usefull.
Don't read this, read the above.