Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
define argument types in subs
#1
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)
Reply
#2
Here are the only two ways I know of:

SUB a (integer1 AS INTEGER, integer2 AS INTEGER)
SUB a (integer1%, integer2%)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
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
Reply
#4
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
Reply
#5
I forgot to mention, you need to put DEFINT before the sub begins =P.
Reply
#6
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
Reply
#7
For me QB doesnt sneekily put a DEFSNG A-Z but a DEFINT A-Z.

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

BTW What do you mean by every QB45 version? IMO QB45 is only one version Wink.
Reply
#10
I tried The Geekery's QB45 archive, QBNZ's archive, HAR-SoftWare's archive, and more. That's what I mean with versions Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)