Jump to content

Newbie With A Question...


Recommended Posts

I created a GUI and I have a script written as well. Basicall the GUI is a form of input fields with a Go button that I would like to run a script to use the data from the input fields to enter into corresponding fields in some programs. I finally figured out how to execute something upon button click, but do I paste my script code in my GUI (like upon button click run this script) or do I point the GUI to another autoit script, i.e. script.exe? Can I pull global variables from the GUI file and use them in another script?

Here is the GUI I've got setup now:

#include <GuiConstants.au3>

; initialize variables
Global $serial
Global $username
Global $password
Global $radius
Global $description
Global $btn

; GUI
GuiCreate("Title", 400, 500)
GuiSetIcon("icon.exe", 0)

; PIC
GuiCtrlCreatePic("logo.gif",168.5,10,63,56)

; INPUT
$serial = GuiCtrlCreateInput("", 225, 75, 100, 20)
GUICtrlCreateLabel("Serial Number - No Dashes ex. L3XXXXX",20,80)

; INPUT
$username = GuiCtrlCreateInput("", 225, 110, 100, 20)
GUICtrlCreateLabel("Network UserName",20,115)

; INPUT
$password = GuiCtrlCreateInput("", 225, 145, 100, 20,$ES_PASSWORD)
GUICtrlCreateLabel("Windows Login Password",20,150)

; INPUT
$radius = GuiCtrlCreateInput("", 225, 180, 100, 20,$ES_PASSWORD)
GUICtrlCreateLabel("RADIUS Password",20,185)

; INPUT
$description = GuiCtrlCreateInput("Example: John Smith - IBM ThinkPad T43", 75, 255, 250, 20)
GUICtrlCreateLabel("Your Name - Brand and Model of PC",100,230)

; GROUP WITH RADIO BUTTONS
GuiCtrlCreateGroup("Type", 150, 315, 100, 75)
GuiCtrlCreateRadio("Laptop", 170, 335, 60)
GuiCtrlSetState(-1, $GUI_CHECKED)
GuiCtrlCreateRadio("Desktop", 170, 360, 60)
GUICtrlCreateGroup ("",-99,-99,1,1) ;close group

; BUTTON
$btn = GuiCtrlCreateButton("Go", 150, 400, 100, 30)

; PROGRESS
GuiCtrlCreateProgress(75, 450, 275, 20)
GuiCtrlSetData(-1, 60)
GuiCtrlCreateLabel("Progress:",20,450)


; GUI MESSAGE LOOP
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $btn
run("script.exe")
Case Else
;;;
EndSelect
WEnd

So, again my question is do I keep script.exe upon button click or do I just remove run("script.exe") and paste the script there?

Any suggestions are welcome. Thanks!

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

I created a GUI and I have a script written as well. Basicall the GUI is a form of input fields with a Go button that I would like to run a script to use the data from the input fields to enter into corresponding fields in some programs. I finally figured out how to execute something upon button click, but do I paste my script code in my GUI (like upon button click run this script) or do I point the GUI to another autoit script, i.e. script.exe? Can I pull global variables from the GUI file and use them in another script?

Here is the GUI I've got setup now:

#include <GuiConstants.au3>

; initialize variables
Global $serial
Global $username
Global $password
Global $radius
Global $description
Global $btn

; GUI
GuiCreate("Title", 400, 500)
GuiSetIcon("icon.exe", 0)

; PIC
GuiCtrlCreatePic("logo.gif",168.5,10,63,56)

; INPUT
$serial = GuiCtrlCreateInput("", 225, 75, 100, 20)
GUICtrlCreateLabel("Serial Number - No Dashes ex. L3XXXXX",20,80)

; INPUT
$username = GuiCtrlCreateInput("", 225, 110, 100, 20)
GUICtrlCreateLabel("Network UserName",20,115)

; INPUT
$password = GuiCtrlCreateInput("", 225, 145, 100, 20,$ES_PASSWORD)
GUICtrlCreateLabel("Windows Login Password",20,150)

; INPUT
$radius = GuiCtrlCreateInput("", 225, 180, 100, 20,$ES_PASSWORD)
GUICtrlCreateLabel("RADIUS Password",20,185)

; INPUT
$description = GuiCtrlCreateInput("Example: John Smith - IBM ThinkPad T43", 75, 255, 250, 20)
GUICtrlCreateLabel("Your Name - Brand and Model of PC",100,230)

; GROUP WITH RADIO BUTTONS
GuiCtrlCreateGroup("Type", 150, 315, 100, 75)
GuiCtrlCreateRadio("Laptop", 170, 335, 60)
GuiCtrlSetState(-1, $GUI_CHECKED)
GuiCtrlCreateRadio("Desktop", 170, 360, 60)
GUICtrlCreateGroup ("",-99,-99,1,1);close group

; BUTTON
$btn = GuiCtrlCreateButton("Go", 150, 400, 100, 30)

; PROGRESS
GuiCtrlCreateProgress(75, 450, 275, 20)
GuiCtrlSetData(-1, 60)
GuiCtrlCreateLabel("Progress:",20,450)
; GUI MESSAGE LOOP
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $btn
run("script.exe")
Case Else
;;;
EndSelect
WEnd

So, again my question is do I keep script.exe upon button click or do I just remove run("script.exe") and paste the script there?

Any suggestions are welcome. Thanks!

you could or you could pass command line args to the other script and have that script parse the command line args

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Moderators

Here is an example of how to use OnEventMode()

#include <GuiConstants.au3>

; Change to OnEvent mode
Opt('GUIOnEventMode', True)

; initialize variables
Global $serial
Global $username
Global $password
Global $radius
Global $description

; GUI
GuiCreate("Title", 400, 500)
GuiSetIcon("icon.exe", 0)
GUISetOnEvent($GUI_EVENT_CLOSE, 'Event_GUIClose')

; PIC
GuiCtrlCreatePic("logo.gif",168.5,10,63,56)

; INPUT
$serial = GuiCtrlCreateInput("", 225, 75, 100, 20)
GUICtrlCreateLabel("Serial Number - No Dashes ex. L3XXXXX",20,80)

; INPUT
$username = GuiCtrlCreateInput("", 225, 110, 100, 20)
GUICtrlCreateLabel("Network UserName",20,115)

; INPUT
$password = GuiCtrlCreateInput("", 225, 145, 100, 20,$ES_PASSWORD)
GUICtrlCreateLabel("Windows Login Password",20,150)

; INPUT
$radius = GuiCtrlCreateInput("", 225, 180, 100, 20,$ES_PASSWORD)
GUICtrlCreateLabel("RADIUS Password",20,185)

; INPUT
$description = GuiCtrlCreateInput("Example: John Smith - IBM ThinkPad T43", 75, 255, 250, 20)
GUICtrlCreateLabel("Your Name - Brand and Model of PC",100,230)

; GROUP WITH RADIO BUTTONS
GuiCtrlCreateGroup("Type", 150, 315, 100, 75)
GuiCtrlCreateRadio("Laptop", 170, 335, 60)
GuiCtrlSetState(-1, $GUI_CHECKED)
GuiCtrlCreateRadio("Desktop", 170, 360, 60)
GUICtrlCreateGroup ("",-99,-99,1,1);close group

; BUTTON
GUICtrlCreateButton("Go", 150, 400, 100, 30)
GUICtrlSetOnEvent(-1, 'MyFunction')

; PROGRESS
GuiCtrlCreateProgress(75, 450, 275, 20)
GuiCtrlSetData(-1, 60)
GuiCtrlCreateLabel("Progress:",20,450)

GUISetState(@SW_SHOW)

While 1
    Sleep(250)
WEnd

Func MyFunction()
    
; Hide the GUI while the function is running
    GUISetState(@SW_HIDE)
; ================
; The script you wish to run should go here
; ================
; Just a test to show that the GUI disapears
    MsgBox(0, "", "Test")
; Show the GUI after the funtion is finished
    GUISetState(@SW_SHOW)
    
EndFunc 

; =============================================================================
; Event_GUIClose():
;    Called when the GUI is asked to close (e.g. when the user clicks the X).
; =============================================================================

Func Event_GUIClose()
    
    Exit
    
EndFunc  ;==>Event_GUIClose
Link to comment
Share on other sites

Here is an example of how to use OnEventMode()

For some reason when I go to close the gui now the x doesn't do anything and the gui stays open. But the rest of it is awesome! Thank you so much!

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
Link to comment
Share on other sites

For some reason when I go to close the gui now the x doesn't do anything and the gui stays open. But the rest of it is awesome! Thank you so much!

try changing

Opt('GUIOnEventMode', True)

to

Opt('GUIOnEventMode', 1)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Works great!

Thanks!

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt
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...