Quote:"]Okay, first you use functions by going to Edit->New FUNCTION.
Type a name, like printHello.
Now, you'll see this:
Code:
FUNCTION printHello
END FUNCTION
Say something like... PRINT "hello" inside there. So, now...
Code:
FUNCTION printHello
PRINT "hello"
END FUNCTION
Now go back - hit F2 and find your "main module". Now type in:
printHello
And hit F5. Walla! You see hello on the screen.
Using variables can be done, look up SHARED in the manual. However, that's a bad idea. It's better to use parameters.... you can find out about those in the online help too.
-[Unknown]
You should really stick to pretending to code the YeBB SE, as QB isn't really your thing...
You can NOT call a FUNCTION the same way you call a SUB...
The difference between SUBs and FUNCTIONs are:
1) SUBs can be called with CALL() or just by the SUBs name but without parenthases.
2) SUBs do not return a value as itself, while FUNCTIONs do...
This is valid and will print "1" on your screen:
Code:
PRINT this%
FUNCTION this%
this% = 1
END FUNCTION
This is NOT valid and will result in an error:
Code:
PRINT this%
SUB this%
this% = 1
END SUB
The following ARE valid:
Code:
CALL this("test")
this "test"
SUB this (something$)
PRINT something$
END SUB
That will print the word "test" twice on your screen.
I personally prefer skipping the word CALL and the parenthases, but that's up to you.
In that example, I used parameters, which are variables passed through a sub or function for use by that sub or function. Whatever string you put in place of something$ will be printed.
Make sense?
This also works backwards, meaning you can retrieve a variable from a sub or function in the parameters:
Code:
TestSub text$
PRINT text$
SUB TestSub (something$)
something$ = "test"
END SUB
That will print the word "test" as the SUB has set that variable through the parameters.
I wanted to be a chemistry teacher but those dreams are long gone...
earn.