How to pass multi-dimensional arrays to a function

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
Posts: 3
Joined: Sat Jul 23, 2016 10:46 pm

How to pass multi-dimensional arrays to a function

Post by Aureal » Tue Jul 11, 2017 1:10 pm

Hi, I've recently discovered that passing arrays to a function is possible. Well, I've decided to create a tetris clone, and, for the sake of optimization, I've put the sprites on a multi-dimensional array, storing them as strings. For example

Code: Select all

dim shared array(4, 5) as string

array(1, 1) = " # "
array(1, 2) = "###"

array(2, 1) = "#  "
array(2, 2) = "#  "
array(2, 3) = "#  "
And so on...

Then I would make a function to draw a random sprite on the screen based on an array "a", but, how do I declare an array in the parameters? and, how do I pass it?

User avatar
Posts: 2180
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: How to pass multi-dimensional arrays to a function

Post by burger2227 » Tue Jul 11, 2017 9:41 pm

FUNCTION myarray(array()) 'passes all indices of the array

DIM SHARED array AS type can be used in main or SHARED array can be used in the Function declarations.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: ...

Post Reply