Jump to content

Recommended Posts

Posted (edited)

Hi, I wrote the below code to learn user defined functions.. jam is the function which calculates summation and division of two numbers $a, $b.. I expect the $sum and $div receives the results $r and $s respectively from the function... but the msbox in the main program doesn't display results properly, while the one inside func shows it correclty. how do I pull the values in $r and $s to $sum and $div respectively.. thanks for all the help on this forum

 

global $a,$b,$sum,$div

$a=1
$b=2
jam($a,$b,$sum,$div)
msgbox(0,"results",$sum&" , "&$div)
 
 
func jam($p,$q,$r,$s )

 $r=$p+$q
 $s = $p/$q
msgbox(0,"results",$r&" , "&$s)
EndFunc

 

Edited by Rskm
typo corrected
Posted
On ‎21‎.‎02‎.‎2018 at 0:53 PM, Rskm said:

global $a,$b,$sum,$div

Try to avoid Global vars

Local $a, $b

Should be enough.

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Posted
11 minutes ago, ajag said:

Try to avoid Global vars

Local $a, $b

Should be enough.

Interestingly, variables declared at the main level are always scoped as global, so it is less confusing to declare them as global. Try this:

Opt('MustDeclareVars', 1)

Local $ttt = "hello"

VarTest()

Func VarTest()
    MsgBox(0,"debug", $ttt)
EndFunc

 

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Posted
25 minutes ago, SlackerAl said:

Interestingly, variables declared at the main level are always scoped as global

missed that...

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...