Array as subroutine's parameter

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
k7
Coder
Posts: 41
Joined: Wed Aug 01, 2007 7:38 am
Location: Tasmania, Australia
Contact:

Array as subroutine's parameter

Post 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?
Anonymous

Post 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.
Erik
Veteran
Posts: 72
Joined: Wed Jun 20, 2007 12:31 pm
Location: LI, NY
Contact:

Post 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...
Post Reply