Jump to content

"OK" Button question


dm83737
 Share

Recommended Posts

DISCLAIMER - I apologize if this seems remedial or that there are a thousand posts already explaining this. I have tried searching for what I am about to ask both in the help file and in this forum and can not seem to search for the right thing apparently. So now, on to embarrassing myself...

I can't seem to find anything other than "You hit the OK button" as something to make the OK button do when pressed/clicked. As you can see in my script below, I am trying to take the info entered by the user and use that as the starting and ending coordinates for a loop that refers to an Excel spreadsheet. About the only thing I could find is what I have already entered. I do know that I need to somehow make the AutoIT script transition from the GUI to actual loop of the rest of the script, but again, I am unfamiliar on how to do that. I did appreciate in my past posts more advanced users pointing me to the tutorial posts (i.e. - AutoIT 1-2-3, etc.), but for some reason, they only give the "You hit the OK button" as a response from doing just that.

If there are other inefficiencies in my code (I know there are probably plenty), I would appreciate some constructive criticism there as well:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         Dan Maxwell

 Script Function:
    Automatically exports the GPIN to a .CSV file

#ce ----------------------------------------------------------------------------

#include <Excel.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode
Opt("GUIResizeMode", 1); Keeps the GUI window from being resized by the user

Global $iA, $iB, $iC, $iD
Global $sMessage, $vPath, $sFilePath1, $oExcel, $fVisible, $sCellValue
Global $Form1_1, $ColumnInput, $ColumnLabel, $ColumnExplanationLabel, $RowStartInput, $RowEndInput, $RowStartLabel, $RowEndLabel
Global $OKButton, $CancelButton

; Variable List

; Setting up the noting of bad policies
Run("notepad.exe")
    WinWaitActive ("Untitled - Notepad")
    Send ("Policies whose GPIN's are empty:")
    Send ("{ENTER}")
    Send ("{ENTER}")

; Makes sure the ADMINISTRATOR is open so test can proceed
MsgBox (64, "The ADMINISTRATOR", "You must be logged into The ADMINISTRATOR in order to proceed", 30)

If WinExists("The ADMINISTRATOR") Then
    Sleep (100)
Else
    MsgBox (16, "Error", "The ADMINISTRATOR is not open.  Exiting...", 5)
    Exit
EndIf

$message = "Please choose the file with the policy listing"

$var = FileOpenDialog($message, @DesktopCommonDir & "\", "Excel Spreadsheet (*.xls)", 1 + 4 )

;$answer1 = InputBox("Column Setup", "Which column would you like to read from?   <i.e. - A=1, B=2, etc.>", "6", "", -1, -1, Default, Default)
;$answer2 = InputBox("Row Setup", "Which row would you like to read from?     <i.e. - 1, 2, etc.>", "2", "", -1, -1, Default, Default)
;$answer3 = InputBox("Row Setup", "What is the last row to read from?     <i.e. - 20, 80, etc.>", "84", "", -1, -1, Default, Default)

; -------------------------------------------------------------------------------------------------------------------------------------;

; This creates the window GUI form
$Form1_1 = GUICreate("Policy Number Look-up", 328, 236, 457, 239)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

; Tells which column to start in.  This is a numerical field, the letters correspond to the number of the letter
;    i.e. - A=1  B=2  C=3  D=4  etc.
$iColumnInput = GUICtrlCreateInput("", 16, 16, 33, 22, $ES_NUMBER)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_FOCUS); <=== the focus starts out on $ColumnInput
$sColumnLabel = GUICtrlCreateLabel("Which column would you like to read from?", 72, 16, 211, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$sColumnExplanationLabel = GUICtrlCreateLabel("i.e. - A=1, B=2, C=3, etc.", 96, 40, 122, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

; Tells which row is the first row to read (aka the beginning of your list)
$iRowStartInput = GUICtrlCreateInput("", 16, 88, 33, 23, $ES_NUMBER)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
$sRowStartLabel = GUICtrlCreateLabel("Which row would you like to start reading from?", 72, 88, 236, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

; Tells which row is the last row to read (aka the end of your list)
$iRowEndInput = GUICtrlCreateInput("", 16, 144, 33, 22, $ES_NUMBER)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
$sRowEndLabel = GUICtrlCreateLabel("What is the last row to read from?", 72, 144, 169, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

; Creates the OK and Cancel buttons on the GUI
$OKButton = GUICtrlCreateButton("OK", 72, 192, 75, 25, 0)
GUICtrlSetOnEvent($OKButton, "OKButton")
$CancelButton = GUICtrlCreateButton("Cancel", 184, 192, 75, 25, 0)
GUICtrlSetOnEvent($CancelButton, "CancelButton")
GUISetState(@SW_SHOW)

; Dictates the behavior of the window
While 1
    Sleep(1000); Sets window to idle
WEnd

Func OKButton() ; When you press the 'OK' button
    $iA = GUICtrlRead($iColumnInput); 
    $iB = GUICtrlRead($iRowStartInput); 
    $iC = GUICtrlRead($iRowEndInput); 
        
EndFunc  ;==>OKButton

Func CancelButton()
;Note: at this point @GUI_CTRLID would equal $CancelButton,
;and @GUI_WINHANDLE would equal $mainwindow
        Exit
EndFunc  ;==>CancelButton

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit

        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE

        Case @GUI_CtrlId = $GUI_EVENT_RESTORE

    EndSelect
EndFunc  ;==>SpecialEvents

; -------------------------------------------------------------------------------------------------------------------------------------;

; Opens the Add_Contract script
$sFilePath1 = $var
; Sets the spreadsheet to appear or stay invisible
$fVisible = 1
$oExcel = _ExcelBookOpen ($sFilePath1,$fVisible)
;Sets the Sheet to the actual script and not other sheets within the script
_ExcelSheetActivate ($oExcel, 1)

; Tells the loop to run from row # to #
For $iD = $iB To $iC
; Each policy number in that column is now referred to as the variable $sCellValue
$sCellValue = _ExcelReadCell ($oExcel, $iD, $iA)

; Procedures
WinActivate ("The ADMINISTRATOR")
WinMove ("The ADMINISTRATOR", "", 0, 0)
MouseClick ("left",110, 65, 1, 0)
Send ("GPIN")
Sleep (25)
Send ($sCellValue)
Send ("{TAB}")
Sleep (25)
Send ("UC1{F11}")
Sleep (5000)

If WinExists ("  Processing") Then
    WinClose ("  Processing")
    WinActivate ("Untitled - Notepad")
    Send ($sCellValue)
    Send ("{ENTER}")
Else
    WinActivate ("The ADMINISTRATOR")
    MouseClick ("left", 640, 145, 1, 0)
    MouseClick ("left", 640, 180, 1, 0)
    MouseClick ("left", 725, 142, 1, 0)
    WinActivate ("Export Window")
    MouseClick ("left", 735, 330, 1, 15)
    Send ("C:\GPIN\")
    Send ($sCellValue)
    Send (".csv")
    MouseClick ("left", 630, 425, 1, 0)

EndIf

Next

; Saves the cuesheet to the CUE's directory
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!y")
Send (@DesktopCommonDir)
Send ("No GPIN policies")
Send (".txt")
Send ("{ENTER}")

_ExcelBookClose($oExcel, 1, 0)

Thanks

Link to comment
Share on other sites

Hope this helps...

#cs ----------------------------------------------------------------------------
    
    AutoIt Version: 3.3.0.0
    Author:         Dan Maxwell
    
    Script Function:
    Automatically exports the GPIN to a .CSV file
    
#ce ----------------------------------------------------------------------------

#include <Excel.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode
Opt("GUIResizeMode", 1); Keeps the GUI window from being resized by the user

Global $iA, $iB, $iC, $iD
Global $sMessage, $vPath, $sFilePath1, $oExcel, $fVisible, $sCellValue
Global $Form1_1, $ColumnInput, $ColumnLabel, $ColumnExplanationLabel, $RowStartInput, $RowEndInput, $RowStartLabel, $RowEndLabel
Global $OKButton, $CancelButton

; Variable List

; Setting up the noting of bad policies
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("Policies whose GPIN's are empty:")
Send("{ENTER}")
Send("{ENTER}")

; Makes sure the ADMINISTRATOR is open so test can proceed
MsgBox(64, "The ADMINISTRATOR", "You must be logged into The ADMINISTRATOR in order to proceed", 30)

If WinExists("The ADMINISTRATOR") Then
    Sleep(100)
Else
    MsgBox(16, "Error", "The ADMINISTRATOR is not open.  Exiting...", 5)
    Exit
EndIf

$message = "Please choose the file with the policy listing"

$var = FileOpenDialog($message, @DesktopCommonDir & "\", "Excel Spreadsheet (*.xls)", 1 + 4)

;$answer1 = InputBox("Column Setup", "Which column would you like to read from?      <i.e. - A=1, B=2, etc.>", "6", "", -1, -1, Default, Default)
;$answer2 = InputBox("Row Setup", "Which row would you like to read from?      <i.e. - 1, 2, etc.>", "2", "", -1, -1, Default, Default)
;$answer3 = InputBox("Row Setup", "What is the last row to read from?      <i.e. - 20, 80, etc.>", "84", "", -1, -1, Default, Default)

; -------------------------------------------------------------------------------------------------------------------------------------;

; This creates the window GUI form
$Form1_1 = GUICreate("Policy Number Look-up", 328, 236, 457, 239)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

; Tells which column to start in.  This is a numerical field, the letters correspond to the number of the letter
;     i.e. - A=1  B=2  C=3  D=4  etc.
$iColumnInput = GUICtrlCreateInput("", 16, 16, 33, 22, $ES_NUMBER)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_FOCUS); <=== the focus starts out on $ColumnInput
$sColumnLabel = GUICtrlCreateLabel("Which column would you like to read from?", 72, 16, 211, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$sColumnExplanationLabel = GUICtrlCreateLabel("i.e. - A=1, B=2, C=3, etc.", 96, 40, 122, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

; Tells which row is the first row to read (aka the beginning of your list)
$iRowStartInput = GUICtrlCreateInput("", 16, 88, 33, 23, $ES_NUMBER)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
$sRowStartLabel = GUICtrlCreateLabel("Which row would you like to start reading from?", 72, 88, 236, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

; Tells which row is the last row to read (aka the end of your list)
$iRowEndInput = GUICtrlCreateInput("", 16, 144, 33, 22, $ES_NUMBER)
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
$sRowEndLabel = GUICtrlCreateLabel("What is the last row to read from?", 72, 144, 169, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")

; Creates the OK and Cancel buttons on the GUI
$OKButton = GUICtrlCreateButton("OK", 72, 192, 75, 25, 0)
GUICtrlSetOnEvent($OKButton, "OKButton")
$CancelButton = GUICtrlCreateButton("Cancel", 184, 192, 75, 25, 0)
GUICtrlSetOnEvent($CancelButton, "CancelButton")
GUISetState(@SW_SHOW)

; Dictates the behavior of the window
While 1
    Sleep(1000); Sets window to idle
WEnd

Func OKButton() ; When you press the 'OK' button
    $iA1 = GUICtrlRead($iColumnInput);
    $iB1 = GUICtrlRead($iRowStartInput);
    $iC1 = GUICtrlRead($iRowEndInput);
    GUISetState(@SW_HIDE, $Form1_1) ;********************************** ADDED*************************
    Run_Excel($iA1, $iB1, $iC1) ;********************************** ADDED*************************
EndFunc   ;==>OKButton

Func CancelButton()
    ;Note: at this point @GUI_CTRLID would equal $CancelButton,
    ;and @GUI_WINHANDLE would equal $mainwindow
    Exit
EndFunc   ;==>CancelButton

Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit

        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE

        Case @GUI_CtrlId = $GUI_EVENT_RESTORE

    EndSelect
EndFunc   ;==>SpecialEvents

; -------------------------------------------------------------------------------------------------------------------------------------;
Func Run_Excel($iA, $iB, $iC) ;********************************** ADDED*************************
    ; Opens the Add_Contract script
    $sFilePath1 = $var
    ; Sets the spreadsheet to appear or stay invisible
    $fVisible = 1
    $oExcel = _ExcelBookOpen($sFilePath1, $fVisible)
    ;Sets the Sheet to the actual script and not other sheets within the script
    _ExcelSheetActivate($oExcel, 1)

    ; Tells the loop to run from row # to #
    For $iD = $iB To $iC
        ; Each policy number in that column is now referred to as the variable $sCellValue
        $sCellValue = _ExcelReadCell($oExcel, $iD, $iA)

        ; Procedures
        WinActivate("The ADMINISTRATOR")
        WinMove("The ADMINISTRATOR", "", 0, 0)
        MouseClick("left", 110, 65, 1, 0)
        Send("GPIN")
        Sleep(25)
        Send($sCellValue)
        Send("{TAB}")
        Sleep(25)
        Send("UC1{F11}")
        Sleep(5000)

        If WinExists("  Processing") Then
            WinClose("  Processing")
            WinActivate("Untitled - Notepad")
            Send($sCellValue)
            Send("{ENTER}")
        Else
            WinActivate("The ADMINISTRATOR")
            MouseClick("left", 640, 145, 1, 0)
            MouseClick("left", 640, 180, 1, 0)
            MouseClick("left", 725, 142, 1, 0)
            WinActivate("Export Window")
            MouseClick("left", 735, 330, 1, 15)
            Send("C:\GPIN\")
            Send($sCellValue)
            Send(".csv")
            MouseClick("left", 630, 425, 1, 0)

        EndIf

    Next

    ; Saves the cuesheet to the CUE's directory
    WinClose("Untitled - Notepad")
    WinWaitActive("Notepad", "Do you want to save")
    Send("!y")
    Send(@DesktopCommonDir)
    Send("No GPIN policies")
    Send(".txt")
    Send("{ENTER}")

    _ExcelBookClose($oExcel, 1, 0)
    
    GUISetState(@SW_SHOW, $Form1_1) ;********************************** ADDED*************************

EndFunc   ;==>Run_Excel ;********************************** ADDED*************************

8)

NEWHeader1.png

Link to comment
Share on other sites

The scripting you added got me to where the GUI disappears and the Excel spreadsheet comes up as expected, but for some (and this happened when I had the $iA, $iB and $iC var's added through input boxes as well) it hangs on the following statement:

; Tells the loop to run from row # to #

For $iD = $iB To $iC

; Each policy number in that column is now referred to as the variable $sCellValue

$sCellValue = _ExcelReadCell($oExcel, $iD, $iA)

If I change the last variable in the quoted script from $iA (it refers to the column the script looks to) to a whole integer (i.e. - 6 in this case), it moves on and starts to perform the function Valuater modified for me. But if I leave it to the var $iA to take the input from the GUI, it hangs at this point.

Now I may be taking this post somewhere other than GUI support, so I apologize if I have. But if it is OK to ask here, I do not know why this stops the script.

Thanks for all the help!

Link to comment
Share on other sites

The scripting you added got me to where the GUI disappears and the Excel spreadsheet comes up as expected, but for some (and this happened when I had the $iA, $iB and $iC var's added through input boxes as well) it hangs on the following statement:

If I change the last variable in the quoted script from $iA (it refers to the column the script looks to) to a whole integer (i.e. - 6 in this case), it moves on and starts to perform the function Valuater modified for me. But if I leave it to the var $iA to take the input from the GUI, it hangs at this point.

Now I may be taking this post somewhere other than GUI support, so I apologize if I have. But if it is OK to ask here, I do not know why this stops the script.

Thanks for all the help!

I don't have any experience with the excel udf so if the following suggestion is of no use then my apologies.

When you have

$iC1 = GUICtrlRead($iRowEndInput);

you have a string in the variable $iC1

If you do this

$iC1 = Number(GUICtrlRead($iRowEndInput));

and the same with the other GuiCtrlReads it might make a difference.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

dm83737,

Try a little error-checking:

- Get the return value from the function and see what the error is.

- What exactly does the variable $iA hold?

Then perhaps...if it works when you set the variable to an integer - try it with Int($iA).

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

dm83737,

Try a little error-checking:

- Get the return value from the function and see what the error is.

- What exactly does the variable $iA hold?

Then perhaps...if it works when you set the variable to an integer - try it with Int($iA).

M23

This worked, thank you very much!

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...