Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass two arrays into a sub-program?

Status
Not open for further replies.

Grozny

Programmer
Jan 27, 2010
5
0
0
US
I can pass one array into a sub-program, but not two arrays. Can anybody here tell me what is wrong with the following code?

DECLARE SUB subroutine (a1(), a2() AS INTEGER)
DIM array1(0 TO 12) AS INTEGER
DIM array2(0 TO 3, 0 TO 4) AS INTEGER
subroutine array1(), array2()

SUB subroutine (a1(), a2() AS INTEGER) STATIC
´ does something with two arrays
END SUB

 
You have a few syntax errors. It's been quite a few years since I've used QBASIC but this runs in QuickBasic 1.1 and 4.5

Code:
 DECLARE SUB subroutine (a1() AS INTEGER, a2() AS INTEGER)

 DIM array1(0 TO 12) AS INTEGER
 DIM array2(0 TO 3, 0 TO 4) AS INTEGER

 DECLARE SUB subroutine (array1() AS INTEGER, array2() AS INTEGER)


 DIM x AS INTEGER, y AS INTEGER



 FOR x = 0 TO 12
   array1(x) = x
 NEXT

 FOR x = 0 TO 3
   FOR y = 0 TO 4
     array2(x, y) = x * 100 + y
   NEXT y
 NEXT

 CALL subroutine(array1(), array2())

SUB subroutine (a1() AS INTEGER, a2() AS INTEGER) STATIC
 ' does something with two arrays

 DIM x AS INTEGER, y AS INTEGER

 CLS

 FOR x = 0 TO 12
   PRINT a1(x);
 NEXT

 PRINT

 FOR x = 0 TO 3:
   FOR y = 0 TO 4
     PRINT a2(x, y);
   NEXT y
   PRINT
 NEXT x

END SUB
 
In my earlier example, delete the redundant line that reads:

DECLARE SUB subroutine (array1() AS INTEGER, array2() AS INTEGER)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top