# 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
Case \$sideb = "?"
\$a2 = \$sidea * \$sidea
\$c2 = \$sidec * \$sidec
Case \$sidec = "?"
\$b2 = \$sideB * \$sideb
\$a2 = \$sidea * \$sidea
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!

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

##### Share on other sites

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.

##### Share on other sites

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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...