Qbasicnews.com

Full Version: define argument types in subs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Is there a way to define the types of arg in a sub? For exemple, set them all to integer? DEFINT doesn't work here.

define a(integer1, integer2)
Here are the only two ways I know of:

SUB a (integer1 AS INTEGER, integer2 AS INTEGER)
SUB a (integer1%, integer2%)
This works for me. It outputs "5 7" instead of "5 6.54871" which proves beyond doubt that both the arguments are integers =).

Code:
DEFINT A-Z
SUB me (a, b)
   PRINT a, b
END SUB


me 5, 6.54871
The data types are assigned based on the symbol at the end of their names. Like in Aga's example, the % sign told QBasic that the variable was an integer.

For a list of the different kinds of variables and their symbols:
http://qbasicnews.com/qboho/qckadvr.dtp.shtml
I forgot to mention, you need to put DEFINT before the sub begins =P.
When using in the QB IDE, QB might sneekily put a DEFSNG A-Z on top of your sub Wink

So, add DEFINT A-Z when necessary. Or use % or AS INTEGER (I prefer the latter in the sub itself, but the % in the DECLARE, like this:

Code:
DECLARE SUB mysub (a%, b%, c!, d#, e$, f&)

SUB mysub (a AS INTEGER, b AS INTEGER, c AS SINGLE, d AS DOUBLE, e AS STRING, f AS LONG)
END SUB
For me QB doesnt sneekily put a DEFSNG A-Z but a DEFINT A-Z.

I wonder why :o
I think it's strange. Every QB45 version I've tried does it sometimes. :-?
Its prolly a built in safeguard or something.

BTW What do you mean by every QB45 version? IMO QB45 is only one version Wink.
I tried The Geekery's QB45 archive, QBNZ's archive, HAR-SoftWare's archive, and more. That's what I mean with versions Wink
Pages: 1 2 3 4 5 6