Sign in to follow this  
Followers 0
Ultima2

need help with variable in script

5 posts in this topic

#1 ·  Posted (edited)

So Im trying to write simple math solver. Almost done but im having a few problem. Here's what I got so far

#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 by Ultima2

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$z = ""

Edit: actually that's not the problem

Use this

#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 by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

The problem is that you reuse the variables for the input controls to do the calculation.

This works:

#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

Share this post


Link to post
Share on other sites

you beat my multiple edits :)


Giggity

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Oh Ok thank you very much. I see why it didnt work now. Had no idea why I used $aValue >_>

Edited by Ultima2

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0