RyanPotter Posted January 14, 2007 Posted January 14, 2007 Hey guys, I'm a bit new to this language and I was wondering if you guys could please take a quick look at my code and try and tell me what's wrong with it. expandcollapse popup#Include <FindSide.au3> #Include <GUIConstants.au3> GUICreate ("Pythagorean Theorum", 400, 400) GUISetState(@SW_SHOW) $sideA = GUICtrlCreateInput("A", 70, 30, 50, 20) $sideB = GUICtrlCreateInput("B", 170, 30, 50, 20) $sideC = GUICtrlCreateInput("C", 270, 30, 50, 20) $button = GUICtrlCreateButton("Find Missing Side", 75, 60, 100, 20) $label = GUICtrlCreateLabel("", 210, 60, 100, 20, 0x1000) GUICtrlCreateLabel("Fill in the unknown side with a question mark.", 90, 5) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Select Case $msg = $button GUICtrlSetData($label, _findaside($sideA,$sideB,$sideC)) EndSelect WendoÝ÷ Ù8b²+-ꮢÑbÔ¢uæ®Þ«¨¶Ú0'!¶r^çÞ®Ëhjëh×6Func _findaside($sideA,$sideB,$sideC) Select Case $sideA = "?" $b2 = $sideB * $sideb $c2 = $sidec * $sidec $answer = $c2 - $b2 $answer1 = Sqrt($answer) return $answer1 Case $sideb = "?" $a2 = $sidea * $sidea $c2 = $sidec * $sidec $answer = $c2 - $a2 $answer1 = Sqrt($answer) Return $answer1 Case $sidec = "?" $b2 = $sideB * $sideb $a2 = $sidea * $sidea $answer1 = $a2 + $b2 $answer2 = Sqrt($answer1) Return $answer2 EndSelect EndFunc Well, that's about it... Is there something blatantly obvious screaming in my face or some subtle thing that's a rookie mistake? Thanks in advance guys, I really appreciate it!
59FIFTY Posted January 14, 2007 Posted January 14, 2007 Here's the problemGUICtrlSetData($label, _findaside($sideA,$sideB,$sideC))$sideA is the ID of the control, but you need the data from the control, so you have to read the control by using GUICtrlReadGUICtrlSetData($label, _findaside(GUICtrlRead($sideA), GUICtrlRead($sideB), GUICtrlRead($sideC)))and I recommend you cosmetic your code better by using tabs and spaces. I know that everyone has it's own style of programming but to find errors it's better to have the code structured like thisFunc _findaside($sideA,$sideB,$sideC) Select Case $sideA = "?" $b2 = $sideB * $sideb $c2 = $sidec * $sidec Return(Sqrt($c2 - $b2)) Case $sideb = "?" $a2 = $sidea * $sidea $c2 = $sidec * $sidec Return(Sqrt($c2 - $a2)) Case $sidec = "?" $b2 = $sideB * $sideb $a2 = $sidea * $sidea Return(Sqrt($a2 + $b2)) EndSelect EndFunclooks much better doesnt it?
RyanPotter Posted January 14, 2007 Author Posted January 14, 2007 Great! Thanks a million, man... Just as it thought, it was blatantly obvious... And yes, I do usually structure my codes nicely, but first I like to get the codes working.
59FIFTY Posted January 14, 2007 Posted January 14, 2007 IF you start to cosmetic your code from the beginning you don't run into many problems, such as unclosed ifs or loop or whatever
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