Jump to content

Need help getting GUI to update / pass through user interactions


Go to solution Solved by MikahS,

Recommended Posts

Trying to write a small program in AutoIt here at work to help out the mathematically challenged. We have a machine that requires a surface area measurement (both sides +10% for components) which the younger generation seems to have trouble calculating. I made up a quick spreadsheet that they could put the length and width measurements into but I thought it would be great to make an AutoIt GUI that can stay on top of the program window at all times.

The problem is... I have never used GUI's with AutoIt and I'm not having much luck figuring it out.

Ideally, I'd like the program to dynamically update the calculated value as users change the length and width input boxes. Less ideally, I tried to write in a "Calculate" button to force an update to the input boxes but not even that seemed to work.

Also, my "Insert Results" button doesn't trigger the mouse clicks/typing like I think it should. I've been sitting in front of this and the help file for a few hours today toying with this but I figured it's time to ask those with more experience where I'm going wrong here.

I've included what I've got so far. Any help would be appreciated, thanks.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Local $areaCalc = GUICreate("Surface Area Calculator", 525, 240, 150, 25, $WS_BORDER, $WS_EX_TOPMOST )
Local $correctedresult = 0
Local $result = 0
Local $length = 1
Local $width = 1
Local $percent = "10%"

GUICtrlCreateLabel("Surface Area Calculator", 30, 10)
GUICtrlCreateLabel("To use, measure the length and width of the board and enter each value into the white boxes below. ", 30, 25)
GUICtrlCreateLabel("The tool will calculate the surface area measurement of the board and can input the values.", 30, 40)
GUICtrlCreateLabel("Length",35,65)
GUICtrlCreateLabel("Width",90,65)
GUICtrlCreateLabel("Buffer",140,65)
GUICtrlCreateLabel("Surface Area",190,65)
Local $lengthbox  = GUICtrlCreateInput($length,30,80,50,20,$ES_NUMBER)
Local $widthbox   = GUICtrlCreateInput($width,85,80,50,20,$ES_NUMBER)
Local $percentbox = GUICtrlCreateInput($percent,140,80,30,20,$ES_NUMBER)
Local $resultbox  = GUICtrlCreateInput($correctedresult,175,80,80,20,$ES_READONLY)
Local $calc       = GUICtrlCreateButton("Calculate",260,77)
Local $movResults = GUICtrlCreateButton("Insert Results",320,77)
GUISetState(@SW_SHOW, $areaCalc)

While 1
    Switch GUIGetMsg()
        Case $calc
            $length = GUICtrlRead($lengthbox)
            $width = GUICtrlRead($widthbox)
            $percent = GUICtrlRead($percentbox)
            If IsNumber($length & $width) Then
                $result = (($length*$width)*2)
                $correctedresult = (($result*$percent)+$result)
            EndIf
            Local $lengthbox  = GUICtrlCreateInput($length,30,80,50,20,$ES_NUMBER)
            Local $widthbox   = GUICtrlCreateInput($width,85,80,50,20,$ES_NUMBER)
            Local $percentbox = GUICtrlCreateInput($percent,140,80,30,20,$ES_NUMBER)
            Local $correctresultbox  = GUICtrlCreateInput($correctedresult,175,80,80,20,$ES_READONLY)
        Case $movResults
            MovResults()
    EndSwitch
   Sleep(1000)
WEnd

Func MovResults()
    MouseClick("left",350,435)
    Send("[TAB]CCA"&$correctedresult&"[TAB]"&$percent)
    MouseClick("left",440,680)
EndFunc
Edited by JuggaloZeke
Link to comment
Share on other sites

  • Solution

I can see that you tried very hard to get this working. It seems your troubles are with updating the GUI window that you've made...

Try something like this (you did most of the coding, I just had some fun with changing it into a couple new functions and changing around your while loop and how you use your switch statement; also how your declaring variables and finding the results of your inputs):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiListBox.au3> ; added this to give us the ability to update the GUI window with your calculated result

; Create the variables
Local $areaCalc, $correctedresult = 0, $result = 0, $length = 1, $width = 1, $percent = "10"
Local $lengthbox, $widthbox, $percent, $percentbox, $calc, $movResults, $length, $width, $msg
Local $resultbox

HotKeySet("{ESC}", "Quit") ; set the ESCAPE key to quit for us
GUI() ; lets make our GUI

While 1
    $msg = GUIGetMsg() ; set the $msg variable to look for GUI events
    Switch $msg
        Case $calc
            $length = GUICtrlRead($lengthbox) ; set the $length to the value inside the $lengthbox
            $width = GUICtrlRead($widthbox) ; set the $width to the value inside the $widthbox
            $percent = GUICtrlRead($percentbox) ; set the $percent to the value inside the $percentbox
            makeResults($length, $width, $percent) ; call our function to make the results for us usign the $length, $width, and $percent parameters
    EndSwitch
WEnd



Func GUI()
    $areaCalc = GUICreate("Surface Area Calculator", 525, 240, 150, 25, $WS_BORDER, $WS_EX_TOPMOST)  ; create the GUI window
    GUICtrlCreateLabel("Surface Area Calculator", 30, 10)
    GUICtrlCreateLabel("To use, measure the length and width of the board and enter each value into the white boxes below. ", 30, 25)
    GUICtrlCreateLabel("The tool will calculate the surface area measurement of the board and can input the values.", 30, 40)
    GUICtrlCreateLabel("Length", 35, 65)
    GUICtrlCreateLabel("Width", 90, 65)
    GUICtrlCreateLabel("Buffer", 140, 65)
    GUICtrlCreateLabel("Surface Area", 190, 65)
    $lengthbox = GUICtrlCreateInput($length, 30, 80, 50, 20, $ES_NUMBER)
    $widthbox = GUICtrlCreateInput($width, 85, 80, 50, 20, $ES_NUMBER)
    $percentbox = GUICtrlCreateInput($percent, 140, 80, 30, 20, $ES_NUMBER)
    $resultbox = GUICtrlCreateList($correctedresult, 175, 80, 80, 20, $ES_READONLY)
    $calc = GUICtrlCreateButton("Calculate", 260, 77)
    GUISetState(@SW_SHOW, $areaCalc)
EndFunc   ;==>GUI

Func makeResults($mWid, $mLen, $mPerc)
    $result = (($mLen * $mWid) * 2)  ; times the length by the width; then the result by 2 and set it in the $result variable
    $correctedresult = (($result * $mPerc) + $result) ; take the result and times it by the percent; then result by the $result
    _GUICtrlListBox_ReplaceString($resultbox, 0, $correctedresult) ; update our GUI to reflect the equation
EndFunc   ;==>makeResults

Func Quit()
    Exit ; quit our script
EndFunc   ;==>Quit
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Thanks for the help. It was a bit frustrating because I could easily write a script that used message boxes with inputs to accomplish the task. Since I haven't tried using an AutoIt GUI before I figured this would be an excellent opportunity but I just couldn't figure it out.

Thanks again!

Link to comment
Share on other sites

Hey, no problem! It was just a couple things that needed to be changed around, taking on challenges is how we learn. :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...