02-24-2025, 06:13 PM
As much fun as it to pass a value instead of a variable, don't expect it to come back as the variable it was passed to in the sub.
Now of course we don't have to match the name of the variable passed, it just needs to be a variable. Oh, and we don't even have to assign it in the argument, but that's sloppy, because it changes type from integer to single (default variable type) and back to integer again, but it works! I often do this until I get my program ready to use, to avoid taking up time initially.
..of course one way to avoid creating more than one TYPE is to assign the type to the argument in the sub call...
Note you need to make the argument match the passing type if you want to avoid a second type entering into the subroutine. Not doing so would cause errors if the the limits of a type were exceeded.
..or just keep it really simple without changing the variable name or type...
Pete
Code: (Select All)
Dim IQ As Integer
printx "My I.Q. is", 160
Print "Wait, let's double check that. Oops, my I.Q. is"; IQ
Sub printx (a$, IQ)
Print a$; IQ
End Sub
Now of course we don't have to match the name of the variable passed, it just needs to be a variable. Oh, and we don't even have to assign it in the argument, but that's sloppy, because it changes type from integer to single (default variable type) and back to integer again, but it works! I often do this until I get my program ready to use, to avoid taking up time initially.
Code: (Select All)
a% = 160: printx "My I.Q. is", a%
Print "Wait, let's double check that. Yep, my I.Q. is"; a%
Sub printx (a$, reallylongexplainedvariablenamehereforIQ)
Print a$; reallylongexplainedvariablenamehereforIQ ' This variable is a single TYPE.
End Sub
..of course one way to avoid creating more than one TYPE is to assign the type to the argument in the sub call...
Code: (Select All)
Dim As Integer a
a = 160: printx "My I.Q. is", a
Print "Wait, let's double check that. Yep, my I.Q. is"; a
Sub printx (a$, reallylongexplainedvariablenamehereforIQ As Integer) ' Added As Integer.
Print a$; reallylongexplainedvariablenamehereforIQ ' Now this variable is an integer TYPE.
End Sub
Note you need to make the argument match the passing type if you want to avoid a second type entering into the subroutine. Not doing so would cause errors if the the limits of a type were exceeded.
Code: (Select All)
Dim IQ As _Integer64 ' Traditional was to DIM, but I like the new QB64 method, above examples, which allow for more variables to be added with commas! Thanks, Dev Team!
IQ = 9223372036854775807
Print IQ
printx "My I.Q. is", IQ
Sub printx (a$, IQ)
Print a$; IQ ' Will appear truncated in SN.
End Sub
..or just keep it really simple without changing the variable name or type...
Code: (Select All)
Dim As Integer IQ
IQ = 160: printx "My I.Q. is", IQ
Print "Wait, let's double check that. Yep, my I.Q. is"; IQ
Sub printx (a$, IQ As Integer)
Print a$; IQ
End Sub
Pete