Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions
#11
you want, for example, to call a subroutine MYSUB and pass variables A and B to it or from it, your SUB statement might look like

SUB MYSUB(A, B)

You would then pass variables to MYSUB via

CALL MYSUB(A, B)

or

CALL MYSUB(C, D)

In the latter case, when MYSUB gets called, C will go into MYSUB as what it calls "A" and D will go into MYSUB as what it calls "B". (You don't have to use the same variable names in the CALL statement as you used in the SUB statement. But they have to be of the same type.) Or if MYSUB defines or modifies A and B they will be passed back to the calling routine in the same way. As an example,

C = 5
D = 10
PRINT C, D, " Before call."
CALL MYSUB(C, D)
PRINT C, D, " After call."
END
SUB MYSUB(A, B)
A = 2 * A
B = 3 * B
END SUB


Before calling MYSUB, C and D had one set of values. After calling it, they have another set.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#12
Another quick point about functions: They're like real-life functions. You put in some variables, but you only get one back. eg y = mx + c is a function in the real world and can be duplicated by a function in QB.
Reply
#13
If you need a function to return more than one value, you can pass others back via the parameter list.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#14
Oooh, yeah.
Reply
#15
ok, I see. I forgot that a funtion returnes a value. All I was trying to do was exec. a few lines of code with one command. So tell me more about staring variables in a SUB. I think that is what I am after. Thanks!
Reply
#16
Storing or Sharing?
Reply
#17
Sharing. My bad. Don't bother, I figured it out!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)