Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Just noticed this
#1
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
Reply
#2
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
Reply
#3
Nice username, helpy Smile
Reply
#4
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

Code:
test (n)
Antoni
Reply
#5
Quote:Nice username, helpy Smile

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
Reply
#6
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)