Jump to content

GUI opening Another GUI but buttons not working


badapple89
 Share

Recommended Posts

Ok so I'm new to coding in general but have made a few small AutoIT scripts, now making a GUI to help us in the IT department with common issues :)

I have this that WORKS when run by itself

global $ReplaceUsername, $ReplaceInitials, $ReplaceDepartment

Dictate()

Func Dictate()

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$guiDictate = GUICreate("Create Dictation XML", 190, 150) ;Create GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUICtrlCreateLabel ("Username?", 10, 10)
$ReplaceUsername = GUICtrlCreateInput("dflemming", 80, 10) ;Username input box

GUICtrlCreateLabel ("Initials?", 10, 40)
$ReplaceInitials = GUICtrlCreateInput("XXX", 80, 40) ;Initiials inputbox

GUICtrlCreateLabel ("Department?", 10, 80)
$ReplaceDepartment = GUICtrlCreateCombo("", 80, 80, 80, 20) ;Combobox
GUICtrlSetData(-1, "Admin|Commercial|LDR|Liquor|LocGovt|Managers|Medical|PI", "Admin") ;Choices for combobox with Admin as default

$btnDS5 = GUICtrlCreateButton("DS5000", 20, 120, 60, 20) ;DS5000 button
$btnDS4 = GUICtrlCreateButton("DS4000", 100, 120, 60, 20) ;DS5000 button

GUICtrlSetOnEvent($btnDS5, "DS5000") ;If button pressed then do following
GUICtrlSetOnEvent($btnDS4, "DS4000") ;If button pressed then do following

GUISetState(@SW_SHOW) ;Set state
While 1
Sleep(1000) ; Idle around
WEnd

EndFunc

Func DS5000()
$Username = GUICtrlRead($ReplaceUsername) ;Get user input from verable
$Initials = GUICtrlRead($ReplaceInitials) ;Get user input from verable
$Department = GUICtrlRead($ReplaceDepartment) ;Get user input from verable

$btnSave = MsgBox(1, "Choice", $Username & @LF & $Initials & @LF & $Department & @LF & "DS5000") ;Create msg to list all inputs
if $btnSave = 1 Then ;If ok then create doc

;Declair Origonal file
$TextFileName = "\\adl-file\Software\Dictation\V5 Dictate xmls\DS5000.xml"

;Check if file actually exists
If FileExists($TextFileName) Then

;Locations to save
$LocationToSave1 = "\\adl-file\profiles$\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"
$LocationToSave2 = "C:\Documents and Settings\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"

;Delete existing xmls
FileDelete ($LocationToSave1 & "*.*")
FileDelete ($LocationToSave2 & "*.*")

;Copy Preference file
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave1, 1)
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave2, 1)

;Text to find
$FindUsername = "username"
$FindInitials = "xxx"
$FindDepartment = "dept"

;Replace text
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents,$FindInitials,$Initials)
$FileContents = StringReplace($FileContents,$FindUsername,$Username)
$FileContents = StringReplace($FileContents,$FindDepartment,$Department)

;Save file to location using username as the filename.
FileWrite($LocationToSave1 & $Username & ".xml",$FileContents)
FileWrite($LocationToSave2 & $Username & ".xml",$FileContents)
Exit
;If $TextFileName doesnt exist say so and exit
Else
MsgBox(4096, "ERROR", "Template file can't be found." & @LF & $TextFileName)
Exit
EndIf
EndIf
EndFunc

Func DS4000()
$Username = GUICtrlRead($ReplaceUsername) ;Get user input from verable
$Initials = GUICtrlRead($ReplaceInitials) ;Get user input from verable
$Department = GUICtrlRead($ReplaceDepartment) ;Get user input from verable

$btnSave = MsgBox(1, "Choice", $Username & @LF & $Initials & @LF & $Department & @LF & "DS4000") ;Create msg to list all inputs
if $btnSave = 1 Then ;If ok then create doc

;Origonal file
$TextFileName = "\\adl-file\Software\Dictation\V5 Dictate xmls\DS4000.xml"

;Check if file actually exists
If FileExists($TextFileName) Then

;Locations to save
$LocationToSave1 = "\\adl-file\profiles$\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"
$LocationToSave2 = "C:\Documents and Settings\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"

;Delete existing xmls
FileDelete ($LocationToSave1 & "*.*")
FileDelete ($LocationToSave2 & "*.*")

;Copy Preference file
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave1, 1)
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave2, 1)

;Text to find
$FindUsername = "username"
$FindInitials = "xxx"
$FindDepartment = "dept"

;Replace text
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents,$FindInitials,$Initials)
$FileContents = StringReplace($FileContents,$FindUsername,$Username)
$FileContents = StringReplace($FileContents,$FindDepartment,$Department)

;Save file to location using username as the filename.
FileWrite($LocationToSave1 & $Username & ".xml",$FileContents)
FileWrite($LocationToSave2 & $Username & ".xml",$FileContents)
Exit

;If $TextFileName doesnt exist say so and exit
Else
MsgBox(4096, "ERROR", "Template file can't be found." & @LF & $TextFileName)
Exit
EndIf
EndIf
EndFunc

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

(might be a bit funky coz I was just playing with it but it works when run)

However I'm trying to launch all that from another GUI (all in the one script)

But when I press the button in my first GUI, the 2nd GUI will pop up but no buttons on it will work and BOTH close buttons wont work.

Have to end out of the script to close them!

#include <GUIConstantsEx.au3>

;For testing of dictation
global $ReplaceUsername, $ReplaceInitials, $ReplaceDepartment

;Set GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Restart Process", 220, 180)
$pos = WinGetPos($mainwindow)
WinMove($mainwindow, "", @DesktopWidth-$pos[2], @DesktopHeight-$pos[3]-30)
;WinSetOnTop($mainwindow,"",1)



GUICtrlCreateLabel("IT STAFF USE ONLY", 55, 10, 220)
GUICtrlSetFont(-1, 8.5, 5000)
GUICtrlSetColor(-1, 0xff0000) ; Red
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked_Main")


$butDictate = GUICtrlCreateButton("Dictation", 150, 140, 60)
GUICtrlSetOnEvent($butDictate, "Dictate")

GUISetState(@SW_SHOW)
While 1
Sleep(1000) ; Idle around
WEnd

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
; FUNCTIONS ; ; FUNCTIONS ; ; FUNCTIONS ; ; FUNCTIONS ; ; FUNCTIONS ; ; FUNCTIONS ; ;
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;

;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
Func CLOSEClicked_Main()
;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
;and @GUI_WINHANDLE would equal $mainwindow
Exit
EndFunc
;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------;
Func Dictate ()
GUICtrlSetState($butDictate, $GUI_DISABLE)

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$guiDictate = GUICreate("Create Dictation XML", 190, 150) ;Create GUI
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked_Dictate")
;WinActivate ($guiDictate)

GUICtrlCreateLabel ("Username?", 10, 10)
$ReplaceUsername = GUICtrlCreateInput("dflemming", 80, 10) ;Username input box

GUICtrlCreateLabel ("Initials?", 10, 40)
$ReplaceInitials = GUICtrlCreateInput("XXX", 80, 40) ;Initiials inputbox

GUICtrlCreateLabel ("Department?", 10, 80)
$ReplaceDepartment = GUICtrlCreateCombo("", 80, 80, 80, 20) ;Combobox
GUICtrlSetData(-1, "Admin|Commercial|LDR|Liquor|LocGovt|Managers|Medical|PI", "Admin") ;Choices for combobox with Admin as default

$btnDS5 = GUICtrlCreateButton("DS5000", 20, 120, 60, 20) ;DS5000 button
$btnDS4 = GUICtrlCreateButton("DS4000", 100, 120, 60, 20) ;DS5000 button

GUICtrlSetOnEvent($btnDS5, "DS5000") ;If button pressed then do following
GUICtrlSetOnEvent($btnDS4, "DS4000") ;If button pressed then do following


GUISetState(@SW_SHOW) ;Set state
While 1
Sleep(1000) ; Idle around
WEnd
EndFunc

Func DS5000()

$Username = GUICtrlRead($ReplaceUsername) ;Get user input from verable
$Initials = GUICtrlRead($ReplaceInitials) ;Get user input from verable
$Department = GUICtrlRead($ReplaceDepartment) ;Get user input from verable

$btnSave = MsgBox(1, "Choice", $Username & @LF & $Initials & @LF & $Department & @LF & "DS5000") ;Create msg to list all inputs
if $btnSave = 1 Then ;If ok then create doc

;Declair Origonal file
$TextFileName = "\\adl-file\Software\Dictation\V5 Dictate xmls\DS5000.xml"

;Check if file actually exists
If FileExists($TextFileName) Then

;Locations to save
$LocationToSave1 = "\\adl-file\profiles$\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"
$LocationToSave2 = "C:\Documents and Settings\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"

;Delete existing xmls
FileDelete ($LocationToSave1 & "*.*")
FileDelete ($LocationToSave2 & "*.*")

;Copy Preference file
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave1, 1)
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave2, 1)

;Text to find
$FindUsername = "username"
$FindInitials = "xxx"
$FindDepartment = "dept"

;Replace text
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents,$FindInitials,$Initials)
$FileContents = StringReplace($FileContents,$FindUsername,$Username)
$FileContents = StringReplace($FileContents,$FindDepartment,$Department)

;Save file to location using username as the filename.
FileWrite($LocationToSave1 & $Username & ".xml",$FileContents)
FileWrite($LocationToSave2 & $Username & ".xml",$FileContents)
Exit
;If $TextFileName doesnt exist say so and exit
Else
MsgBox(4096, "ERROR", "Template file can't be found." & @LF & $TextFileName)
Exit
EndIf
EndIf
EndFunc

Func DS4000()

$Username = GUICtrlRead($ReplaceUsername) ;Get user input from verable
$Initials = GUICtrlRead($ReplaceInitials) ;Get user input from verable
$Department = GUICtrlRead($ReplaceDepartment) ;Get user input from verable

$btnSave = MsgBox(1, "Choice", $Username & @LF & $Initials & @LF & $Department & @LF & "DS4000") ;Create msg to list all inputs
if $btnSave = 1 Then ;If ok then create doc

;Origonal file
$TextFileName = "\\adl-file\Software\Dictation\V5 Dictate xmls\DS4000.xml"

;Check if file actually exists
If FileExists($TextFileName) Then

;Locations to save
$LocationToSave1 = "\\adl-file\profiles$\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"
$LocationToSave2 = "C:\Documents and Settings\"&@UserName&"\Application Data\Olympus\DSSPlayerProR5\"

;Delete existing xmls
FileDelete ($LocationToSave1 & "*.*")
FileDelete ($LocationToSave2 & "*.*")

;Copy Preference file
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave1, 1)
FileCopy ("\\adl-file\Software\Dictation\V5 Dictate xmls\Preference.xml", $LocationToSave2, 1)

;Text to find
$FindUsername = "username"
$FindInitials = "xxx"
$FindDepartment = "dept"

;Replace text
$FileContents = FileRead($TextFileName)
$FileContents = StringReplace($FileContents,$FindInitials,$Initials)
$FileContents = StringReplace($FileContents,$FindUsername,$Username)
$FileContents = StringReplace($FileContents,$FindDepartment,$Department)

;Save file to location using username as the filename.
FileWrite($LocationToSave1 & $Username & ".xml",$FileContents)
FileWrite($LocationToSave2 & $Username & ".xml",$FileContents)
Exit

;If $TextFileName doesnt exist say so and exit
Else
MsgBox(4096, "ERROR", "Template file can't be found." & @LF & $TextFileName)
Exit
EndIf
EndIf
EndFunc

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

Sorry that its a little messy, but any help appreciated.

Thanks BadApple

Link to comment
Share on other sites

  • Moderators

badapple89,

Welcome to the AutoIt forum. :)

Have a read of the Managing Multiple GUIs tutorial in the Wiki and come back you still have problems. ;)

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

Actually another question. Same script so Ill post it here (ill move if needed).

I have to have this line at the start of my script as it tells me im using variables without deceleration.

Tried to put them in the functions themselves (the first 3 are used in the 2nd gui the last 3 in main GUI) but that didn't work either.

global $ReplaceUsername, $ReplaceInitials, $ReplaceDepartment, $comRDC, $butWord, $butDictate

Fair enough. But my question is. Why isn't it telling me to declair $butOutlook and $butInsight. The code for them is the SAME as $butWord?!?

Here is the full starting bit of my code (should I post the whole thing?)

#include 

;For testing of dictation
global $ReplaceUsername, $ReplaceInitials, $ReplaceDepartment, $comRDC, $butWord, $butDictate

global $mainwindow, $guiDictate = 9999

Main_window ()

Func Main_window ()

;Set GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
$mainwindow = GUICreate("Restart Process", 220, 180)
$pos = WinGetPos($mainwindow)
WinMove($mainwindow, "", @DesktopWidth-$pos[2], @DesktopHeight-$pos[3]-30)
;WinSetOnTop($mainwindow,"",1)



GUICtrlCreateLabel("IT STAFF USE ONLY", 55, 10, 220)
GUICtrlSetFont(-1, 8.5, 5000)
GUICtrlSetColor(-1, 0xff0000) ; Red
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

$comRDC = GUICtrlCreateCombo("", 50, 40, 70) ;Combobox
GUICtrlSetData(-1, "adl-exmail|adl-Apps|adl-Print|adl-TS2", "adl-exmail") ;Choices for combobox with Admin as default
$butRDC = GUICtrlCreateButton("Connect", 120, 38, 60)
GUICtrlSetOnEvent($butRDC, "RDC")

GUICtrlCreateLabel("Process to restart?", 70, 75)
$butWord = GUICtrlCreateButton("Word", 10, 90, 60)
GUICtrlSetOnEvent($butWord, "Word")
$butInsight = GUICtrlCreateButton("Insight", 80, 90, 60)
GUICtrlSetOnEvent($butInsight, "Insight")
$butOutlook = GUICtrlCreateButton("Outlook", 150, 90, 60)
GUICtrlSetOnEvent($butOutlook, "Outlook")

GUICtrlCreateLabel("Other Options", 80, 125)
$butFixVeiws = GUICtrlCreateButton("Fix Veiws", 80, 140, 60)
GUICtrlSetOnEvent($butFixVeiws, "FixVeiws")

$butDictate = GUICtrlCreateButton("Dictation", 150, 140, 60)
GUICtrlSetOnEvent($butDictate, "Dictate")

GUISetState(@SW_SHOW)
While 1
Sleep(1000) ; Idle around
WEnd
EndFunc
Link to comment
Share on other sites

  • Moderators

badapple89,

I imagine it is because you are trying to reference those variables you have now declared Global in other the functions which are not included in that snippet, whereas you are not doing so with the other 2. :)

I suggest reading the Variables - using Global, Local and ByRef tutorial in the Wiki to learn more about scoping variables. ;)

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

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