Posts: 66
Threads: 32
Joined: Dec 2002
declare sub test(a as ushort)
dim n as ushort => 3
test n
print n
sleep
sub test(a as ushort)
a=a-1
end sub
Just noticed this.
What i do with the variable a in the test sub effects the variable n outside the sub.
How would i approach this correctly? I don't want n to be effected.
Should i just send the value of n. And how do you do that?
this qb act like this or is it new for fb?
Thx alot!
ttp://hem.passagen.se/qb.basta
Posts: 21
Threads: 3
Joined: Dec 2004
Code:
Declare Sub test(ByVal a As UShort)
Dim n as UShort => 3
test n
Print n
Sleep
Sub test(ByVal a As UShort)
a = a - 1
End Sub
Posts: 1,272
Threads: 36
Joined: Feb 2003
Nice username, helpy
Posts: 1,407
Threads: 117
Joined: Dec 2002
This use of Byval appeared with PDS. QB4.5 allowed you to use BYVAL only when calling external C functions. To pass byval to a QB sub you needed to put parentheses around variables
Antoni
Posts: 21
Threads: 3
Joined: Dec 2004
Quote:Nice username, helpy
It is not why I am so qualified to help with freebasic ... I am not
... I am just a beginner with freebasic
... and I only look around a bit and when I will
have the possibillity to use freebasic in a project
I will jump more into it ;-)
helpy is just a "relict" from the time, where
I wanted to start a buisness (
www.helpy.de)
OK! back to the topic:
Look at:
http://www.freebasic.net/wiki/wikka.php?...ptionbyval
Quote:Syntax:
OPTION BYVAL
Description:
Sets BYVAL as the default method for passing arguments to FUNCTIONS and SUBS. If OPTION BYVAL is not used, the default methode is BYREF, as in QB.
cu, helpy
Posts: 357
Threads: 118
Joined: Oct 2004
Everybody is a beginner in FreeBasic. Luckily its got similar syntax to Qbasic and C. Other options to your problem:
Make the variable that you are changing SHARED: DIM SHARED a as ushort
Pass by reference: test @n
Use a FUNCTION instead of a SUB:
n = test(n)
FUNCTION test(a as ushort) as ushort
a = a - a
test = a
END FUNCTION
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.