Page 1 of 1

Array as subroutine's parameter

Posted: Thu Aug 02, 2007 7:04 pm
by k7
Elo. What is the correct way to declare an array in a subroutine's parameters in FB? Is it possible to define the dimensions and size of the array when declaring it, as I can't find any help on this in the documentation. Currently I am using one like this:

Code: Select all

sub drawimage (img_to_load())
    size = ubound (img_to_load, 1)
    ...
end sub
I use UBOUND to determine the size of the passed array. A specific size for the parameter array isn't relevant to my current project, but is it possible to declare one?

Posted: Thu Aug 02, 2007 10:45 pm
by Anonymous
I'm not sure if FB can do that, you should post on the FB forums at http://www.freebasic.net/forum/index.php
freebasic.net forums

You could just DIM SHARED the array so that it is accessable in all the subs.

Posted: Fri Aug 03, 2007 9:32 am
by Erik
Idk about free basic but you can do it in old Qbasic like so:

Code: Select all

'main
CLS

DIM the(0 TO 60) AS INTEGER

FOR i% = 0 TO 60 'just filling the array...
  the(i%) = 5
NEXT i%

CALL test(the())

END

'sub
SUB test (thePassed%())

FOR i% = 0 TO 60            'dumping to screen to verify it worked.
  PRINT thePassed%(i%)
NEXT i%

END SUB
Hope this helps...