Jump to content

Help assigning functions to buttons


Jadog
 Share

Recommended Posts

I'm rather new at this and I just created my first gui. I have a few buttons that I would like to assign functions to and after spending a considerable amount of time watching training tutorials, I just can't seem to get it right. This is the gui script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Marquee.au3>
#include <excel.au3>
;
;
;
;
#region ### START Koda GUI section ### Form=P:TopLevelAHOHActivityImportSG2CPSG2CP.kxf
$Form1 = GUICreate("SG to CP Import Tool", 514, 427, 571, 195)
$Group1 = GUICtrlCreateGroup("CP Information", 8, 8, 497, 201)
$Input1 = GUICtrlCreateInput("MyServerTopLevelCompanyActivityImport", 136, 36, 361, 21)
GUICtrlSetTip(-1, "Select your import directory (Ex: MyServerTopLevelCompanyActivityImport")
$Label1 = GUICtrlCreateLabel("CP Local Bin Directory", 26, 64, 110, 17)
$Label2 = GUICtrlCreateLabel("Server Import Directory", 24, 40, 112, 17)
$Label3 = GUICtrlCreateLabel("Company Alias", 66, 101, 73, 17)
$Label4 = GUICtrlCreateLabel("User ID", 96, 128, 40, 17)
$Label5 = GUICtrlCreateLabel("Password", 86, 152, 50, 17)
$Label6 = GUICtrlCreateLabel("Workgroup", 79, 176, 57, 17)
$Input2 = GUICtrlCreateInput("C:Program FilesRSCPCPSQL - StationBin", 136, 60, 361, 21)
GUICtrlSetTip(-1, "Select the CP Bin directory (Ex: C:Program FilesRSCPCPSQL - StationBin")
$Input3 = GUICtrlCreateInput("", 136, 96, 225, 21)
$Input4 = GUICtrlCreateInput("", 136, 124, 193, 21)
$Input5 = GUICtrlCreateInput("", 136, 148, 193, 21)
$Input6 = GUICtrlCreateInput("1", 136, 172, 193, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Import or Verify", 8, 320, 153, 73)
$Radio1 = GUICtrlCreateRadio("Import", 16, 344, 113, 17)
$Radio2 = GUICtrlCreateRadio("Verify", 16, 360, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Import", 368, 344, 121, 41)
$Group3 = GUICtrlCreateGroup("Remove Duplicates on Import", 8, 224, 169, 89)
$Radio3 = GUICtrlCreateRadio("All", 16, 248, 113, 17)
$Radio4 = GUICtrlCreateRadio("Specific", 16, 264, 113, 17)
$Radio5 = GUICtrlCreateRadio("Added on Import", 16, 280, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Checkbox1 = GUICtrlCreateCheckbox("Round retail prices to the nearest .05 or .09", 224, 232, 233, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Import Vendor Units", 224, 256, 121, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Auto Accept Price Changes", 224, 280, 225, 17)
$Button2 = GUICtrlCreateButton("Cancel", 228, 344, 121, 41)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd

I am trying to set the Import button ($Button1) to begin the following function:

$oExcel = _ExcelBookOpen($Input1 & "SG Update Vendor Items & Add New Products.xls", 1)
If @error = 1 Then
MsgBox(0, "Error!", "Unable to Create the Excel Object")
Exit
ElseIf @error = 2 Then
MsgBox(0, "Error!", "File does not exist!")
Exit
EndIf

I am also at a loss how to set the Cancel button (#Button2) to exit and close the gui. Any help would be very much appreciated!

Edited by Jadog
Link to comment
Share on other sites

For your button action use something like this:

Case $Button1
        $oExcel = _ExcelBookOpen($Input1 & "SG Update Vendor Items & Add New Products.xls", 1)
        If @error = 1 Then
            MsgBox(0, "Error!", "Unable to Create the Excel Object")
            Exit
        ElseIf @error = 2 Then
            MsgBox(0, "Error!", "File does not exist!")
            Exit
        EndIf

Add that after the case statement for $GUI_EVENT_CLOSE, add your other buttons as needed using the same format.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I tend to go another route:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("MyGui",560,175,200,150)
GUISetOnEvent($GUI_EVENT_CLOSE,"_ExitFunction")

$Button1 = GUICtrlCreateButton("EXIT",450,65,100,50)

GUICtrlSetOnEvent($Button1,"_MyFunction")

GUISetState(@SW_SHOW)

While 1
     Sleep(100)
Wend

Func _MyFunction()
     MsgBox(262144,"Button Click","You clicked the button!")
     _ExitFunction()
EndFunc

Func _ExitFunction()
     Exit
EndFunc

If you try to fail and succeed which have you done?AutoIt Forum Search

Link to comment
Share on other sites

That would only work if he was using OnEvent mode, but from the code in the OP he was using the message loop mode, so that was how I figured he wanted to go.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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