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) |
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 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 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&) 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 . 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 |