Jump to content

Cant Move code to GUI Window


Recommended Posts

I have 5 different scripts that perform different automation functions.

They all work very well.

I thought that putting all of them into a single window with a button for each one would be simple and easy.

I created a function for the first script and it worked.

I created a second button that did not point to anything.

I created a new function called "EMailCL" that has no code. I ran the gui and it ran.

Then I pasted the code from the script (which runs fine) in between "Func EMailCL()" and "EndFunc" and when I attempt to run the GUI I get a syntax error "Func" with a caret under the "F" of Function.

There are no functions in "EMailCL"

What gives???

Link to comment
Share on other sites

Here is the code that works by itself as a standalone script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****

#AutoIt3Wrapper_outfile=C:\HouseMaster\Programs\SendDocs.exe

#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Date.au3>

dim $DT ;datedim $FC ;File Count

Dim $FL[10] ;file list

;Dim $CompName=EnvGet("computername")

#include <File.au3>

#include <Array.au3>

$DT=stringreplace(_nowcalcdate(),"/","-")

;$FC=DirGetSize("C:\Documents and Settings\Mike\My Documents\My Pictures\Toolbox\"&$DT,1)

;==========================================================================================

;new code, get file names and number of files in folder.

$FileList = _FileListToArray(EnvGet("USERPROFILE")&"\My Documents\My Pictures\Toolbox\"&$DT, "*.pdf", 1)

Opt("MouseCoordMode", 0)

;=========================================================================

;Goto Outlook

If Not WinActivate("Microsoft Outlook Web Access") Then

MsgBox(0,'',"Cant find outlook")

Exit

EndIf

For $I = 1 to $FileList[0]

MouseMove(300,210,0)

MouseClick("left")

;New message

WinWait("Untitled -- Message")

;===========================================================

;size the window properly

$WS=WinGetClientSize("Untitled -- Message")

If $WS[0] < 710 or $WS[1] < 420 Then

;MsgBox(0,"",$WS[0] & " "& $WS[1])

WinActivate("Untitled -- Message")

MouseMove($WS[0],$WS[1]+20,0)

MouseDown("Left")

MouseMove(850,510,0)

MouseUp("Left")

EndIf

;================================================================

MouseMove(75,90,0)

Sleep(1000)

Send("pwpi-reports@housemaster.us.com{tab}Cece.Johnston@housemaster.us.com")

Send("{tab}{tab}{end}")

MouseMove(50,210,0)

;For $I = 1 to $FileList[0]

MouseClick("left")

WinWaitActive("Attachments")

While StringInStr(WinGetClassList("Attachments"),"ComboBox")< 1

;WinActivate("Attachments")

WEnd

MouseMove(100,120,10)

;make 10 to slow mouse move so that text box is ready, 0 no work

Sleep(2000)

MouseClick("Left")

Send(EnvGet("USERPROFILE")&"\My Documents\My Pictures\Toolbox\"&$DT&"\"&$FileList[$I])

;ready to attach files

MouseMove(450,166,0)

MouseClick("Left")

MouseMove(450,330,0)

While WinExists("Attachments")

MouseClick("Left")

Sleep(1000)

WEnd

;now put in subject line

$A=StringReplace($FileList[$I]& " / ",".pdf","")

MouseMove(150,225,0)

MouseClick("Left")

Send($A)

MouseMove(30,75,0)

MouseClick("Left")

WinWaitClose("Untitled -- Message")

Sleep(500)

WinActivate("Microsoft Outlook Web Access")

Next

Exit

;====================================================================================================

Here is a GUI window that I created:

#include <GUIConstantsEx.au3>

#include <Date.au3>

GUICreate("HouseMaster Automation 2", 250, 400)

;GUICtrlCreateLabel("Hello world! How are you?", 30, 10)

$StopOlympus = GUICtrlCreateButton("Stop Olympus", 70, 50, 100)

$SendCheckList = GUICtrlCreateButton("Send Checklists", 70, 80, 100)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $StopOlympus

StopOlympus() ;this one works

Case $msg = $SendCheckList

Checklist()

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

;===============Stop Olympus Camera====================================

Func StopOlympus()

Opt("wintitlematchmode",2)

If WinExists("Drag And File Gold") Then

WinWaitClose("Drag And File Gold")

EndIf

RunWait("C:\Program Files\USB Safely Remove\usr.exe stop -n olympus")

;MsgBox(0,"","OK to remove")

Run("C:\Program Files\Drag And File Gold\df32.exe")

EndFunc

;==================E-Mail Checklist/s======================================

Func Checklist()

;If I add the code here, I get "Syntax error "Func"

EndFunc

Thanks

Link to comment
Share on other sites

I reworked the order of the code abit and the gui control buttons react as expected.

Does this help?

;Here is the code that works by itself as a standalone script:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=C:\HouseMaster\Programs\SendDocs.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <File.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>

;Here is a GUI window that I created:

GUICreate("HouseMaster Automation 2", 250, 400)
;GUICtrlCreateLabel("Hello world! How are you?", 30, 10)
$StopOlympus = GUICtrlCreateButton("Stop Olympus", 70, 50, 100)
$SendCheckList = GUICtrlCreateButton("Send Checklists", 70, 80, 100)
$openoutlook = GUICtrlCreateButton("Open Outlook", 70, 110, 100)
$menufile = GUICtrlCreateMenu("&File")
$fileexit = GUICtrlCreateMenuItem("Exit", $menufile)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
    Case $msg = $StopOlympus
        StopOlympus() ;this one works 
    Case $msg = $SendCheckList
        Checklist()
    case $msg = $openoutlook
        openoutlook()
    Case $msg = $GUI_EVENT_CLOSE or $msg = $fileexit
        ExitLoop
    EndSelect
WEnd
;Exit

func openoutlook()
    dim $DT ;datedim $FC ;File Count
    Dim $FL[10] ;file list
    ;Dim $CompName=EnvGet("computername")
    $DT=stringreplace(_nowcalcdate(),"/","-")
    ;$FC=DirGetSize("C:\Documents and Settings\Mike\My Documents\My Pictures\Toolbox\"&$DT,1)

    ;==========================================================================================
    ;new code, get file names and number of files in folder.
    $FileList = _FileListToArray(EnvGet("USERPROFILE")&"\My Documents\My Pictures\Toolbox\"&$DT, "*.pdf", 1)
    Opt("MouseCoordMode", 0)

    ;=========================================================================
    ;Goto Outlook
    If Not WinActivate("Microsoft Outlook Web Access") Then
        MsgBox(0,'',"Cant find outlook")
        Exit
    EndIf

    For $I = 1 to $FileList[0]
        MouseMove(300,210,0)
        MouseClick("left")
        ;New message
        WinWait("Untitled -- Message")
        ;===========================================================
        ;size the window properly
        $WS=WinGetClientSize("Untitled -- Message")
        If $WS[0] < 710 or $WS[1] < 420 Then
        ;MsgBox(0,"",$WS[0] & " "& $WS[1])
        WinActivate("Untitled -- Message")
        MouseMove($WS[0],$WS[1]+20,0)
        MouseDown("Left")
        MouseMove(850,510,0)
        MouseUp("Left")
        EndIf
        ;================================================================
        MouseMove(75,90,0)
        Sleep(1000)
        Send("pwpi-reports@housemaster.us.com{tab}Cece.Johnston@housemaster.us.com")
        Send("{tab}{tab}{end}")

        MouseMove(50,210,0)
        ;For $I = 1 to $FileList[0]
        MouseClick("left")
        WinWaitActive("Attachments")
        While StringInStr(WinGetClassList("Attachments"),"ComboBox")< 1
        ;WinActivate("Attachments")
        WEnd
        MouseMove(100,120,10)
        ;make 10 to slow mouse move so that text box is ready, 0 no work
        Sleep(2000)
        MouseClick("Left")
        Send(EnvGet("USERPROFILE")&"\My Documents\My Pictures\Toolbox\"&$DT&"\"&$FileList[$I])

        ;ready to attach files

        MouseMove(450,166,0)
        MouseClick("Left")

        MouseMove(450,330,0)

        While WinExists("Attachments")
        MouseClick("Left")
        Sleep(1000)
        WEnd

        ;now put in subject line
        $A=StringReplace($FileList[$I]& " / ",".pdf","")
        MouseMove(150,225,0)
        MouseClick("Left")
        Send($A)
        MouseMove(30,75,0)
        MouseClick("Left")

        WinWaitClose("Untitled -- Message")

        Sleep(500)
        WinActivate("Microsoft Outlook Web Access")
    Next
    Exit
    ;====================================================================================================
EndFunc; end openoutlook()

;===============Stop Olympus Camera====================================
Func StopOlympus()
    Opt("wintitlematchmode",2)
    If WinExists("Drag And File Gold") Then
    WinWaitClose("Drag And File Gold")
    EndIf
    RunWait("C:\Program Files\USB Safely Remove\usr.exe stop -n olympus")
    ;MsgBox(0,"","OK to remove")

    Run("C:\Program Files\Drag And File Gold\df32.exe")
EndFunc; end StopOlympus()
;==================E-Mail Checklist/s======================================
Func Checklist()
    for $i=0 to 100
        beep(2000+$i, 10)
    next
    MsgBox(0, "Success", "Checklist button" & @crlf & "was clicked")
    ;exit
EndFunc; end Checklist()
Edited by songersoft
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...