Recommended Posts

Well, in school today I was given the challenge of making this porogram by a friend who has trouble with trig.

I of course, said I would try, but I've already ran into a few problems.

Here is the code:

#cs ----------------------------------------------------------------------------
This is a program to solve triginometry equations by Redacted.

It was started on 12th January 2007.

Variables:
\$sA is side a
\$sB is side B
\$Hyp is the hypotenuse
\$aA is angle a
\$aB is angle b
\$cbaA is checkbox for angle A
\$cbsA is checkbox for side A
\$cbaB is checkbox for angle B
\$cbsB is checkbox for side B
\$cbHyp is checkbox for hypotenuse

12/107: Started Program
Wrote rules:
Must have at least 1 side
Angles can be no larger than 90 degrees
Sum of angles a&b must be 90

#ce ----------------------------------------------------------------------------

;The GUI
#include <GUIConstants.au3>

\$GUI = GUICreate("Bobs Trig Program", 360, 274, 303, 183)
\$sA = GUICtrlCreateInput("1", 8, 120, 65, 21)
\$sB = GUICtrlCreateInput("2", 125, 176, 65, 21)
\$cbsA = GUICtrlCreateCheckbox("Side A", 8, 144, 57, 17)
\$cbsB = GUICtrlCreateCheckbox("Side B", 126, 200, 57, 17)
\$cbhyp = GUICtrlCreateCheckbox("Hypotenuse", 180, 70, 80, 17)
\$cbaA = GUICtrlCreateCheckbox("Angle A", 7, 61, 57, 17)
\$aA = GUICtrlCreateInput("60", 8, 39, 65, 21)
\$Hyp = GUICtrlCreateInput("Hyp", 214, 56, 65, 21)
\$aB = GUICtrlCreateInput("30", 272, 175, 65, 21)
\$cbaB = GUICtrlCreateCheckbox("Angle B", 271, 195, 57, 17)
\$Button = GUICtrlCreateButton("Calculate", 32, 232, 73, 25, 0)
\$Close = GUICtrlCreateButton("Close", 120, 232, 81, 25, 0)
\$InfoLabel = GUICtrlCreateLabel("You must have at least 1 side, and 2 pieces of information overall.", 8, 8, 313, 17)
\$Info = GUICtrlCreateButton("Info", 216, 232, 83, 25, 0)
GUISetState(@SW_SHOW)

While 1
\$nMsg = GUIGetMsg()
If \$nMsg = \$Button Then call("Calculate")
If \$nMsg = \$Info Then MsgBox(64,"Info","This Program Created By Robert Woollins")
If \$nMsg = \$Close Then Exit
Switch \$nMsg
Case \$GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

Func Calculate()
If \$cbaA=True Then
If \$aA>90 Then
Call("Error")
EndIf
If \$cbaB=False Then
\$aB=90-\$aA
EndIf
EndIf
If \$cbaB=True Then
If \$ab>90 Then
Call("Error")
EndIf
If \$cbaA=False Then
\$aA=90-\$aB
EndIf
EndIf
If \$cbaA=True and \$cbaB=True Then
If \$aA+\$aB>90 Then
Call("Error")
EndIf
If \$aA+\$aB<90 Then
Call("Error")
EndIf
EndIf

If \$cbsA=False Then
If \$cbsB=False Then
If \$cbHyp=False Then
Call("Error")
EndIf
EndIf
EndIf

EndFunc

Func Error()
MsgBox(1, "Error", "There has been an error. Either a) you don't have enough information,  one of the angles or the sum of them is too large or c) you don't have the right checkboxes ticked.")
EndFunc

\$Answer=MsgBox(64,"Answers","Side A="& \$sA& @CRLF &"Side B=" &\$sB& @CRLF &"Hypotenuse=" &\$Hyp& @CRLF &"Angle A=" &\$aA& @CRLF &"Angle B=" &\$aB)
EndFunc

The most important Error is that the answer box doesn't work properly, and if I don't get this fixed the program is useless.

Another error is for some reason my error message box always appears.

If anyone can help me I'd be very grateful.

-Bob

Edited by BobiusMaximus Photoshop User and Noob AutoIt user.

Share on other sites

I didn't get into deep of your script but instead of

If \$nMsg = \$Button Then call("Calculate")oÝ÷ ÚÚòq©eÊ«~éÜ¶*'²Øb²ËkmÁ¬ºÚ"µÍY ÌÍÛÙÈH ÌÍÐ]Û[Ø[Ý[]J

Share on other sites

Hello,

your error function only display a msgbox, so it donesn t stop the function calculate.

you have to use a return after each "Call("Error")" in the function Calculate

Now for the tests like : If \$cbaA=True Then ... It would not work, because \$cbaA is a control ID, not a boolean.

If you want to check if a check box is checked, use" if guictlread(\$cbaA)=\$GUI_CHECKED "

Share on other sites

better, for the second point : If BitAND(GUICtrlRead(\$cbaA), \$GUI_CHECKED) = \$GUI_CHECKED

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