Jump to content

using function


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

msgbox(0,"results",$sum&" , "&$div)
func jam($p,$q,$r,$s )

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


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"


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


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

  • Create New...