Stuff it into an associative array - key names must be unique, so that will automatically filter out the duplicates - no need to search through them.
Code: Select all
scanList =
(
J93KNP891;
KH973626NP;
BN21234NOP;
BN21234NOP;
)
; Remove all the ; characters...
StringReplace, scanList, scanList, `;, , ALL
; Split the string into lines
scans := StrSplit(scanList, "`n")
; Now build an array using name as the key.
; Key names are unique, so this will filter out the duplicates
filtered := {}
for i, chars in scans {
filtered[chars] := 1
}
; Now re-build the list
list := ""
for name, unused in filtered {
list .= name "`n"
}
msgbox % list
FYI, when working with scanners and AHK, I found it incredibly useful to configure the scanner to send a "preamble" key *before* it sends the scanned characters.
This is usually done by scanning special barcodes from the manual.
Lets say it sends F12 as a pre-amble.
Declare an AHK hotkey to F12 which activates an "input" command which waits for keys to be sent, and waits for the end char (;)
https://autohotkey.com/docs/commands/Input.htm
This may be complicated as your "End Char" is
;, which is a comment in AHK, but here is roughly what your code would probably look like:
Code: Select all
F12::
; "Start waiting for input, end when you see ;"
Input, chars, ,;
; chars now holds the characters scanned
; Pass the characters on to your processing function
ProcessScan(chars)
return
I have some code that I wrote when working in asset management - it may be useful:
https://autohotkey.com/boards/viewtopic.php?t=4686