Jump to content

Recommended Posts

Posted

I have the following code and I am not sure about my variables. Particularly $finish and $number. Because I am running the script in a loop I think because I haven't declared them properly they are accumulating each time the script runs, I guess the reason why the script always seems to fall down. Was wondering if anyone could have a quick look and see the problem?? Sorry its a little long, but its mostly because of double spaces between lines!!

Thanks

Mark

;
; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x/NT
; Author:        Jonathan Bennett (jon@hiddensoft.com)
;
; Script Function:
;   Rename Style.
;

;===
; Declare global variables
;===

Global $Paused
Global $ekrusername
Global $ekrpasswrd
Global $excelfile
Global $handle
Global $x = 527
Global $y = 187
Global $finish
Global $number
Global $opsystem
Global $opsysend

;===
;Application Settings
;===

$excelpath = "J:\MERHCNTL\EK Rechner"

;===
;Hotkeys governing Pause and Exit options
;===

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

; In boxes to supply info
$ekrusername = InputBox("EKR Logon", "Enter your EKR Username (This field is case sensitive)", "",)
$ekrpasswrd = InputBox("EKR Logon", "Enter your EKR Password", "", "*")
$excelfile = InputBox("Microsoft Excel", "Please enter the Excel file you are working from", "")

OpenImplementationSchedule()

;LoadEKR()

Func LoadEKR()

; Run EK Rechner
    Run("\\ottouk30\ldrive\PROGRAMM.32\EKSYSTEM\EKSYS32.EXE ekp")

; Wait for the Database Login Screen to become active
    WinWaitActive("Database Login EKP")

; Now that the Database Login Screen is active, then login
    Send("{TAB 3}")
    Send($ekrusername)
    Send("{TAB}")
    Send($ekrpasswrd)
    Send("{Enter}")

    LoadExcelFile()

EndFunc

Func LoadExcelFile()

; Run Microsoft Excel
    Run("C:\Program Files\Microsoft Office\Office\excel.exe")
    
; Wait for the Microsoft Excel to become active
    WinWaitActive("Microsoft Excel - Book1")
    
;Load the Excel File
    Run("explorer.exe " & $excelpath)   
    
; Wait for the filepath to appear
    WinWaitActive("J:\MERHCNTL\EK Rechner")
    
    WinWaitActive("Microsoft Excel - " & $excelfile)
    
    MsgBox(0, "Error", "Clear all error messages")

    WinActivate("Microsoft Excel - " & $excelfile)
    Send("{F5}")    
    Send("A1")
    Send("{ENTER}")
    Send("{DOWN}")
    
    OpenDamito()

EndFunc

Func OpenDamito()

; Open EK RECHNER toolbar
    WinActivate("EK - SYSTEM   @EKP")

; Set co-ordinates used relative to the window rather than the screen
    AutoItSetOption("MouseCoordMode", 0)
    AutoItSetOption("PixelCoordMode", 0)

; Find the appropriate button using pixel colour and then click to launch Damito
    $coord = PixelSearch( 0, 0, 360, 36, 0x060650 )
    If @error Then
        MsgBox(0, "Error", "Damito cannot be found under this login")
        
        Exit
    EndIf
    
    If Not @error Then
    ; Click on the Damito's button
        MouseClick("left", $coord[0], $coord[1], 1, 1)
    EndIf

; Wait until Damito has loaded
    WinWaitActive("Damito - " & $ekrusername & "@EKP")

    OpenImplementationSchedule()

EndFunc

Func OpenImplementationSchedule()

; Activate the Damito window
    WinActivate("Damito - " & $ekrusername & "@EKP")
    
    Sleep(1000)

; Open the Implementation Schedule
    Send("{F10}")
    Send("{DOWN}")
    Send("{RIGHT}")
    Send("{DOWN}")
    Send("{ENTER}")
    
; Wait for the window to load
    While MouseGetCursor() = 15
            sleep(10)
    WEnd

    Sleep(100)

; Enter the SKC
    Send("{TAB}")
    
; These are here for when Tesco is also an SKC option
;Send("{UP}")
;Send("{TAB}")

    Sleep(100)

; Enter the Season
    WinActivate("Microsoft Excel - " & $excelfile)
    Send("^c")

; Activate the Damito window
    WinActivate("Damito - " & $ekrusername & "@EKP")

    WinWaitActive("Damito - " & $ekrusername & "@EKP")

    $bak = ClipGet()
    $array = StringSplit($bak, "")
    
; Enter the Season
    Send($array[1])
    Send($array[2])
    Send($array[3])

;Wait for the data to load
    While MouseGetCursor() = 15
        sleep(10)
    WEnd
    
    Sleep(100)
    
; Enter the Publication 
    WinActivate("Microsoft Excel - " & $excelfile)
    Send("{RIGHT 4}")
    Send("^c")
    
; Activate the Damito window
    WinActivate("Damito - " & $ekrusername & "@EKP")

    WinWaitActive("Damito - " & $ekrusername & "@EKP")

    $bak = ClipGet()
    $array1 = StringSplit($bak, "")
    
; Enter the Publication
    Send("{TAB}")
    Send($array1[1])
    Send($array1[2])
    Send($array1[3])

    While MouseGetCursor() = 15
        sleep(10)
    WEnd
    
    Sleep(100)
    
; Enter the version
    Send("{TAB}")
    Send("9")
    
; Enter the Buyer & Merch group
    Send("{TAB}")
    
    WinActivate("Microsoft Excel - " & $excelfile)
    Send("{LEFT 2}")
    Send("^c")
    
    $bak2 = ClipGet()
    
    Send("{RIGHT}")
    Send("^c")
    
    $bak3 = ClipGet()
    
    $array2 = StringSplit($bak2, "")
    $array3 = StringSplit($bak3, "")
    
; Activate the Damito window
    WinActivate("Damito - " & $ekrusername & "@EKP")

    WinWaitActive("Damito - " & $ekrusername & "@EKP")
    Send($array2[1])
    Send($array2[2])
    Send($array3[1])
    Send($array3[2])
    
    While MouseGetCursor() = 15
        sleep(10)
    WEnd
    
    Send("{ENTER")
    
; Wait for the items to load
    While MouseGetCursor() = 15
        sleep(10)
    WEnd    

    Send("{ENTER}")

    Sleep(1000)

; Activate the Damito window
;   WinActivate("Damito - " & $ekrusername & "@EKP", "Implementation Schedule")
    
;   WinWaitActive("Damito - " & $ekrusername & "@EKP", "Implementation Schedule")

;   $pgquest = InputBox("Microsoft Excel", "Do you want to leave this item?", "")   
    
;   If $pgquest = "yes" Then
    
;   Reset()
    
;   EndIf
    
    EnterData()

EndFunc
    
Func EnterData()
    
    WinActivate("Microsoft Excel - " & $excelfile)
    Send("{RIGHT 4}")
    Send("^c")
    
    $clip1 = ClipGet()
    
    $opsystem = StringStripWS($clip1, 8)
    
    Send("{RIGHT}")
    Send("^c")
    
    $clip2 = ClipGet()
    
    $opsysend = StringStripWS($clip2, 8)
    
    Sleep(100)

; Activate the Damito window
    WinActivate("Damito - " & $ekrusername & "@EKP")
    
    WinWaitActive("Damito - " & $ekrusername & "@EKP")
    
    $number = -1 
    
    WinActivate("Damito - " & $ekrusername & "@EKP", "Implementation Schedule")
    
    WinWaitActive("Damito - " & $ekrusername & "@EKP", "Implementation Schedule")
    
    Sleep(2000)
    
    Do
        $number = $number + 1
        
        $var = PixelGetColor($x , $y)
    
        $y = $y + 22
                
    Until $var = 16777215
    
    Send("{TAB 4}")
    
    WinActivate("Damito - " & $ekrusername & "@EKP", "Implementation Schedule")
    
    WinWaitActive("Damito - " & $ekrusername & "@EKP", "Implementation Schedule")   
        
        $finish = 0
        
            Send("{TAB}")
            Send("{SHIFTDOWN}") 
            Send("{RIGHT 12}")
            Send("{SHIFTUP}")
            Send("^c")

            $finish = $finish + 1

            $check = ClipGet()
        
            If $check = "00.00.0000" Then   
                GoAhead()
            EndIf

            If $finish = $number Then
                Send("{TAB 11}")
                Send("{SPACE}")
            
            Reset()
            
            EndIf

            Do
            
            $finish = $finish + 1
            
                Send("{SHIFTDOWN}") 
                Send("{RIGHT 12}")
                Send("{SHIFTUP}")
                Send("^c")
            
            $check2 = ClipGet()
    
            If $check2 = "00.00.0000" Then  
                Notation()
            EndIf
            
                Send("{TAB 12}")
            Until $finish = $number 
                
                Send("{TAB 11}")
                Send("{SPACE}")
                
                Reset()
    
EndFunc             
        
Func GoAhead()      
    
        $finish = 0
        
        Do
            Send($opsystem)
            Send("{TAB}")
            Send($opsysend)
            Send("{TAB}")
            Send($opsystem)
            Send("{TAB}")
            Send($opsystem)
            Send("{TAB 9}")

            $finish = $finish + 1
        
        Until $finish = $number
                        
        Save()
                
EndFunc
        
Func Notation()

        Send("{DOWN 20}")
        Send("{TAB 11}")
        Send("{SPACE}")
    
        WinActivate("Microsoft Excel - " & $excelfile)
        WinWaitActive("Microsoft Excel - " & $excelfile)
        Send("{RIGHT}")
        Send("Half Done")
        
        Reset()
EndFunc

Func Save()

    ; Save the data
        Send("{TAB 20}")
        Send("{SPACE}")

        WinWaitActive("Save!")
        Send("{ENTER}")
        Send("{TAB}")
        Send("{SPACE}")

        Reset()
EndFunc

Func Reset()
    
    WinActivate("Microsoft Excel - " & $excelfile)
    WinWaitActive("Microsoft Excel - " & $excelfile)
    Send("{LEFT 20}")
    Send("{DOWN}")
    
    Sleep(1000)
    
    OpenImplementationSchedule()
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

; Finished!
Posted

I read through your script and it appears that your script ends up in a big loop:

Start > OpenImplementationSchedule() > EnterData() > GoAhead() > Save() > Reset()

(But Reset() calls OpenImplementationSchedule()! Uh-oh!)

Posted

Hey,

Thanks for taking a look.

That loop is what I want it to do. I need it to loop round and the best way I saw to do it was to call the functions. Could this be affecting my variables??

Thanks

mark

Posted

Could you please let us know what kind of error you're getting? That'll greatly help to determine the specific problem.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...