Jump to content

Help With Pythagorean Theorum Code


Recommended Posts

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.

#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!

Link to comment
Share on other sites

Here's the problem

GUICtrlSetData($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 GUICtrlRead

GUICtrlSetData($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 this

Func _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
EndFunc

looks much better doesnt it?

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...