I seems like the reload in below snippet doesn't reset the script completely causing an error message if I run it a second time.
I was alway under the impression Reload would start from scratch just like you run the script for the first time.
Is that not the case ?
The funny thing is, if I do
Code: Select all
^r::reload
Part of my script has this code:
Code: Select all
if (Line = arr.Length)
{
A_Clipboard := ""
Line := 1
MsgBox("Before reload") ; >>>>> THIS MSGBOX SHOWS UP ON MY SCREEN
Reload
Sleep(2000)
MsgBox("After reload") ; >>>>> THIS ONE DOESN'T (AND SHOULDN'T) SHOW UP ON MY SCREEN
}
Error: Invalid index.
Specifically: 2
030: Reload()
031: }
▶ 032: Artikelnummer := arr[Line][9]
033: Omschrijving := arr[Line][10]
034: Aantal := RTrim(arr[Line][11], ",00")
Full script
Code: Select all
#Requires AutoHotkey v2.0
SetKeyDelay(100)
Line := 1
Omschrijving := ""
Aantal := ""
Land_van_oorsprong := ""
Statistiekcode := ""
Gewicht := ""
Valuta := ""
var := RTrim(A_Clipboard," `n`r") ; Trim last empty line
Array.Prototype.DefineProp('Default', {Value: ""}) ; could be Value: "n/a" or "n.v.t" in Dutch
arr := []
for x,y in strsplit(var,"`n","`r")
{
z := strsplit(y,a_tab)
z.Length := 18 ; "sets" the array length of each line to 18
arr.push(z)
}
^2::
{
global Line+=1
if !InStr(A_Clipboard, "Interne ID document") ; Clipboard must contain the text "Interne ID document, otherwise reload the script"
{
MsgBox("Geen DHL Data gevonden !")
Line := 1
Reload
}
Artikelnummer := arr[Line][9]
Omschrijving := arr[Line][10]
Aantal := RTrim(arr[Line][11], ",00")
Land_van_oorsprong := arr[Line][18]
Statistiekcode := StrReplace(StrReplace(arr[Line][17], "."), A_Space) ; remove spaces and dots
Gewicht := StrReplace(arr[Line][15], ",",".") ; replace commas with dots
Valuta := arr[Line][14]
ToolTip("Valuta = " . Valuta . " Aantal regels " . arr.Length)
if (Valuta = "EUR")
Bedrag := StrReplace(arr[Line][12], ",",".") ; replace commas with dots
else
Bedrag := StrReplace(arr[Line][13], ",",".") ; replace commas with dots
if (Artikelnummer != "P")
{
Send(Omschrijving . "`t" . Aantal . "`t")
KeyWait "LButton", "D"
Send(Land_van_oorsprong . "`r`t`t" . Statistiekcode . "`t")
Send(Gewicht . "`t" . Bedrag) . "`r`t`t"
}
else
{
ToolTip("Klik op het porto veld.")
KeyWait "LButton", "D"
Send(Bedrag . "`r")
}
if (arr[2][14] != "EUR") AND (arr.Length = Line)
{
VV := (arr[2][14])
ToolTip("Klik op het valuta veld. " . arr[2][14])
Sleep(100)
KeyWait "Lbutton", "D"
Sleep(1000)
Send(VV . "`r")
ToolTip
}
if (Line = arr.Length)
{
A_Clipboard := ""
Line := 1
MsgBox("Before reload") ; <<<<<<<<<<<THIS FIRES
Reload
Sleep(2000)
MsgBox("After reload") ; <<<<<<<<<<<THIS DOESN'T
}
}
^r::Reload
^e::ExitApp