Jump to content

Windows 2000 and AutoIT ?


Recommended Posts

Dear Friends,

I have the following code which seems to work on Windows 98 machines. However I have just tried it on a Windows 2000 machine and the CopyToExcel function isn't working. The clipboard isn't seeing any of my information to copy!!! Is it because of the operating system or a problem with my code ??? Does anybody knows how to help??

Thanx

Mark

; AutoIt Version: 3.0

; Language: English

; Platform: Win9x/NT

; Author: Mark Palfreeman (hi0u2323@liv.ac.uk)

; Script: Parallel Loader

; Function: Copy data from Excel to EK-Rechner.

;===

; Application settings

;===

$loadFile = "Microsoft Excel"

$logFilePath = "J:\MERHCNTL\EK Rechner\Mark\Testing\EK Integration Item Load Test Run\Logs"

$autoSaveLogFiles = "Y" ;"Y" or "N"

$acceptableTol = 0.05 ;A size percentage total within this tolerance is acceptable.

$unAcceptableTol = 5.00 ;A size percentage total within this tolerance will be correctd,

;A size percentage total outside this tolerance is an error.

$mSpeed = 0 ;Mouse speed (0 - fastest, 100 - slowest)

$wTime = 1 ;Wait time in seconds for windows that may or may not appear

;===

; Stern co-ordinates

;===

Dim $sternSKCCell[2]

$sternSKCCell[0] = 115 ;x co-ordinate

$sternSKCCell[1] = 59 ;y co-ordinate

Dim $sternDetailedItemEPartsCell[2]

$sternDetailedItemEPartsCell[0] = 736

$sternDetailedItemEPartsCell[1] = 183

Dim $sternFilterWindowItemNoCell[2]

$sternFilterWindowItemNoCell[0] = 455

$sternFilterWindowItemNoCell[1] = 305

Dim $sternFilterButton[2]

$sternFilterButton[0] = 557

$sternFilterButton[1] = 57

Dim $sternDetailedItemEButton[2]

$sternDetailedItemEButton[0] = 75

$sternDetailedItemEButton[1] = 255

Dim $sternStyleCreationButton[2]

$sternStyleCreationButton[0] = 75

$sternStyleCreationButton[1] = 189

$sternSaveButton = "{F8}"

$sternDetailedItemEPODataTab = "{TAB 4}" & "{RIGHT 7}" ;Relative to $sternSKCCell (and "Master Data" being the opening default tab)

$sternDetailedItemECOOCell = "{TAB 3}" ;Relative to $sternDetailedItemEPODataTab

$sternDetailedItemEItemNoCell = "{TAB 3}" ;Relative to $sternSKCCell

$sternFilterWindowStyleNoCell = "{TAB}" ;Relative to $sternFilterWindowItemNoCell

$sternStyleCreationNetEstCell = "{TAB 2}"

$sternStyleCreationSpreadCell = "{TAB}"

$sternWGCell = "{TAB 2}" ;Relative to $sternSKCCell

$sternSizeRangeFirstOptDesc = "{LEFT 2}" ;Relative to $sternSizeRangeFirstWindow

$sternSizeRangeFirstWindow = "{TAB 12}" ;Relative to $sternSKCCell

;===

; Excel cell values

;===

$excelWG = "A2"

$excelStyleNo = "B2"

$excelItemNoRef = "D2"

$excelItemNo = "E2"

$excelParts = "F2"

$excelEstimate = "G2"

$excelSpread = "H2"

$excelCOO = "I2"

$excelOptnDesc = "J2"

$excelSize = "L2"

;===

Main()

Exit

Func Main()

;Prompt user to run script

$answer = MsgBox(1, "EK-Rechner - Parallel Loader", "Please have Loading List active in Excel")

;If "No" was clicked (7) then exit, else run

If $answer == 1 Then

ParallelLoader()

MsgBox(0, "EK-Rechner - Parallel Loader", "Completed. Please see Log Files...")

;Show log files (open Windows Explorer)

Run("explorer.exe " & $logFilePath)

WaitWinActive("classname=CabinetWClass", "")

Send("{F5}") ;Refresh view

Send("!vd") ;View details

EndIf

EndFUNC ;Main

Func ParallelLoader()

;Set window title matching "advanced" mode option (4)

AutoItSetOption("WinTitleMatchMode", 4)

;Default $showToolTips, toggle status with Numlock key

Global $showToolTips = 1 ;1 (on) or 0 (off)

Send("{NUMLOCK on}")

HotKeySet("{NUMLOCK}" ,"ToggleToolTips")

InitialiseLogFiles()

;Declare global variables to store Excel values

Global $cOO, $estimate, $itemNoRef, $itemNo, $parts, $spread, $styleNo, $wG

While 1

$wG = CopyFromExcel($excelWG)

If StringIsSpace($wG) Then

;END OF EXCEL SPREADSHEET SO EXIT

ExitLoop

Else

;Copy details from Excel to global variables

;Capturing all of these now will minimise flicking between applications later

$styleNo = CopyFromExcel($excelStyleNo)

$itemNoRef = CopyFromExcel($excelItemNoRef)

$itemNo = CopyFromExcel($excelItemNo)

$parts = CopyFromExcel($excelParts)

$estimate = CopyFromExcel($excelEstimate)

$spread = CopyFromExcel($excelSpread)

$cOO = CopyFromExcel($excelCOO)

ActivateStern()

;Open Style Creation

LeftClick($sternStyleCreationButton)

;Handle Data Not Saved window

WaitWin("classname=#32770", "")

If WinActive("classname=#32770", "") Then

Send("n") ;Do not save data - problem already logged

EndIf

;Handle window

WaitWin("Attention", "")

If WinActive("Attention", "") Then

Send("{ENTER}") ;Dismiss window

EndIf

Wait()

;Select WG cell, paste and apply

LeftClick($sternWGCell)

Send($wG)

Send("{ENTER}")

Wait()

;Handle window

WaitWin("Error", "")

If WinActive("Error", "") Then

LogProblem("Invalid Warengruppe: " & $wG)

CloseWindow("Error", "")

Else

;Input Style Creation data (then Detailed Item E data)

StyleCreation()

EndIf

;Advance to next row of Excel spreadsheet

DeleteExcelItem()

EndIf

Wend

FinaliseLogFiles()

EndFUNC ;ParallelLoader

Func StyleCreation()

WaitSternActive()

;Click filter button

LeftClick($sternFilterButton)

WaitWinActive("classname=TFormFilter", "")

;Select Item No cell and paste value

;Double click to highlight any cell contents

DoubleLeftClick($sternFilterWindowItemNoCell)

Send($ItemNo)

;Select Style No cell and paste value

LeftClick($sternFilterWindowStyleNoCell)

Wait()

Send($styleNo)

;Apply filter

Send("{ENTER}")

;Wait for Stern - Filter window to de-activate

WaitWinNotActive("classname=TFormFilter", "")

;Handle Item No / Style No error window

WaitWin("classname=TMessageForm", "")

If WinActive("classname=TMessageForm", "") Then

;Dismiss Item No / Style No error window

CloseWindow("classname=TMessageForm", "")

;Ensure Stern - Filter window is active again

WaitWinActive("classname=TFormFilter", "")

LogProblem("")

;Ensure error window is closed (can sometimes be re-opened by Log() function)

CloseWindow("classname=TMessageForm", "")

;Ensure Stern - Filter windows is closed

CloseWindow("classname=TFormFilter", "")

Else

StyleCreation2()

EndIf

EndFUNC ;StyleCreation

Func StyleCreation2()

WaitSternActive()

;Select first Size Range window

ResetPointer()

LeftClick($sternSizeRangeFirstWindow)

;Advance to Size Range window for current Item No within Style

For $i = 1 to ($itemNoRef - 1)

Send("{DOWN}")

Next

;Open Size Range window

Send("{SPACE}")

WaitWinActive("Size Range", "")

;Go to first option

LeftClick($sternSizeRangeFirstOptDesc)

$totalSize = 0

;Loop through all options

While 1

;Copy Option Desc

$optnDesc = Copy()

If StringIsSpace($optnDesc) Then

;END OF SIZE RANGE LIST SO EXIT

ExitLoop

Else

;Paste Option to Excel and retreive Size

PasteToExcel($excelOptnDesc, $optnDesc)

$size = CopyFromExcel($excelSize)

$totalSize = $totalSize + $size

ActivateWindow("Size Range", "")

;Paste size

Send("{RIGHT 2}")

Send($size)

Send("{ENTER}")

Send("{LEFT 2}")

EndIf

WEnd

;If totalSize is > unacceptableTol then log problem

;Else if totalSize is > acceptableTol then amend size

If TolExceeded($totalSize, $acceptableTol) Then

$newSize = $size + 100 - $totalSize

If ($newSize < 0) OR (TolExceeded($totalSize, $unAcceptableTol)) Then

LogProblem("Size Range total: " & $totalSize)

ActivateWindow("Size Range", "")

Else

Send("{UP}")

Send("{RIGHT 2}")

Send($newSize)

Send("{ENTER}")

$totalSize = $totalSize - $size + $newSize

EndIf

EndIf

;Close Size Range window

;Closing window without using OK button bypasses size validation!

CloseWindow("Size Range", "")

If NOT TolExceeded($totalSize, $acceptableTol) Then

StyleCreation3()

EndIf

EndFUNC ;StyleCreation2

Func StyleCreation3()

;Select Net Est. cell and paste

LeftClick($sternStyleCreationNetEstCell)

Send($estimate)

;Select Spread cell and paste

LeftClick($sternStyleCreationSpreadCell)

Send($spread)

;Check for invalid spread

WaitWin("classname=#32770", "")

If WinActive("classname=#32770", "") Then

LogProblem("")

CloseWindow("classname=#32770", "")

Else

;Perform Stern Save

LeftClick($sternSaveButton)

Wait()

;Input Detailed Item E data

DetailedItemE()

EndIf

EndFUNC ;StyleCreation3

Func TolExceeded($value, $tolerance)

Select

Case ($value == 0)

$result = 0

Case ($value < (100 - $tolerance))

$result = 1

Case ($value > (100 + $tolerance))

$result = 1

Case Else

$result = 0

EndSelect

Return $result

EndFUNC ;TolExceeded

Func DetailedItemE()

WaitSternActive()

;Open Detailed ItemE

LeftClick($sternDetailedItemEButton)

WaitWinActive("Stern", "Master Data")

;Select Item No cell and paste value (should already be present!)

LeftClick($sternDetailedItemEItemNoCell)

Send($itemNo)

;Check item can be loaded

WaitWin("C - Detailed ItemE", "")

If WinActive("C - Detailed ItemE", "") Then

LogProblem("")

CloseWindow("C - Detailed ItemE", "")

Else

DetailedItemE2()

EndIf

EndFUNC ;DetailedItemE

Func DetailedItemE2()

WaitSternActive()

;Paste into Parts cell

LeftClick($sternDetailedItemEPartsCell)

Send($parts)

;Select POData tab and paste into Country of Origin cell

ResetPointer()

LeftClick($sternDetailedItemEPODataTab)

LeftClick($sternDetailedItemECOOCell)

Send($cOO)

;Perform Stern save

LeftClick($sternSaveButton)

;Check for missing values / invalid size percentage

WaitWin("classname=#32770", "")

If WinActive("classname=#32770", "") Then

LogProblem("")

CloseWindow("classname=#32770", "")

Else

LogComplete()

EndIf

Wait()

EndFUNC ;DetailedItemE2

Func ActivateExcel()

;Activate and wait for Excel

ActivateWindow($loadFile, "")

EndFUNC ;ActivateExcel

Func ActivateStern()

;Activate and wait for Stern

ActivateWindow("classname=TFormMain", "")

EndFUNC ;ActivateStern

Func ActivateWindow($winTitle, $winText)

;Activate and wait for window

WinActivate($winTitle, $winText)

WaitWinActive($winTitle, $winText)

EndFUNC ; ActivateWindow

Func CloseWindow($winTitle, $winText)

If WinExists($winTitle, $winText) Then

;ActivateWindow($winTitle, $winText)

;Close window

ShowToolTip ("Closing window: " & $winTitle & " " & $winText)

WinKill($winTitle, "")

HideToolTip()

EndIf

EndFUNC ;CloseWin

Func WaitWin($winTitle, $winText)

ShowToolTip("Checking for window: " & $winTitle & " " & $winText)

WinWait($winTitle, $winText, $wTime)

HideToolTip()

EndFUNC ;WaitWin

Func WaitSternActive()

Wait()

;Wait for Stern to become active

WaitWinActive("classname=TFormMain", "")

Wait()

EndFUNC ;WaitSternActive

Func WaitWinActive($winTitle, $winText)

ShowToolTip("Waiting for window: " & $winTitle & " " & $winText)

WinWaitActive($winTitle, $winText)

HideToolTip()

EndFUNC ;WaitWinActive

Func WaitWinNotActive($winTitle, $winText)

;Wait indefinitely for window to de-activate

ShowToolTip("Waiting for window: " & $winTitle & " " & $winText & " to de-activate")

WinWaitNotActive($winTitle, $winText)

HideToolTip()

EndFUNC ;WaitWinNotActive

Func Wait()

;Wait for pointer to return from hour-glass (15)

ShowToolTip("Awaiting system response")

Sleep(100) ;Allow time for hour-glass to appear

Do

Until MouseGetCursor() <> 15

HideToolTip()

EndFUNC ;Wait

Func ShowToolTip($tipText)

;Display tooltip in top left-hand corner of screen

If $showToolTips Then

ToolTip($tipText, 0, 0)

EndIf

EndFUNC ;ShowToolTip

Func HideToolTip()

;Clear any existing tooltip

ShowToolTip("")

EndFUNC ;HideToolTip

Func ToggleToolTips()

HideToolTip()

;Toggle ToolTip status

$showToolTips = NOT $showToolTips

EndFUNC ;ToggleToolTips

Func ResetPointer()

;Reset pointer (move to top left cell)

;Double click required because of drop down

DoubleLeftClick($sternSKCCell)

EndFUNC ;ResetPointer

Func LeftClick($coOrdinates)

If IsArray($coOrdinates) Then

MouseClickLeft($coOrdinates, 1)

Else

Send($coOrdinates)

EndIf

EndFUNC ;LeftClick

Func DoubleLeftClick($coOrdinates)

MouseClickLeft($coOrdinates, 2)

EndFUNC ;DoubleLeftClick

Func MouseClickLeft($coOrdinates, $clicks)

MouseClick("left", $coOrdinates[0], $coOrdinates[1], $clicks, $mSpeed)

EndFUNC ;MouseClickLeft

Func CopyFromExcel($cell)

LocateExcelCell($cell)

;Return cell contents

Return Copy()

EndFUNC; CopyFromExcel

Func Copy()

;Copy to clipboard and return contents (stripped of all white-space)

Send('^c')

Return StringStripWS(ClipGet(), 8)

EndFUNC ; Copy

Func PasteToExcel($cell, $value)

LocateExcelCell($cell)

;Paste value to cell and action

Send($value)

Send("{ENTER}")

EndFUNC; PasteToExcelExcel

Func LocateExcelCell($cell)

ActivateExcel()

Wait()

;Activate Go To window

Send('^g')

WaitWinActive("Go To", "")

;Go to cell

Send($cell)

Send("{ENTER}")

Wait()

EndFUNC; LocateExcelCell

Func InitialiseLogFiles()

;Confirm log file path OR EXIT!

FileSelectFolder("Please confirm log folder", $logFilePath, 7)

If @error == 1 Then

Exit

EndIf

;Get Loading List (from Excel)

ActivateExcel()

$loadFile = WinGetTitle("active")

;Create log files

$loadFileShortName = StringReplace(StringReplace($loadFile, "Microsoft Excel - ", ""), ".xls", "")

$timeStamp = @YEAR & @MON & @MDAY & "." & @Hour & @MIN & @SEC

$completedLogFileName = $logFilePath & "\Completed." & $loadFileShortName & "." & $timeStamp & ".log"

$problemLogFileName = $logFilePath & "\Problem." & $loadFileShortName & "." & $timeStamp & ".log"

$completedLogFileHandle = FileOpen($completedLogFileName, 2)

$problemLogFileHandle = FileOpen($problemLogFileName, 2)

Global $completedLogFile, $problemLogFile

;If a filename is used rather than a file handle, the file will be opened and closed (and

;therefore saved) during the function call.

If $autoSaveLogFiles == "Y" Then

$completedLogFile = $completedLogFileName

$problemLogFile = $problemLogFileName

Else

$completedLogFile = $completedLogFileHandle

$problemLogFile = $problemLogFileHandle

EndIf

$logHeader = GetTimeStamp() & "Started."

$logBody = "'" & $loadFileShortName & "' on " & @ComputerName

WriteLogFile($completedLogFile, $logHeader, $logBody)

WriteLogFile($problemLogFile, $logHeader, $logBody)

EndFUNC ;InitialiseLogFiles

Func FinaliseLogFiles()

$logFooter = @CRLF & GetTimeStamp() & "Finished."

WriteLogFile($completedLogFile, $LogFooter, "")

WriteLogFile($problemLogFile, $LogFooter, "")

If $autoSaveLogFiles <> "Y" Then

FileClose($completedLogFile)

FileClose($problemLogFile)

EndIf

EndFUNC ;FinaliseLogFiles

Func WriteLogFile($logFile, $logHeader, $logBody)

While 1

If $logBody == "" Then

$fileWriteHandle = FileWrite($logFile, $logHeader & @CRLF)

Else

$fileWriteHandle = FileWrite($logFile, $logHeader & @CRLF & $logBody & @CRLF & @CRLF)

EndIf

;Check for write error

If $fileWriteHandle == -1 Then

MsgBox(0, "EK-Rechner - Parallel Loader", "Unable to write Log File: " & $logFile)

WaitWinNotActive("EK-Rechner - Parallel Loader", "")

Else

ExitLoop

EndIf

WEnd

EndFUNC ;WriteLogFile

Func LogProblem($logBody)

If $logBody == "" Then

;Get basic mode window text

$logBody = WinGetText("")

;Get advanced mode window text

If $logBody == "" Then

$logBody = WinGetText("active")

EndIf

;Strip out button text and white space

$logBody = StringReplace($logBody, "Cancel" & @LF, "")

$logBody = StringReplace($logBody, "OK" & @LF, "")

$logBody = StringStripWS($logBody, 7)

;Dismiss window

Send("{ENTER}")

EndIf

;Write to "Problem log"

$logHeader = GetTimeStamp() & $itemNo

WriteLogFile($problemLogFile, $logHeader, $logBody)

EndFUNC ;LogProblem

Func LogComplete()

;Write to "Completed log"

$logHeader = GetTimeStamp() & $itemNo

WriteLogFile($completedLogFile, $logHeader, "")

EndFUNC ;LogComplete

Func GetTimeStamp()

Return(@MDAY & "/" & @MON & "/" & @YEAR & " @ " & @HOUR & ":" & @MIN & ":" & @SEC & " - " )

EndFUNC ;GetTimeStamp

Func DeleteExcelItem()

;Copy Excel Size Lookup function to next row

CopyFromExcel($excelSize)

Send("{DOWN}")

Send('^v') ;Paste

;Locate top row

LocateExcelCell($excelItemNO)

Send("{APPSKEY}") ;Open context window

Send("d") ;Select "delete"

Send("r") ;Select "entire row"

Send("{ENTER}") ;Delete entire row

Wait()

EndFUNC ;DeleteExcelItem

; Finished!

Link to comment
Share on other sites

Its absurd to post a script that large and expect people to reply (With helpful information). Trim it back to a small example that reproduces the problem you encounter in the large script so others can test and express their findings.

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