Sign in to follow this  
Followers 0
happy2help

Trying to combine 2 working scripts -- help!

5 posts in this topic

I have 2 working scripts that i would like to combine so i get 1 systray icon and it all works from 1 place.

Scripts.rar

The reason i have foldermonitor2.au3 (the combined 1) as well as the others, is because the others are still in use!

When i run the script, i cant get the GUI to come up. When i click on "Show" nothing happens and the "Run Now" becomes "Show" too!

Share this post


Link to post
Share on other sites



happy2help,

Do you notice anything strange about this section of your script? :)

If @ComputerName = "washws1" Then
    TraySetIcon("C:\Users\Public\Backup\Batch files\Icons\FOLDER.ICO")
    MsgBox(0, "AutoIt", "THIS IS TONY'S PC", 10)
    Global $hTray_Show_Item = TrayCreateItem("OpenXpos Script", $menu)
    TrayItemSetOnEvent(-1, "On_Tray_openxpos")
    Global $hTray_Show_Item = TrayCreateItem("Monday Run", $menu)
    TrayItemSetOnEvent(-1, "On_Monday_Run")
    Global $hTray_Show_Item = TrayCreateItem("Monthly Run", $menu)
    TrayItemSetOnEvent(-1, "On_Monthly_Run")
    TrayCreateItem("")
    Global $hTray_Show_Item = TrayCreateItem("Show Import", $menu)
    TrayItemSetOnEvent(-1, "On_Show")
    Global $hTray_Show_Item = TrayCreateItem("DL_Watch")
    TrayItemSetOnEvent(-1, "On_Tray_Watch")
    TrayCreateItem("")
    Global $hTray_Show_Item = TrayCreateItem("Show")
    TrayItemSetOnEvent(-1, "On_Tray_Show")
EndIf   
Global $aFileList, $aFolderList, $sFileList, $sFolderList, $sFileList2

TrayCreateItem("")
Global $hTray_Show_Item = TrayCreateItem("Run Now")

Do think it is normal to save all your tray item ControlIDs to the same variable? :idea:

If you give them separate names, you should find that your GUI will display and only the items you wish will change text. :)

At least, that is what happens for me, but I had to comment out a lot of lines to get it to work on my machine.

I hope that helps. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

"I see" said the blind man!!

Makes sense to split up the variables now someone has pointed that out. It now works, but once the GUI is on show, i cant hide it with the "x" in the corner. It did in the separate script. Here is my amended script.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\Icons\DocumentRepository.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#RequireAdmin
#include "B:\Scripts\allneeded.au3"
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Opt("WinWaitDelay", 850) ;250 milliseconds
Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
Opt("SendKeyDelay", 50)          ;50 milliseconds
Opt("TrayOnEventMode", 1) ; Use event trapping for tray menu
Opt("TrayMenuMode", 3) ; Default tray menu items will not be shown
$s_dir =  '"C:\Users\Public\Backup\Batch files\Shoots\"'
TraySetIcon("B:\Scripts\online.ico")
$menu = TrayCreateMenu("Folder Monitor")
$smtp = "-smtp Mail.Global.FrontBridge.com -d shoots.co.uk"
$sScripts = "B:\Scripts\"
$sToUse = "B:\Scripts\To Use\"
If @ComputerName = "washws1" Then
    TraySetIcon("C:\Users\Public\Backup\Batch files\Icons\FOLDER.ICO")
    MsgBox(0, "AutoIt", "THIS IS TONY'S PC", 10)
    Global $hTray_Show_Item1 = TrayCreateItem("OpenXpos Script", $menu)
    TrayItemSetOnEvent(-1, "On_Tray_openxpos")
    Global $hTray_Show_Item2 = TrayCreateItem("Monday Run", $menu)
    TrayItemSetOnEvent(-1, "On_Monday_Run")
    Global $hTray_Show_Item3 = TrayCreateItem("Monthly Run", $menu)
    TrayItemSetOnEvent(-1, "On_Monthly_Run")
    TrayCreateItem("")
    Global $hTray_Show_Item4 = TrayCreateItem("Show Import", $menu)
    TrayItemSetOnEvent(-1, "On_Show")
    Global $hTray_Show_Item5 = TrayCreateItem("DL_Watch")
    TrayItemSetOnEvent(-1, "On_Tray_Watch")
    TrayCreateItem("")
    Global $hTray_Show_Item6 = TrayCreateItem("Show")
    TrayItemSetOnEvent(-1, "On_Tray_Show")
EndIf   
Global $aFileList, $aFolderList, $sFileList, $sFolderList, $sFileList2

TrayCreateItem("")
Global $hTray_Show_Item7 = TrayCreateItem("Run Now")
TrayItemSetOnEvent(-1, "On_Tray_Run")
TrayCreateItem("")
Global $hTray_Exit_Item = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

MsgBox(0, "WAIT", "FolderMonitor now running", 5)

readDir()
Func readDir() ;reading directories and putting it in a list
$sFileList = ""
$sFileList2 = ""
$sFolderList = ""
$aFileList = _FileListToArray($sToUse, "*", 1)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $i = 1 To $aFileList[0]
    $sFileList &= $aFileList[$i] & "|"
Next
$aFolderList = _FileListToArray($sScripts, "*", 2)
If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf
For $i = 1 To $aFolderList[0]
    If $aFolderList[$i] <> "To Use" Then
        $sFolderList &= $aFolderList[$i] & "|"
    EndIf
Next
EndFunc

#Region ; create GUI
$Form1 = GUICreate("Script Copier", 360, 300, 193, 125, -1, $WS_EX_TOOLWINDOW)
$List1 = GUICtrlCreateList("", 20, 20, 120, 270)
$List2 = GUICtrlCreateList("", 150, 20, 120, 270)
$Button1 = GUICtrlCreateButton("Copy Now", 280, 20, 73, 49, 0)
$Button2 = GUICtrlCreateButton("Update ini File", 280, 100, 73, 49, 0)
GUICtrlSetData($List1, $sFileList)
GUICtrlSetData($List2, $sFolderList)
GUISetState(@SW_HIDE)
#EndRegion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            TrayItemSetText($hTray_Show_Item6, "Show")
            GUISetState(@SW_HIDE, $Form1)
        Case $Button1
            CopyPressed()
        Case $Button2
            UpDate()
    EndSwitch
    On_Tray_Run()
    If @MIN = "00" Or @MIN = "15" Or @MIN = "30" Or @MIN = "45" And @ComputerName = "shootsepos1" Then servers()
    Sleep(60000) ; sleep 60 seconds
WEnd

Func On_Tray_openxpos()
    RunWait(@AutoItExe & " /AutoIt3ExecuteScript " & $s_dir & "OpenXpos.au3")
EndFunc

Func On_Monday_Run()
    RunWait(@AutoItExe & " /AutoIt3ExecuteScript " & $s_dir & "MondayRun.au3")
EndFunc

Func On_Monthly_Run()
    RunWait(@AutoItExe & " /AutoIt3ExecuteScript " & $s_dir & "MonthlyRun.au3")
EndFunc

Func On_Exit()
    Exit
EndFunc

Func On_Tray_Run()
    $filename = "FolderMonitor.ini"
    $file = FileOpen($filename, 0)
    $progy = "Empty"
    ; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.", 20)
        Sleep(300000)
        On_Tray_Run()
    EndIf
    
    ; Read in lines of text until the EOF is reached
    While 1
        $line = "B:\Scripts\" & @ComputerName & "\" & FileReadLine($file)
        If @error = -1 Then ExitLoop
        If FileExists ($line) Then
            RunWait(@AutoItExe & " /AutoIt3ExecuteScript " & $line)
            If $line = "B:\Scripts\" & @ComputerName & "\RestartServer.au3" Then $progy = $line
            If $line = "B:\Scripts\" & @ComputerName & "\Shutdown.au3" Then $progy = $line
            If $line = "B:\Scripts\" & @ComputerName & "\Hibernate.au3" Then $progy = $line
            Sleep (5000)
            FileDelete($line)
        EndIf
    Wend
    FileClose($file)
    If $progy = "B:\Scripts\" & @ComputerName & "\RestartServer.au3" Then Shutdown(6)
    If $progy = "B:\Scripts\" & @ComputerName & "\Shutdown.au3" Then Shutdown(5)
    If $progy = "B:\Scripts\" & @ComputerName & "\Hibernate.au3" Then Shutdown(64)

EndFunc   ;==>On_Tray_Run

Func On_Show()
    WinActivate("frmProgress")
    Sleep(500)
    WinActivate("classname=WindowsForms10.window.8.app4","Progress")
    WinActivate("classname=WindowsForms10.window.8.app4","Import Complete")
EndFunc

Func servers()
    If Not FileExists("\\shootsepos1\Openxpos") Then
        RunWait(@ComSpec & ' /c B:\Scripts\mailsend.exe -v ' & $smtp & ' -f it@shoots.co.uk -sub "Broadband Problem" -M "\\shootsepos1\Openxpos cannot be accessed" -t it@shoots.co.uk +cc +bc')
        MsgBox(4096, "", "\\shootsepos1\openxpos Dir Does NOT exists",3600)
    EndIf

    If Not FileExists("\\shootsepos2\openxpos") Then
        RunWait(@ComSpec & ' /c B:\Scripts\mailsend.exe -v ' & $smtp & ' -f it@shoots.co.uk -sub "Broadband Problem" -M "\\shootsepos2\Openxpos cannot be accessed" -t it@shoots.co.uk +cc +bc')
        MsgBox(4096, "", "\\shootsepos2\openxpos Dir Does NOT exists",3600)
    EndIf

    If Not FileExists("\\shootsepos3\openxpos") Then
        RunWait(@ComSpec & ' /c B:\Scripts\mailsend.exe -v ' & $smtp & ' -f it@shoots.co.uk -sub "Broadband Problem" -M "\\shootsepos3\Openxpos cannot be accessed" -t it@shoots.co.uk +cc +bc')
        MsgBox(4096, "", "\\shootsepos3\openxpos Dir Does NOT exists",3600)
    EndIf

    If Not FileExists("\\shoots-svr1\HOME") Then
        RunWait(@ComSpec & ' /c B:\Scripts\mailsend.exe -v ' & $smtp & ' -f it@shoots.co.uk -sub "Broadband Problem" -M "\\shoots-svr1\HOME cannot be accessed" -t it@shoots.co.uk +cc +bc')
        MsgBox(4096, "", "\\shoots-svr1\HOME Dir Does NOT exists",3600)
    EndIf
EndFunc

Func CopyPressed()
    MsgBox(0, "Button Pressed", "About to copy the file you have selected", 3)
    $Value1 = GUICtrlRead($List1)
    $Value2 = GUICtrlRead($List2)
    If FileExists($sScripts & $Value2 & "\" & $Value1) Then MsgBox(0, "ERROR", $sScripts & $Value2 & "\" & $Value1 & " already exists")
    FileCopy($sToUse & $Value1, $sScripts & $Value2 & "\")
    If FileExists($sScripts & $Value2 & "\" & $Value1) Then
        $answer = MsgBox(0, $sToUse & $Value1, $sScripts & $Value2 & "\" & $Value1 & " Exists", 30)
        If $answer = -1 Then On_Tray_Show()
    EndIf
    On_Tray_Show()
EndFunc   ;==>CopyPressed

Func UpDate()
    $aFileList = _FileListToArray($sToUse, "*", 1)
    If @error = 1 Then
        MsgBox(0, "", "No Files\Folders Found.")
        Exit
    EndIf
    For $i = 1 To $aFileList[0]
        $sFileList &= $aFileList[$i] & "|"
    Next
    $file = FileOpen("FolderMonitor.ini", 2)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    For $i = 1 To $aFileList[0]
        $sFileList2 &= $aFileList[$i] & @CRLF
    Next
    FileWrite($file, $sFileList2)
    FileClose($file)
    readDir()
    MsgBox(0, "Done", "FolderMonitor.ini now Up To Date.")
EndFunc   ;==>UpDate

Func On_Tray_Show()

    If TrayItemGetText($hTray_Show_Item6) = "Show" Then
        TrayItemSetText($hTray_Show_Item6, "Hide")
        GUISetState(@SW_SHOW, $Form1)
    Else
        TrayItemSetText($hTray_Show_Item6, "Show")
        GUISetState(@SW_HIDE, $Form1)
    EndIf

EndFunc   ;==>On_Tray_Show

Func On_Tray_Watch()

    FileCopy($sToUse & "DL_Watch.au3", $sScripts & "Vista\")

EndFunc   ;==>On_Tray_Show

Sorry for such a large post.

Share this post


Link to post
Share on other sites

happy2help,

While you are in your Sleep(60000) the script is completely unresponsive - the only chance you have to get a message is the single call to GUIGetMsg that you make once every 60 secs! Hardly surprising that it does not react! :(

Here is the way to keep your loop responsive and still only fire the remainer of the loop every 60 secs: :idea:

While 1
    ; Get current timestamp
    $iBegin = TimerInit()
    Do ; Keep polling GUIGetMsg until 60 secs are up
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                TrayItemSetText($hTray_Show_Item6, "Show")
                GUISetState(@SW_HIDE, $Form1)
            Case $Button1
                CopyPressed()
            Case $Button2
                UpDate()
        EndSwitch
    Until TimerDiff($iBegin) > 60000
    ; Now run your once a minute function
    On_Tray_Run()
    If @MIN = "00" Or @MIN = "15" Or @MIN = "30" Or @MIN = "45" And @ComputerName = "shootsepos1" Then servers()
WEnd

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

That works a treat - so simple when you know how!

Share this post


Link to post
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
Sign in to follow this  
Followers 0