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

How to pass multi-dimensional arrays to a function

Post by Aureal »

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
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

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

Post by burger2227 »

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 : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply