Hi Micha,
I tried to compile my script with the new Unicode build on the device (WinCE).
1. I still can't choose the icon in the AHK2EXE window - I click 'browse' and the window flashes up and then disappears straight away so I can't choose anything. I can choose the source and destination for the Src and Dest, but just not the "Ico" still. I also tried to edit the resources of the resulting exe using PE Explorer, it still doesn't change the icon.
2. After compiling my script, I try to run it and I get an error:
The section of code it appears to be failing on is where the function is called below:
Code:
ButtonFind: ; the g-label handler for the Find button
FindPostcode() ; <-- seems to be failing here
Return
Here is the script I compiled:
Code:
OnExit, ExitSub ; this is the sub to run when the script exits
#SingleInstance, FORCE ; automatically overwrite an existing session
#NoEnv ; dont try to resolve environment variables (better for performance).
; #NoTrayIcon ; don't show a tray icon
PostcodeDataFileName := "PostcodeData.txt" ; the file that contains all the postcode > bag mappings
BagLocDataFileName := "BagLocData.txt" ; the file that contains all the bag number > location mappings
AppName := "Postcode Finder" ; the app name to be displayed on the window
AppVersion := "v1.0" ; the version to be displayed on the window
; Process, Exist, DWTray.exe ; this is to check that the DataWedge (scanner) process is running
; If ( !ErrorLevel )
; Run, \Application\Motorola DataWedge\DWTray.exe
; some variables to change/calculate control positioning more easily
ButtonWidth := 30
ControlHeight := 20
BorderWidth := 10
ButtonXPos := A_ScreenWidth - ButtonWidth - BorderWidth
InputWidth := ButtonXPos - (BorderWidth * 2)
; the main GUI
Gui, Add, Edit, w%InputWidth% h%ControlHeight% vBarcodeInput ; the edit box where the barcode will be scanned
Gui, Add, Button, w%ButtonWidth% h%ControlHeight% x%ButtonXPos% yp gButtonFind Default, Find ; the button that triggers the searching
Gui, Font, s11
Gui, Add, Text, xm w160, Last Scanned Barcode: ; label
Gui, Font, w2000
Gui, Add, Text, xp+170 w150 yp vLastScannedText, ; the dynamic text that will display the last scanned value that was looked up
Gui, Font, s60 cBlue
Gui, Add, Text, xm-20 yp+10 w%A_ScreenWidth% vBagNum Center, ; the large bag number
Gui, Font, s20 cBlue
Gui, Add, Text, xm-20 w%A_ScreenWidth% vBagName Center, ; the name of the location that the bag will go to
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%, %AppName% %AppVersion% ; the title line of the window
GuiControl, Focus, BarcodeInput ; focus the edit box to begin with ready for the first scan
If ( !FileExist(A_ScriptDir . "\" . PostcodeDataFileName) ) ; check the main data file exists, this script is useless without it!
{
MsgBox, File "%PostcodeDataFileName%" not found. Exiting.
ExitApp ; exit (will trigger the ExitSub)
}
FileRead, PostcodeData, %A_ScriptDir%\%PostcodeDataFileName% ; if found, read the file
If ( !FileExist(A_ScriptDir . "\" . BagLocDataFileName) ) ; check if the location data file exists, if not advise user that the loc will not be displayed.
MsgBox, File "%BagLocDataFileName%" not found. Only Bag Numbers will be displayed, not their corresponding locations.
Else
FileRead, BagLocData, %A_ScriptDir%\%BagLocDataFileName% ; if found, read the file
Return ; end of auto-execute section
ButtonFind: ; the g-label handler for the Find button
FindPostcode()
Return
; this is the main function that does the data validation and searching
FindPostcode()
{
global PostcodeData, BagLocData ; global vars to access the data from the data text files
global BarcodeInput, LastScannedText, BagNum ; global vars to access the GUI controls
Gui, Submit, NoHide ; retreive values of all controls
StringReplace, BarcodeInput, BarcodeInput, *, , All ; get rid of Code39 start and stop characters
Loop, Parse, BarcodeInput ; parse the scanned input character-by-character and pull out the alpha and numeric sections of the postcode
{
If ( InStr("abcdefghijklmnopqrstuvwxyz", A_LoopField) ) ; if its alpha
PCAlpha .= A_LoopField ; add it to the alpha string
Else If ( InStr("0123456789", A_LoopField) ) ; if its numeric
PCNum .= A_LoopField ; add it to the numeric scring
Else
{
SynErr := "Scanned Data" ; define the error message that will be shown
Goto, SyntaxError ; skip the rest and go to this label below
}
BarcodeInputClean := PCAlpha . PCNum ; this is the barcode that we will actually be looking up
}
Loop, Parse, PostcodeData, `n, `r ; loop through the postcode data file line-by-line
{
If ( ! A_LoopField ) ; if the line was empty, get the next line
Continue
If ( !PCFound ) ; if we haven't already found a match in the last iteration, check this line
{
If ( !InStr(A_LoopField, "[" . PCAlpha . "]") ) ; check if the line contains the alpha barcode (e.g. [ST] )
Continue ; if not found, go to the top of the loop again
Else
{
PCFound := A_LoopField ; if it was found in this line, save the line and go to the top of the loop again
Continue
}
}
Else ; if the PCFound was saved in the last iteration, it means we have found the right alpa section of the file for the postcode that was scanned
{
If ( InStr(A_LoopField, "[") ) ; this means we have hit the next section, so break
Break
StringSplit, Bags, A_LoopField, :
If ( Bags0 != 2 ) ; if there weren't 2 'halves' of the line, the syntax is wrong
{
SynErr := "PCData Ln " . A_Index ; set the syntax error message to show the file and line number of the problem
Goto, SyntaxError
}
RangeStr := Bags1 ; this will be the range of the postcode numbers that the bag covers (e.g. 1-9 )
Destbag := Bags2 ; this is the corresponding bag number
Loop, Parse, RangeStr, `, ; there may be more than one range that this covers, so check each (e.g. 1-9,11-15 )
{
If ( InStr( A_LoopField, "-" ) ) ; find if it is a range or a single number
{
StringSplit, Range, A_LoopField, `-
If ( Range0 != 2 ) ; check there were only 2 halves to the range, otherwise there is a syntax error
{
SynErr := "PCData Ln " . A_Index
Goto, SyntaxError
}
If Range1 is not integer ; if either of the range numbers are not integers, there was a syntax error
{
SynErr := "PCData Ln " . A_Index
Goto, SyntaxError
}
If Range2 is not integer ; if either of the range numbers are not integers, there was a syntax error
{
SynErr := "PCData Ln " . A_Index
Goto, SyntaxError
}
If ( Range1 > Range2 ) ; swap numbers around if they are the wrong order
{
RangeT := Range1
Range1 := Range2
Range2 := RangeT
}
If PCNum between %Range1% and %Range2% ; find out if the number that we are searching for is in the current range being looked at
{
BagNumFound := Destbag ; save the bag number to be displayed later
Break ; exit the loop as we have found a match
}
Else
Continue ; if it wasn't in the range, check the next one
}
Else ; it wasn't a range, so should be a single number
{
If ( A_LoopField = PCNum or A_LoopField = "*" ) ; if it matches the one we are looking for (or is a * which means 'match all')
{
BagNumFound := Destbag ; save the bag number to be displayed later
Break ; exit the loop as we have found a match
}
Else
Continue ; if it wasn't a match, check the next one
}
}
If ( BagNumFound ) ; if we found the bag number, exit this outer loop
Break
Else ; otherwise, check the next line in the data file
Continue
}
}
If ( BagNumFound ) ; if we managed to find the corresponding bag number in the file
{
Loop, Parse, BagLocData, `n, `r ; check the bag name file to get the name of the city/area that the bag corresponds to
{
StringSplit, BagLoc, A_LoopField, `=
If ( BagLoc0 != 2 ) ; if there weren't 2 'halves' to the line then there was a syntax error
{
SynErr := "BagLoc Ln " . A_Index
Goto, SyntaxError
}
Else ; split the string and try to find a match for the bag number
{
BagLoc1 = %BagLoc1% ; autotrim
BagLoc2 = %BagLoc2% ; autotrim
If ( BagNumFound = BagLoc1 ) ; if we found a match for the number
{
BagNameFound := BagLoc2 ; save the area name for display later
Break ; finish looking as we have found a match
}
Else ; otherwise continue looking
Continue
}
}
If ( ! BagNameFound ) ; if after looking in the bag name file we didn't find a match, show an appropriate string instead
BagNameFound := "Not Found"
}
SyntaxError:
GuiControl, , LastScannedText, ; clear this to ensure it is shown correctly
GuiControl, , LastScannedText, %BarcodeInputClean% ; show the last scanned barcode that we searched for
GuiControl, , BagNum, ; clear the bag number control to ensure it is shown correctly later
If ( SynErr ) ; if there was a syntax error, display "Error" and the error text
{
GuiControl, , BagNum, Error
GuiControl, , BagName, %SynErr%
}
Else If ( BagNumFound ) ; otherwise, if we found a matching bag, display the number and location text
{
GuiControl, , BagNum, Bag %BagNumFound%
GuiControl, , BagName, %BagNameFound%
}
Else ; otherwise, there wasn't a syntax error but we didn't find a match, so show appropriate "unknown" message
{
GuiControl, , BagNum, Bag `?
GuiControl, , BagName, Unknown
}
GuiControl, , BarcodeInput ; clear the edit box of the previously scanned barcode
GuiControl, Focus, BarcodeInput ; focus the edit box ready for the next scan
}
ExitSub: ; this sub will run when the script exits
GuiClose: ; or someone closes the window
GuiEscape: ; or someone presses escape on the window
Esc:: ; or presses escape anywhere
OnExit
ExitApp ; exit the script unconditionally
Return
Is there something I am doing wrong?