Qbasicnews.com
define argument types in subs - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: define argument types in subs (/thread-3186.html)

Pages: 1 2 3 4 5 6


define argument types in subs - banAnnA - 02-12-2004

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)


define argument types in subs - Agamemnus - 02-12-2004

Here are the only two ways I know of:

SUB a (integer1 AS INTEGER, integer2 AS INTEGER)
SUB a (integer1%, integer2%)


define argument types in subs - TheBigBasicQ - 02-12-2004

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



define argument types in subs - RST - 02-13-2004

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


define argument types in subs - TheBigBasicQ - 02-13-2004

I forgot to mention, you need to put DEFINT before the sub begins =P.


define argument types in subs - Neo - 02-13-2004

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



define argument types in subs - TheBigBasicQ - 02-13-2004

For me QB doesnt sneekily put a DEFSNG A-Z but a DEFINT A-Z.

I wonder why :o


define argument types in subs - Neo - 02-13-2004

I think it's strange. Every QB45 version I've tried does it sometimes. :-?


define argument types in subs - TheBigBasicQ - 02-13-2004

Its prolly a built in safeguard or something.

BTW What do you mean by every QB45 version? IMO QB45 is only one version Wink.


define argument types in subs - Neo - 02-13-2004

I tried The Geekery's QB45 archive, QBNZ's archive, HAR-SoftWare's archive, and more. That's what I mean with versions Wink