Rskm Posted February 21, 2018 Posted February 21, 2018 (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 February 21, 2018 by Rskm typo corrected
RTFC Posted February 21, 2018 Posted February 21, 2018 Just replace your func parameter definition by: func jam($p,$q, ByRef $r, ByRef $s ) and welcome to the forum. My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
ajag Posted February 23, 2018 Posted February 23, 2018 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)
SlackerAl Posted February 23, 2018 Posted February 23, 2018 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.
ajag Posted February 23, 2018 Posted February 23, 2018 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)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now