KillerSam Posted January 28, 2007 Share Posted January 28, 2007 This is probably realy easy but. How do I make a script that will set "0" into my two input boxes "$a" and "$b"? So when the user presses the "clear" button, the calculations will all use the initial values of 0 for both $a and $b? Script below.expandcollapse popupGlobal $GUI = GUICreate("Hypotenuse-Calculator", 600, 300) GUISetBkColor(0x00E0FFFF) GUICtrlCreatePic(@ScriptDir & "\images\triangle.gif",10,50, 200,200) GUICtrlCreateLabel("Please Enter the length for the 2 values that you have.", 10, 10) GUICtrlCreateLabel("Click the Calculate button when entered.", 10, 25) GUICtrlCreateLabel("A", 255, 80) $a = GUICtrlCreateInput("", 220, 100, 60, 20) GUICtrlCreateLabel("B", 315, 80) $b = GUICtrlCreateInput("", 290, 100, 60, 20) $calculate = GUICtrlCreateButton("Calculate", 530,260, 50) $clear = GUICtrlCreateButton("Clear", 470,260, 50) $answer1 = GUICtrlCreateLabel("", 465, 100,73) $answer2 = GUICtrlCreateLabel("", 465, 130,73) $answer3 = GUICtrlCreateLabel("", 465, 160,73) $answer4 = GUICtrlCreateLabel("", 465, 190,130) $answer5 = GUICtrlCreateLabel("", 465, 210,130) $answer1a = GUICtrlCreateLabel("A Squared" ,390, 100,70) $answer2a = GUICtrlCreateLabel("B Squared:", 390, 130,70) $answer3a = GUICtrlCreateLabel("A+B squared:", 390, 160,70) $answer4a = GUICtrlCreateLabel("Square rooted:", 390, 190,70) $answer5a = GUICtrlCreateLabel("Length of C:", 390, 210,70) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $calculate Then $data = GUICtrlRead($a) * GUICtrlRead($a) ; reads input and calculates their sum GUICtrlSetData($answer1, $data) $data2 = GUICtrlRead($B) * GUICtrlRead($B) ; reads input and calculates their sum GUICtrlSetData($answer2, $data2) $data3 = (GUICtrlRead($a)*GUICtrlRead($a)) + (GUICtrlRead($B)*GUICtrlRead($B)) ; reads input and calculates their sum GUICtrlSetData($answer3, $data3) $data4 = Sqrt((GUICtrlRead($a)*GUICtrlRead($a)) + (GUICtrlRead($B)*GUICtrlRead($B))) GUICtrlSetData($answer4, $data4) $data5 = Sqrt((GUICtrlRead($a)*GUICtrlRead($a)) + (GUICtrlRead($B)*GUICtrlRead($B))) GUICtrlSetData($answer5, $data5) EndIf Wend Link to comment Share on other sites More sharing options...
Xenobiologist Posted January 28, 2007 Share Posted January 28, 2007 Hi, also added to accept only numbers. expandcollapse popup#include<GuiConstants.au3> Global $GUI = GUICreate("Hypotenuse-Calculator", 600, 300) GUISetBkColor(0x00E0FFFF) GUICtrlCreatePic(@ScriptDir & "\images\triangle.gif", 10, 50, 200, 200) GUICtrlCreateLabel("Please Enter the length for the 2 values that you have.", 10, 10) GUICtrlCreateLabel("Click the Calculate button when entered.", 10, 25) GUICtrlCreateLabel("A", 255, 80) $a = GUICtrlCreateInput("", 220, 100, 60, 20,$ES_NUMBER) GUICtrlCreateLabel("B", 315, 80) $b = GUICtrlCreateInput("", 290, 100, 60, 20,$ES_NUMBER) $calculate = GUICtrlCreateButton("Calculate", 530, 260, 50) $clear = GUICtrlCreateButton("Clear", 470, 260, 50) $answer1 = GUICtrlCreateLabel("", 465, 100, 73) $answer2 = GUICtrlCreateLabel("", 465, 130, 73) $answer3 = GUICtrlCreateLabel("", 465, 160, 73) $answer4 = GUICtrlCreateLabel("", 465, 190, 130) $answer5 = GUICtrlCreateLabel("", 465, 210, 130) $answer1a = GUICtrlCreateLabel("A Squared", 390, 100, 70) $answer2a = GUICtrlCreateLabel("B Squared:", 390, 130, 70) $answer3a = GUICtrlCreateLabel("A+B squared:", 390, 160, 70) $answer4a = GUICtrlCreateLabel("Square rooted:", 390, 190, 70) $answer5a = GUICtrlCreateLabel("Length of C:", 390, 210, 70) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $calculate Then $data = GUICtrlRead($a) * GUICtrlRead($a) ; reads input and calculates their sum GUICtrlSetData($answer1, $data) $data2 = GUICtrlRead($B) * GUICtrlRead($B) ; reads input and calculates their sum GUICtrlSetData($answer2, $data2) $data3 = (GUICtrlRead($a) * GUICtrlRead($a)) + (GUICtrlRead($B) * GUICtrlRead($B)) ; reads input and calculates their sum GUICtrlSetData($answer3, $data3) $data4 = Sqrt((GUICtrlRead($a) * GUICtrlRead($a)) + (GUICtrlRead($B) * GUICtrlRead($B))) GUICtrlSetData($answer4, $data4) $data5 = Sqrt((GUICtrlRead($a) * GUICtrlRead($a)) + (GUICtrlRead($B) * GUICtrlRead($B))) GUICtrlSetData($answer5, $data5) EndIf If $msg = $clear Then GUICtrlSetData($a, "") GUICtrlSetData($b, "") EndIf WEnd So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
KillerSam Posted January 28, 2007 Author Share Posted January 28, 2007 Many thanks for that! Is it possible to also allow decimal places? 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