Jump to content

Lost in a While Loop


locutus243
 Share

Recommended Posts

Hi Guys,

I have the script below. I want to run it once every 5 minutes for 10 hours. However when I try and put a While 1 WEnd loop in then it either tells that there is no WEnd for my While loop or it says that my Function EKR Login hasn't got an EndFUNC (which it clearly has)

I would appreciate it if anybody could give me any advice.

;

; AutoIt Version: 3.0

; Language: English

; Platform: Win9x/NT

;

; Script Function:

; Runs EK Rechner Login.

;

; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)

$answer = MsgBox(4, "AutoIt Example (English Only)", "This script will run EK Rechner. Run?")

; Check the user's answer to the prompt (see the help file for MsgBox return values)

; If "No" was clicked (7) then exit the script

If $answer = 7 Then

MsgBox(0, "AutoIt", "OK. Bye!")

Exit

EndIf

$i = 0

While $i <= 10000

EKRLogin()

Func EKRLogin()

;Start timer

$begin = TimerStart()

; Run EK Rechner

Run("\\ottouk30\ldrive\PROGRAMM.32\EKSYSTEM\EKSYS32.EXE eki")

; Wait for the Database Login Screen to become active

WinWaitActive("Database Login EKI")

; Now that the Database Login Screen is active, then login

Send("{TAB 3}")

Send("MARKP{TAB}")

Send("OTTOUK{Enter}")

WinWaitActive("EK - SYSTEM @EKI")

$EKRLogin = TimerStop($begin)

$file = FileOpen("EKR Login.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $EKRLogin & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;EKR Login

OpenStern()

Func OpenSTERN()

;Start Timer

$begin = TimerStart()

;Open EK RECHNER toolbar

WinActivate("EK - SYSTEM @EKI")

;Set mouse co-ordinates in window mode option (0)

AutoItSetOption("MouseCoordMode", 0)

MouseClick("left", 164, 33, 1, 10)

WinWaitActive("Stern", "ToolBarStandard")

;Stop Timer

$OpenSTERN = TimerStop($begin)

$file = FileOpen("OpenSTERN.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $OpenSTERN & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;OpenSTERN

InputSelectionCriteria()

Func InputSelectionCriteria()

;Start Timer

$begin = TimerStart()

;Select the working group

Send("{TAB 2}")

;Enter a new working group

Send("{BS}")

Send("99.01.001.01")

Send("{ENTER}")

;Wait for the item list to appear

WinWaitActive("Stern", "Item List:")

$InputSelectionCriteria = TimerStop($begin)

$file = FileOpen("Input Selection Criteria.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $InputSelectionCriteria & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;InputSelectionCriteria

OpenBackgroundDataModule()

Func OpenBackgroundDataModule()

;Start Timer

$begin = TimerStart()

; Run Background Data Module

MouseClick("left", 74, 124, 1, 10)

;Wait for the module to appear

WinWaitActive("Stern", "WG Data")

$OpenBackgroundDataModule = TimerStop($begin)

$file = FileOpen("Open Background Data Module.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $OpenBackgroundDataModule & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;OpenBackgroundDataModule

OpenStyleCreationModule()

FUNC OpenStyleCreationModule()

;Start Timer

$begin = TimerStart()

; Style Creation Module

MouseClick("left", 75, 189, 1, 10)

WinWaitActive("Stern", "ToolBarFarbe")

$OpenStyleCreationModule = TimerStop($begin)

$file = FileOpen("Open Style Creation Module.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $OpenStyleCreationModule & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;OpenStyleCreationModule

CreateNewStyle()

Func CreateNewStyle()

;Start Timer

$begin = TimerStart()

;Create New Style

MouseClick("left", 288, 89, 1, 10)

;Give the stle a description

Send("{TAB}")

Send("Marks Leather Trousers")

Send("{TAB}")

;Choose a supplier from the list provided

Send("W998")

Send("{TAB}")

;Choose the appropriate MAK code

Send("32")

Send("{TAB 4}")

;Select the colour of that item

Send("Black")

Send("{TAB 3}")

Send("{SPACE}")

;Set mouse co-ordinates in window mode (0)

AutoItSetOption("MouseCoordMode", 0)

;List the size range for that item

Send("{SPACE}")

Send("{TAB}")

Send("{SPACE}")

WinWaitActive("Option")

;Select an option

Send("{TAB}")

Send("12")

Send("{ENTER}")

Send("{TAB 2}")

;Create a new option

MouseClick("left", 20,112,1,10)

;Select another option

Send("{TAB}")

Send("{SPACE}")

Send("{TAB}")

Send("14")

Send("{ENTER}")

;Create a new option

MouseClick("left", 20,112,1,10)

;Select another option

Send("{TAB}")

Send("{SPACE}")

Send("{TAB}")

Send("16")

Send("{ENTER}")

;Create a new option

MouseClick("left", 20,112,1,10)

;Select another option

Send("{TAB}")

Send("{SPACE}")

Send("{TAB}")

Send("18")

Send("{ENTER}")

;Create a new option

MouseClick("left", 20,112,1,10)

;Select another option

Send("{TAB}")

Send("{SPACE}")

Send("{TAB}")

Send("20")

Send("{ENTER}")

;Enter the option size%

Send("20")

Send("{ENTER}")

Send("20")

Send("{ENTER}")

Send("20")

Send("{ENTER}")

Send("20")

Send("{ENTER}")

Send("20")

Send("{ENTER}")

Send("!{F4}")

;Enter estimation and spread

Send("{TAB 2}")

Send("100 {TAB}")

Send("100001")

;Save new item

Send("{F8}")

WinWaitActive("Stern", "TR")

;Copy, and create second item

Send("{LEFT 9}")

Send("{SPACE}")

MouseClick("left", 187, 243, 1, 10)

Send("{TAB 14}")

Send("Blue")

Send("{F8}")

$CreateNewStyle = TimerStop($begin)

;Delete changes that have been made

Send("{TAB 19}")

Send("{SPACE}")

Send("{TAB 11}")

Send("{SPACE}")

MouseClick("left", 211, 240, 1, 10)

Send("{ENTER}")

Sleep(3000)

MouseClick("left", 462, 58, 1, 10)

Send("{ENTER}")

$file = FileOpen("Create New Style.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $CreateNewStyle & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;CreateNewStyle

OpenDetailedItemEModule()

FUNC OpenDetailedItemEModule()

;Start Timer

$begin = TimerStart()

;Run Detailed ItemE Module

MouseClick("left", 76, 254, 1, 10)

WinWaitActive("Stern", "Master Data")

$OpenDetailedItemEModule = TimerStop($begin)

$file = FileOpen("Open Detailed ItemE module.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $OpenDetailedItemEModule & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;OpenDetailedItemEModule

CompleteMandatoryFieldsinDetailedItemE()

Func CompleteMandatoryFieldsinDetailedItemE()

;Start Timer

$begin = TimerStart()

;Find the item we're working on!

Send("{TAB 3}")

Send("TR1036")

Send("{ENTER}")

;Master Data

Send("{TAB 21}")

Send("119")

Send("{TAB 3}")

Send("Q37")

MouseClick("left", 737, 180, 1,10)

Send("1")

Send("{TAB 2}")

Send("1")

Send("{TAB 5}")

Send("0")

;Supplier

MouseClick("left", 250, 161, 1, 10)

Send("Mks Lthr Trs")

Send("{DOWN 2}")

Send("Marks Leather Trousers")

Send("{TAB 14}")

Send("2")

;Options

MouseClick("left", 299, 158, 1, 10)

Send("{TAB 3}")

Send("40")

Send("{ENTER}")

Send("40")

Send("{ENTER}")

Send("20")

Send("{ENTER}")

;Mpub

MouseClick("left", 344, 158, 1, 10)

Send("{TAB 6}")

Send("100001")

Send("{DOWN}")

Send("100001")

;Prices

MouseClick("left", 387, 162, 1, 10)

MouseClick("left", 474, 223, 1, 10)

Opt("MouseClickDelay", 3000)

Send("{F8}")

Opt("MouseClickDelay", 1000)

;Logistics

MouseClick("left", 485, 157, 1, 10)

Send("{TAB 5}")

Send("8")

;PO Data

MouseClick("left", 548, 162, 1, 10)

Send("{TAB 2}")

Send("CN")

Send("{DOWN}")

Send("99")

Send("{DOWN}")

Send("314")

Send("{DOWN 9}")

Send("{RIGHT 2}")

Send("{SPACE}")

WinWaitActive("Stern - Choosing Incoterms", "Cancel")

Send("FR")

Send("{TAB}")

Send("{ENTER}")

WinWaitNotActive("Stern - Choosing Incoterms", "Cancel")

;Save

Send("{F8}")

$CompleteMandatoryFieldsinDetailedItemE = TimerStop($begin)

$file = FileOpen("CompleteMandatoryFieldsinDetailedItemE.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $CompleteMandatoryFieldsinDetailedItemE & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;CompleteMandatoryFieldsinDetailedItemE

CreateNewItemInQuickLoad()

Func CreateNewItemInQuickLoad()

;Start Timer

$begin = TimerStart()

;Find the item we're working on!

Send("{TAB 3}")

Send("TR1123")

Send("{ENTER}")

;Select the Quickload button

MouseClick("left", 305, 84, 1, 10)

;Fill in the mandatory fields

MouseClick("left", 126, 86, 1, 10)

;Description

Send("Marks Shorts")

Send("{ENTER 3}")

;Style Description

Send("Marks Shorts")

Send("{ENTER 2}")

;Colour

Send("Purple")

Send("{ENTER 2}")

;MAK Code

Send("999")

Send("{ENTER}")

;Ret%

Send("{DOWN 5}")

Send("15")

;Move To Next Column

Send("{ENTER}")

Send("{RIGHT 4}")

;QA Technician

Send("Q37")

;SC Code

Send("{UP}")

Send("119")

;156 Weeks Terms

Send("{UP 2}")

Send("0")

;Unit of Sales QTY

Send("{UP 3}")

Send("1")

;Net Estimate

Send("{UP 4}")

Send("100")

;Spread

Send("{UP 3}")

Send("100001")

;Move To Next Column

Send("{UP}")

Send("{RIGHT 4}")

;Buyers Description

Send("Mks Shts")

;Delivery Address

Send("{ENTER 3}")

Send("2")

;Currency

Send("{ENTER 5}")

Send("GBP")

;Labels

Send("{ENTER 2}")

Send("1")

;Method Of Dispatch

Send("{ENTER 3}")

Send("8")

;Move To Next Column

Send("{RIGHT 4}")

Send("{UP 5}")

;Country Of Origin

Send("BE")

;Transport Packaging

Send("{ENTER}")

Send("99")

;Terms Of Payment

Send("{ENTER}")

Send("987")

;Incoterms

Send("{ENTER}")

Send("{RIGHT}")

Send("{SPACE}")

Send("HK")

Send("{TAB}")

Send("{ENTER}")

;Save

Send("{F8}")

;Close Quick Load Screen

Send("!{F4}")

$CreateNewItemInQuickLoad = TimerStop($begin)

$file = FileOpen("Create New Item In Quick Load.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $CreateNewItemInQuickLoad & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFUNC ;CreateNewItemInQuickLoad

OpenMpubCopyingModule()

Func OpenMpubCopyingModule()

;Start Timer

$begin = TimerStart()

; Run MPub Copying Module

MouseClick("left", 75, 317, 1, 10)

WinWaitActive("Stern", "Select None")

$OpenMpubCopyingModule = TimerStop($begin)

$file = FileOpen("Open Mpub Copying Module.txt", 1)

; Check if file opened for writing OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

FileWrite($file, "Date " & @MDAY & ":" & @MON & ":" & @YEAR & @CRLF)

FileWrite($file, "Time (msecs) ")

FileWrite($file, $OpenMpubCopyingModule & @CRLF)

FileWrite($file, "Time Recorded " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF)

EndFunc ;OpenMpubCopyingModule

CopyItemIntoAnotherPublication()

Func Wait()

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

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

Do

Until MouseGetCursor() <> 15

EndFUNC ;Wait

CloseAll()

Func CloseAll()

;CloseSTERN

Send("!{F4}")

Send("{ENTER}")

;Close EK Rechner Toolbar

Send("!{F4)")

Send("{ENTER}")

EndFUNC ;CloseAll

Sleep(50000)

WEnd

; Finished!

Link to comment
Share on other sites

Func must be OUTSIDE any loop. You'll call them as needed with their name!

E.g.

;Show 1000 random numbers...
For $c = 1 to 1000
   tooltip(_Randomnumber())
   sleep(100)
Next

Exit
Func _RandomNumber()
   Return Random(0,1000)
EndFunc

Also try Tidy to indent your code and see better yours loops. It will also help you finding the problem. Good hunt.

Link to comment
Share on other sites

  • Developers

ok... you cannot just surround th WHOLE thing with while/wend. Funcs have to be seperated. I started cleaning the indentation, but the script is too long. study the change.

<{POST_SNAPBACK}>

You mean you are doing this manually ? :ph34r: you should try Tidy :(

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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