Jump to content

Function runs twice and shouldn't


 Share

Recommended Posts

I Started using AutoIT a week ago to help make some repetitive tasks at work easier. I have made progress by searching the forums and using the help file. I thought I about had this figured out, but I have a problem and I am not sure why it is working the way it is. What I plan on is a GUI with inputs and a button for each input that call the same function. When the button is pressed it will take what information is in the input box and run a function to enter the $input information into another program. I was able to get this to work, but I also am going to need a few more buttons in the GUI that do not use the same function as the input boxes/buttons do.

When I click the $Load button it runs cmd.exe twice and I only want it to run once.

Also when I click the $Load1 button it does both the actions that pressing $button[0] and $button[1] take and I do not want it to.

Can someone point me in the right direction as to what I am doing wrong?

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

Global $Button[2], $Input[2]

$Form1 = GUICreate("Remedy Assinger")
$Input[0] = GUICtrlCreateInput("", 8, 8, 121, 21)
$Input[1] = GUICtrlCreateInput("", 8, 58, 121, 21)
$Button[0] = GUICtrlCreateButton("Send", 136, 8, 75, 25, 0)
$Button[1] = GUICtrlCreateButton("Send", 136, 58, 75, 25, 0)
$Load = GUICtrlCreateButton("Load", 136, 108, 75, 25, 0)
$Load1 = GUICtrlCreateButton("Load1", 136, 158, 75, 25, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    For $b = 0 to 1
        If $Msg = $GUI_EVENT_CLOSE then Exit
        If $Msg = $Button[$b] Then start()
        If $Msg = $Load Then run("cmd.exe")
        If $Msg = $Load1 Then start()
    Next
WEnd

Func start()
        Run("Notepad.exe")
        Sleep(3000)
        Send(GUICtrlRead($Input[$b]))
    EndFunc
Link to comment
Share on other sites

  • Developers

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE then Exit
    For $b = 0 to 1
        If $Msg = $Button[$b] Then start()
    Next
    If $Msg = $Load Then run("cmd.exe")
    If $Msg = $Load1 Then start()
WEnd

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE then Exit
    For $b = 0 to 1
        If $Msg = $Button[$b] Then start()
    Next
    If $Msg = $Load Then run("cmd.exe")
    If $Msg = $Load1 Then start()
WEnd
Nice! Thanks! That was simple enough, and I spent a while trying to figure that out. :D
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...