1 option base 1 5 dim src%(50), dst%(50) 10 srcoff% = varptr(src%) 15 srcseg% = seg 20 dstoff% = varptr(dst%) 25 dstseg% = seg 30 for i% = 1 to 100 35 def seg = srcseg% 40 temp% = peek(srcoff%) 45 def seg = dstseg% 50 poke dstoff%, temp% 55 srcoff% = srcoff% + 1 60 if srcoff% = 0% then srcseg% = srcseg% + 1% 65 dstoff% = dstoff% +1 70 if dstoff% = 0% then dstseg% = dstseg% + 1% 80 next i%The example illustrates the use of varptr in an unusual means of copying the array src% to the array dst%. Varptr is used in lines 10 and 20 to assign the lower 16-bits of the 32-bit addresses (the offsets) to the variables srcoff% and dstoff%. The value of seg (the high-order 16-bits of the addresses) for each of the arrays is saved (in lines 15 and 20) in the variables srcseg% and dstseg% for later use in lines 35 and 45. The for...next loop (lines 30-80) increment the offsets (lines 55 and 65) and check for segment incrementing (lines 60 and 70). The poke (line 50) effects the swap. Of course, there are better ways to copy arrays. This method is shown only to illustrate the varptr function.
from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber