Jump to content

Recommended Posts

Posted

I made (2) text boxes, each one requiring the user to input a set of numbers. When the numbers are put in the text boxes the user would press [button] Run Notepad and functions coord1 and coord2 would send the input values [Send($x)  and Send($y)] on the note pad. I keep getting this error: [warning: $hInput1: possibly used before declaration.] 

#include <GUIConstantsEx.au3>
Local $x = $hInput1
Local $y = $hInput2

Example()

Func Example()

    ; Create a GUI with various controls.
    Local $iWidthCell = 70
    $hGUI = GUICreate("Test", 400, 250)
    GUICtrlCreateLabel("X:", 5, 15, $iWidthCell)
    $hInput1 = GUICtrlCreateInput("", 20, 10, 25, 20)
    GUICtrlCreateLabel("Y:", 48, 15, $iWidthCell)
    $hInput = GUICtrlCreateInput("", 60, 10, 25, 20)



    ; Create a button control.
    Local $idNotepad = GUICtrlCreateButton("Run Notepad", 120, 170, 85, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $iPID = 0

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop

            Case $idNotepad
                ; Run Notepad with the window maximized.
                $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

    ; Close the Notepad process using the PID returned by Run.
    If $iPID Then ProcessClose($iPID)
EndFunc   ;==>Example

;Calls first coords
Func coords1()
    Sleep(1000)
    Send($x)

EndFunc   ;==>coords1

;Calls second coords
Func coords2()
    Sleep(1000)
    Send($y)
EndFunc   ;==>coords2

 

Posted
#include <GUIConstantsEx.au3>
Local $x = 0
Local $y = 0

Example()

Func Example()

    ; Create a GUI with various controls.
    Local $iWidthCell = 70
    $hGUI = GUICreate("Test", 400, 250)
    GUICtrlCreateLabel("X:", 5, 15, $iWidthCell)
    $hInput1 = GUICtrlCreateInput("", 20, 10, 25, 20)
    GUICtrlCreateLabel("Y:", 48, 15, $iWidthCell)
    $hInput2 = GUICtrlCreateInput("", 60, 10, 25, 20)



    ; Create a button control.
    Local $idNotepad = GUICtrlCreateButton("Run Notepad", 120, 170, 85, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $iPID = 0

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop

            Case $idNotepad
                ; Run Notepad with the window maximized.
                $x = GUICtrlRead($hInput1)
                $y = GUICtrlRead($hInput2)
                $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
                coords1()
                coords2()

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

    ; Close the Notepad process using the PID returned by Run.
    If $iPID Then ProcessClose($iPID)
EndFunc   ;==>Example

;Calls first coords
Func coords1()
    Sleep(1000)
    Send($x)
EndFunc   ;==>coords1

;Calls second coords
Func coords2()
    Sleep(1000)
    Send($y)
EndFunc   ;==>coords2

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Posted

Ace.

You should also consider getting rid of global vars and passing the data directly to the functions.

#include <GUIConstantsEx.au3>

Example()

Func Example()

    ; Create a GUI with various controls.
    Local $iWidthCell = 70
    $hGUI = GUICreate("Test", 400, 250)
    GUICtrlCreateLabel("X:", 5, 15, $iWidthCell)
    $hInput1 = GUICtrlCreateInput("", 20, 10, 25, 20)
    GUICtrlCreateLabel("Y:", 48, 15, $iWidthCell)
    $hInput2 = GUICtrlCreateInput("", 60, 10, 25, 20)


    ; Create a button control.
    Local $idNotepad = GUICtrlCreateButton("Run Notepad", 120, 170, 85, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $iPID = 0

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop

            Case $idNotepad
                ; Run Notepad with the window maximized.
                $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)
                ; Call functions passing them the user daya
                coords1(GUICtrlRead($hInput1))
                coords2(GUICtrlRead($hInput2))

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

    ; Close the Notepad process using the PID returned by Run.
    If $iPID Then ProcessClose($iPID)
EndFunc   ;==>Example

;Calls first coords
Func coords1($x)
    Sleep(1000)
    Send($x)
EndFunc   ;==>coords1

;Calls second coords
Func coords2($y)
    Sleep(1000)
    Send($y)
EndFunc   ;==>coords2

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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
×
×
  • Create New...