Jump to content

using function


Rskm
 Share

Recommended Posts

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
Link to comment
Share on other sites

Just replace your func parameter definition by:

func jam($p,$q, ByRef $r, ByRef $s )

and welcome to the forum.:)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...