CodeFox Posted March 17, 2008 Share Posted March 17, 2008 (edited) Hey, I've written this simple program to calculate the hypotenuse of a triangle but it does not display the value in the input box. There's probably something simple wrong with my syntax as i'm trying to pick up the autoit language again after not using it in about a year Also for the input boxes i've set them to only allow numbers however i'd like decimals to be able to be used aswell. Could anyone point me in the right direction. Thanks in advance, CodeFox expandcollapse popup; Checks to see if more than one WinManager is running $g_szVersion = "WinManager v0.1" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) #include <GUIConstants.au3> HotKeySet("^!x", "Quit") $ES_NUMBER = 0x2000 Dim $WinWidth, $WinHeight, $WinHyp $WinWidth = 0 $WinHeight = 0 $WinHyp = 0 GUICreate("WinManager - The Onsite Measurement Checker", 450 , 300 ); Creates a GUI in the center of the screen Opt("GUICoordMode",1) $WinWidth = GUICtrlCreateEdit ( "", 175, 15 , 100 , 25, $ES_NUMBER ) $WinHeight = GUICtrlCreateEdit ( "", 175, 50 , 100 , 25, $ES_NUMBER ) GUICtrlCreateEdit ( ""& $WinHyp , 175, 125 , 100 , 25, $ES_NUMBER ) $Button_1 = GUICtrlCreateButton ("Calculate", 175, 85, 100, 25) $Button_2 = GUICtrlCreateButton ( "Help", 120, 175, 100, 25) $Button_3 = GUICtrlCreateButton ( "Exit", 225, 175, 100 , 25) GUISetState () ; Displays GUI ; Runs the GUI until manually closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 WinHypotenuse($WinWidth, $WinHeight); Calcualte button pressed and the hypo is calculated Case $msg = $Button_2 MsgBox(0, 'Help', 'Using WinManager is simple and easy!') ; Help button is pressed and message box appears with details Case $msg = $Button_3 $ans = MsgBox(32+4, 'Exit WinManager', 'Are You Sure You Want To Exit WinManager?') ; Exit button is pressed. The user is asked if they are sure they want to exit If $ans = 6 Then $msg = $GUI_EVENT_CLOSE ExitLoop ElseIf $ans = 7 Then ContinueLoop EndIf EndSelect Wend Func WinHypotenuse($WinWidth, $WinHeight) $WinHyp = $WinWidth*$WinWidth+$WinHeight*$WinHeight; return sqrt($WinHyp); Endfunc Func Quit() Exit EndFunc Edited March 17, 2008 by CodeFox Link to comment Share on other sites More sharing options...
Aceguy Posted March 17, 2008 Share Posted March 17, 2008 expandcollapse popup; Checks to see if more than one WinManager is running $g_szVersion = "WinManager v0.1" If WinExists($g_szVersion) Then Exit; It's already running AutoItWinSetTitle($g_szVersion) #include <GUIConstants.au3> HotKeySet("^!x", "Quit") Dim $WinWidth, $WinHeight, $WinHyp $WinWidth = 0 $WinHeight = 0 $WinHyp = 0 GUICreate("WinManager - The Onsite Measurement Checker", 450 , 300 ); Creates a GUI in the center of the screen Opt("GUICoordMode",1) $WinWidth = GUICtrlCreateEdit ( "", 175, 15 , 100 , 25, $ES_NUMBER ) $WinHeight = GUICtrlCreateEdit ( "", 175, 50 , 100 , 25, $ES_NUMBER ) $results=GUICtrlCreatelabel ( "Results here", 175, 125 , 100 , 25 ) $Button_1 = GUICtrlCreateButton ("Calculate", 175, 85, 100, 25) $Button_2 = GUICtrlCreateButton ( "Help", 120, 175, 100, 25) $Button_3 = GUICtrlCreateButton ( "Exit", 225, 175, 100 , 25) GUISetState () ; Displays GUI ; Runs the GUI until manually closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 WinHypotenuse($WinWidth, $WinHeight); Calcualte button pressed and the hypo is calculated Case $msg = $Button_2 MsgBox(0, 'Help', 'Using WinManager is simple and easy!') ; Help button is pressed and message box appears with details Case $msg = $Button_3 $ans = MsgBox(32+4, 'Exit WinManager', 'Are You Sure You Want To Exit WinManager?') ; Exit button is pressed. The user is asked if they are sure they want to exit If $ans = 6 Then $msg = $GUI_EVENT_CLOSE ExitLoop ElseIf $ans = 7 Then ContinueLoop EndIf EndSelect Wend Func WinHypotenuse($WinWidth, $WinHeight) $WinHyp = $WinWidth*$WinWidth+$WinHeight*$WinHeight; GUICtrlSetData($results,$WinHyp) Endfunc Func Quit() Exit EndFunc NOT TESTED [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
pacman1176 Posted March 17, 2008 Share Posted March 17, 2008 (edited) $WinHyp = $WinWidth*$WinWidth+$WinHeight*$WinHeight; GUICtrlSetData($results,$WinHyp) You forgot the square root, plus it's good practice to have it return value rather than perform that operation in the function. I would do it like this: While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 GuiCtrlSetData($results,WinHypotenuse($WinWidth, $WinHeight)); Calcualte button pressed and the hypo is calculated [...] Func WinHypotenuse($WinWidth, $WinHeight) $WinHyp = $WinWidth*$WinWidth+$WinHeight*$WinHeight; return sqrt($WinHyp); Endfunc edit: forgot code tags Edited March 17, 2008 by pacman1176 Link to comment Share on other sites More sharing options...
Aceguy Posted March 17, 2008 Share Posted March 17, 2008 *SIGH* [u]My Projects.[/u]Launcher - not just for games & Apps (Mp3's & Network Files)Mp3 File RenamerMy File Backup UtilityFFXI - Realtime to Vana time Clock Link to comment Share on other sites More sharing options...
CodeFox Posted March 17, 2008 Author Share Posted March 17, 2008 (edited) Thanks guys - I'll test the modifications you've posted. Anyone know how to allow decimals to be entered or is it best to just leave the input open to anything to be able to do that? Edited March 17, 2008 by CodeFox Link to comment Share on other sites More sharing options...
CodeFox Posted March 18, 2008 Author Share Posted March 18, 2008 For some reason it doesn't work the result returns 5 everytime. I would like it to update each time the calculate button is pressed with different numbers supplied. Anyone know why? Link to comment Share on other sites More sharing options...
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