Ultima2 Posted November 26, 2008 Share Posted November 26, 2008 (edited) So Im trying to write simple math solver. Almost done but im having a few problem. Here's what I got so far expandcollapse popup#include <GUIConstants.au3> GUICreate("test",300,250) GUICtrlCreateLabel("Put in the form of Ax + B = C", 10, 20) GUICtrlCreateLabel("X",40, 46) GUICtrlCreateLabel("+", 57, 44) GUICtrlCreateLabel("=", 110, 44) $exitbutton = GUICtrlCreateButton("Exit", 30, 200) $Avalue = GUICtrlCreateInput("",10,40,30,30) $Bvalue = GUICtrlCreateInput("", 70, 40, 30, 30) $Cvalue = GUICtrlCreateInput("", 130, 40, 30, 30) $okbutton = GUICtrlCreateButton("ok", 2, 200) GUISetState() Do While 1 $msg = GUIGetmsg() Select Case $msg = $okbutton $aValue = GUICtrlRead($Avalue) $bValue = GUICtrlRead($Bvalue) $cValue = GUICtrlRead($Cvalue) $r = $cValue - $bValue $z = $r/$aValue ExitLoop Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $exitbutton Exit EndSelect WEnd MsgBox(0,"The value is", $z) $z = 0 Until $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton Exit How do I make the variable $z = nothing again after the MsgBox appears so I could keep using the GUI to solve. So for example if I put in 12x + 2 = 20, it would give me 1.5 for x. If I kept continuing, it would give me -1.#IND? How do I clear the value for the variable $z after the MsgBox appear so I could keep using the GUI? Edited November 26, 2008 by Ultima2 Link to comment Share on other sites More sharing options...
youknowwho4eva Posted November 26, 2008 Share Posted November 26, 2008 (edited) $z = "" Edit: actually that's not the problem Use this expandcollapse popup#include <GUIConstants.au3> GUICreate("test",300,250) GUICtrlCreateLabel("Put in the form of Ax + B = C", 10, 20) GUICtrlCreateLabel("X",40, 46) GUICtrlCreateLabel("+", 57, 44) GUICtrlCreateLabel("=", 110, 44) $exitbutton = GUICtrlCreateButton("Exit", 30, 200) $Avalue = GUICtrlCreateInput("",10,40,30,30) $Bvalue = GUICtrlCreateInput("", 70, 40, 30, 30) $Cvalue = GUICtrlCreateInput("", 130, 40, 30, 30) $okbutton = GUICtrlCreateButton("ok", 2, 200) GUISetState() Do $msg = GUIGetmsg() If $msg = $okbutton Then Call("math") ElseIf $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton Then Call("close") EndIf Until $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton Exit Func math() $aValueread = GUICtrlRead($Avalue) $bValueread = GUICtrlRead($Bvalue) $cValueread = GUICtrlRead($Cvalue) $r = $cValueread - $bValueread $z = $r/$aValueread MsgBox(0,"The value is", $z) $z = "" EndFunc Func close() Exit EndFunc Another Edit: guess I should explain what you did wrong. you changed the value of the valueread variables. so the second time it was ctrlreading something that was already ctrlread. Edited November 26, 2008 by youknowwho4eva Giggity Link to comment Share on other sites More sharing options...
autoitter Posted November 26, 2008 Share Posted November 26, 2008 The problem is that you reuse the variables for the input controls to do the calculation. This works: expandcollapse popup#include <GUIConstants.au3> GUICreate("test",300,250) GUICtrlCreateLabel("Put in the form of Ax + B = C", 10, 20) GUICtrlCreateLabel("X",40, 46) GUICtrlCreateLabel("+", 57, 44) GUICtrlCreateLabel("=", 110, 44) $exitbutton = GUICtrlCreateButton("Exit", 30, 200) $Avalue = GUICtrlCreateInput("",10,40,30,30) $Bvalue = GUICtrlCreateInput("", 70, 40, 30, 30) $Cvalue = GUICtrlCreateInput("", 130, 40, 30, 30) $okbutton = GUICtrlCreateButton("ok", 2, 200) GUISetState() Do While 1 $msg = GUIGetmsg() Select Case $msg = $okbutton $aVal = GUICtrlRead($Avalue) $bVal = GUICtrlRead($Bvalue) $cVal = GUICtrlRead($Cvalue) $r = $cVal - $bVal $z = $r/$aVal ExitLoop Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $exitbutton Exit EndSelect WEnd MsgBox(0,"The value is", $z) $z = 0 Until $msg = $GUI_EVENT_CLOSE or $msg = $exitbutton Exit Link to comment Share on other sites More sharing options...
youknowwho4eva Posted November 26, 2008 Share Posted November 26, 2008 you beat my multiple edits Giggity Link to comment Share on other sites More sharing options...
Ultima2 Posted November 26, 2008 Author Share Posted November 26, 2008 (edited) Oh Ok thank you very much. I see why it didnt work now. Had no idea why I used $aValue >_> Edited November 26, 2008 by Ultima2 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