Qbasicnews.com

Full Version: heh...me? A noob question?: Returning a value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
:oops: This is very embassing for me to be posting a question in a noob forum, but it is a noob question after all....
Ok, lets say if I had this SUB.
Now, I want to have this line of code in my program:

Code:
IF My_Sub var1%, var2%, var3$ THEN Do_Something

How do I return a boolean value from a sub?
Let's say here's the SUB:

Code:
SUB My_Sub (var1%, var2%, var3$)
var1% = var2%
Bolvar = -1
END SUB

How do I return Bolvar So the IF checks it like in the other line. One more thing while I'm here: what is the symbol for a boolean variable?

Did I explain that well? :lol:
Smile I thought Boolean values were just AND, OR, NOR, XOR, ect..

I never seen any like that, but my best bet if your going for truth..

var3% = -1

:???:
Umm...no what you stated were logic operators.

Anybody else?
Use functions; similar syntax to subs, but you have to specify the type that the function returns... e.g.

[syntax="QBasic"]
FUNCTION My_Sub% (var1%, var2%, var3$)
var1% = var2%
My_Sub% = -1
END FUNCTION
[/syntax]

Then you can do something like:

[syntax="QBasic"]
IF My_Sub%(var1%, var2%, var3$) = -1 THEN Do_Something
[/syntax]

-shiftLynx
Thank you

oh ya, aparrently QB considers an integer as the same thing as a boolean...well more like a square to a rectangle (a square is a rectangle, but a rectangle is not neccessarly a square), where square:rectangle::boolean:integer.

so doing this is valid:

IF i% THEN Do_Something

It will Do_Something as long as i% is non-zero.

So thanks again.