Page 1 of 1

Passing arrays to subs

Posted: Sat Oct 13, 2007 9:11 am
by Theophage
Okay, I tried searching google for "passing arrays subs quickbasic" and I couldn't find what I needed. Even the qb45 help couldn't help me.

I'm writing a game which I've recently decided to to all in text graphics (chr$(219)s and chr$(177)s) so I've had to write my own text GET and PUT routines. Here is my PUT routine:

Code: Select all

SUB TextSprite (xpos, ypos, array(), index)
  ctr = index + 2
  FOR v = ypos to ypos + array(index + 1) - 1
    FOR h = xpos to xpos + array(index) - 1
      colr = array(ctr)
      IF colr > 0 AND h > -1 AND v > -1 AND h < 80 AND v < 50 THEN
        IF colr < 128 THEN
          POKE h * 2 + v * 160, 219
          POKE h * 2 + v * 160 + 1, colr
        ELSE
          POKE h * 2 + v * 160, 177
          POKE h * 2 + v * 160 + 1, colr - 128
        END IF
      END IF
      ctr = ctr + 1
    NEXT h
  NEXT v
END SUB
You will note that this routine requires that I pass the array which holds the sprite data into the SUB as well the index value of where in the array the particular sprite resides. When I use the above code, however, I get a type mismatch error.

So how do I (properly) pass an array into a SUB? Or, if it cannot be done, what can I do as a work around?

Posted: Sat Oct 13, 2007 9:26 am
by Theophage
Dammit, I should really play around a bit more before posting; I found my problem.

It seems that QB wanted to make my variables SINGLE by putting the "!" by their names in the DECLARE, but that wasn't in my SUB. In fact, in the program I defined the array to be an INTEGER. So what I did was put "AS INTEGER" in all three places (the DECLARE statement, my DIM statement, and in the SUB statement) and now it seems to work fine.

Posted: Sat Oct 13, 2007 4:37 pm
by Mac
[quote="Theophage"]Dammit, I should really play around a bit more before posting; I found my problem.

It seems that QB wanted to make my variables SINGLE by putting the "!" by their names in the DECLARE, but that wasn't in my SUB. In fact, in the program I defined the array to be an INTEGER. So what I did was put "AS INTEGER" in all three places (the DECLARE statement, my DIM statement, and in the SUB statement) and now it seems to work fine.[/quote]

Good thing you found it. Nobody would help you because you haven't even acknowledged help on your previous post.

Mac

Posted: Sat Oct 13, 2007 9:29 pm
by Theophage
To be honest, Mac, I hadn't touched that program since I already got help on it (and responded), so I hadn't even implemented the change you suggested on it afterward. Going over my plans for the game I'm (hoping to) write, I decided I would like to try it in the text mode. But I understand how it is to not get a response, so I just wrote one over in the thread. I do thatnk you for your help. :)

Posted: Wed Oct 31, 2007 6:31 pm
by burger2227
SNARK!!!!!!!!!!