Separating Scanned Data

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 09:57

We have been using AHK for scanning a barcode with one piece of data: (artworkID) then copying that artwork to a folder. Now our barcodes are going to have two pieces of data: ORDERNUMBER"XYZ"ARTWORKID without the quotations. I'm trying to figure out how to separate this scanned data before sending it in the script below. I just need to send the information after XYZ.

Any thoughts?

Code: Select all

Gui,+AlwaysOnTop
Gui, Font, s18 Arial
Gui, Add, Text,, ADULT FILE SCANN
Gui, Font, s10 Arial
Gui, Add, Text,, Scan the barcode
Gui, Add, Edit, h30 w240 vgtx,
Gui, Add, Button, x22 y130 w90 h30 gopengtx default, Adult
Gui, Add, Button, x115 y130 w60 h30 gopengtx2, Toddler
;Gui, Add, Button, x177 y120 w60 h30 gopengtx3, XLarge.
;Gui, Add, Button, x22 y160 w60 h30 gopengtx4, LTank.
Gui, Add, Button, x22 y200 w90 h30 gOpenFiles , Files
Gui, Add, Button, x115 y200 w90 h30 gClear2, Clean
Gui, Show ,x3400 y50 w300 h260


return

opengtx:
Gui,Submit,Nohide
source := "\\Office-server\JPGFILES\" . gtx . ".jpg"

run, %source%
sourcetwo := "\\DSPBServer\ALL-ARTWORK\" . gtx . ".png"
FileCopy, %sourcetwo%, C:\Users\PB\Desktop\HotFolder\Adult\*%A_dd%%A_Sec%.*


SetTimer, Close, -900
SetTimer, Clear2, -1300
Return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 26 Nov 2022, 11:16, edited 1 time in total.
Reason: Please use code tags. Thank you!

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Separating Scanned Data

Post by mikeyww » 26 Nov 2022, 10:06

What are all relevant examples of your input and output strings?

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 10:16

Here is data we are scanning

9214XYZ20ETC-C28
9307XYZ20ETC-C03
9593XYZ20HC-E26
9794XYZ20HC-F39
9091XYZ21TG-C29
2659928909XYZ21TG-C31
2659928909XYZ21TG-C31
2661720635XYZE20ETC-GB

the data we need to push through is

20ETC-C28
20ETC-C03
20HC-E26
20HC-F39
21TG-C29
21TG-C31
21TG-C31
E20ETC-GB

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Separating Scanned Data

Post by JoeWinograd » 26 Nov 2022, 10:23

bivanchan wrote:I just need to send the information after XYZ.
If I'm understanding your question, this will do it:

Code: Select all

DataArray:=StrSplit(BarcodeData,"XYZ")
OrderNumber:=DataArray[1]
ArtworkID:=DataArray[2]
Check out the documentation on StrSplit. Regards, Joe

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Separating Scanned Data

Post by mikeyww » 26 Nov 2022, 10:24

Another one:

Code: Select all

str = 
(
9214XYZ20ETC-C28
9307XYZ20ETC-C03
9593XYZ20HC-E26
9794XYZ20HC-F39
9091XYZ21TG-C29
2659928909XYZ21TG-C31
2659928909XYZ21TG-C31
2661720635XYZE20ETC-GB
)
For each, item in StrSplit(str, "`n")
 MsgBox,, Result, % item "`n`n" trimEx(item)

trimEx(str) {
 Return RegExReplace(str, ".+XYZ")
}
I think I prefer Joe's!

However:

Code: Select all

str = 
(
9XYZ21XYZ4XYZ20ETC-C28
)
For each, item in StrSplit(str, "`n")
 MsgBox,, Result, % item "`n`n" trimEx(item)

trimEx(str) {
 Return RegExReplace(str, ".+XYZ")
}

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Separating Scanned Data

Post by JoeWinograd » 26 Nov 2022, 10:28

Our messages crossed. I posted that code before seeing your examples. Now that I have, the code will work. :) Of course, you want to push through ArtworkID, not OrderNumber (you don't even need the OrderNumber var...that's just for understanding how StrSplit works). Regards, Joe

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 10:31

Thank You Joe, this is clean code, I'm going to give it a try. I've been racking my brain on it for a while. Just not sure where to drop it in on the existing code. I always get confused on that part.

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Separating Scanned Data

Post by mikeyww » 26 Nov 2022, 10:38

I think you could use %ArtworkID% wherever you need it in an AHK command parameter.

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Separating Scanned Data

Post by JoeWinograd » 26 Nov 2022, 11:05

bivanchan wrote:Just not sure where to drop it in on the existing code. I always get confused on that part.
Well, it's simply a variable that contains the ArtworkID. Look in the current code for where ArtworkID is assigned a value from the barcode data...when it was just "one piece of data". Now that the barcode contains two pieces of data, use the StrSplit code to put the DataArray[2] value in the ArtworkID variable. After that, all the code should work fine...same as when it was just "one piece of data". If you're still having trouble, post the script and we'll help you through it. Regards, Joe

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 11:56

Thank you for your time on this. I do really appreciate it.

I guess on this where its confusing me is because it has a Gui window that pops up. Thinking the code should be split before it shows up in the Gui box right or after?

Code: Select all

Gui,+AlwaysOnTop
Gui, Font, s18 Arial
Gui, Add, Text,, ADULT FILE SCANN
Gui, Font, s10 Arial
Gui, Add, Text,, Scan the barcode
Gui, Add, Edit, h30 w240 vgtx,
Gui, Add, Button, x22 y130 w90 h30 gopengtx default, Adult
Gui, Show ,x3400 y50 w300 h260
return

DataArray:=StrSplit(" . gtx . ","XYZ")
OrderNumber:=DataArray[1]
ArtworkID:=DataArray[2]

opengtx:
Gui,Submit,Nohide
source := "\\Office-server\JPGFILES\%ArtworkID%.jpg"


run, %source%
sourcetwo := "\\DSPBServer\homes\ALL-ARTWORK\"".png"
FileCopy, %sourcetwo%, C:\Users\Audley\Desktop\DTF HotFolder\Adult\*%A_dd%%A_Sec%.*


SetTimer, Close, -900
SetTimer, Clear2, -1300
Return



Close:
SetTitleMatchMode, 2
SplitPath, source, fn
WinClose, %fn%
Return

Exit:
GuiClose:
ExitApp 

OpenFiles:
Run \\Office-server\dtgprintfiles\JPGFILES\
return

Clear2:
GuiControl, , gtx
Return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 26 Nov 2022, 15:24, edited 1 time in total.
Reason: Please use code tags. Thank you!

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Separating Scanned Data

Post by mikeyww » 26 Nov 2022, 11:58

Hi,

Unlabeled code following Return is unreachable and never executes. You could move it into auto-exec or a labeled subroutine where you want it to be executed.

Code: Select all

Gui, Font, s10
Gui, Add, Edit  , w230 vbarcode, abcXYZdef
Gui, Add, Button, wp   Default , Go
Gui, Show,, Scans
Return

ButtonGo:
Gui, Submit
MsgBox, 64, Code, % trimmed := trimEx(barcode)
Return

trimEx(str) {
 Return StrSplit(str, "XYZ").2
}

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 12:21

Thank you, thinking about it, it would need to be split before it’s entered into the existing text box as sometimes we need to edit the artwork ID slightly.

Not sure how to implement that code above before the existing controls.

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Separating Scanned Data

Post by mikeyww » 26 Nov 2022, 12:26

It sounds like you want to alter the contents of a control? Below is one example. You can call the Trim routine any number of times to update the barcode based on the bar. I don't know exactly how your script works, so I'm providing some sample code here to demonstrate functionality.

Code: Select all

bar = abcXYZdef
Gui, Font, s10
Gui, Add, Edit  , w230 vbarcode
Gui, Add, Button, wp   Default , Go
Gui, Show,, Scans
Trim:
GuiControl,, barcode, % trimEx(bar)
Return

ButtonGo:
Gui, Submit
MsgBox, 64, Code, %barcode%
Return

trimEx(str) {
 Return StrSplit(str, "XYZ").2
}

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Separating Scanned Data

Post by JoeWinograd » 26 Nov 2022, 12:49

I presume that the Edit control gets populated by the barcode scanner, NOT by the user typing into the field, but it's unclear to me how that happens. It must be by clicking the Adult button, since there are no other controls in the GUI (or hotkeys in the script), but that goes to the label opengtx, and I don't see anything there that looks as if it's doing a barcode scan. Are there other parts to this script?

As a side comment, this syntax is wrong:

Code: Select all

DataArray:=StrSplit(" . gtx . ","XYZ")
By putting quotes around the entire first param, you're making it a literal. The result of that code will be that DataArray[1] is this:

{Space} . gtx . {Space}

(where I've used {Space} to mean a space character) and that DataArray[2] is null. The code you want is this:

Code: Select all

DataArray:=StrSplit(gtx,"XYZ")
That brings me back full circle to: How does gtx get assigned a value by the barcode scanner? Regards, Joe

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 12:56

Thanks joe, This is the full script.

We open up the Gui, The Scanner is basically like a keyboard, once we scan, it auto pops open the image, copies the artwork to a hot folder, waits a second or so then closes, clears the text box and is ready for a new scan.

sometimes we have to add a Letter before or after the artwork file name for different variations of art.

I'm assuming, I would have to add a text box before my existing that would then populate the existing one?

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Separating Scanned Data

Post by JoeWinograd » 26 Nov 2022, 13:48

OK, I think I got it. When the GUI opens (and the Edit control has focus), you hit the barcode scanner and it populates the Edit field with the text from the scan, which, of course, the Edit control puts into the gtx variable (and you can add your letter there after scanning). So, what you want to do is break up the new two-piece data right after the Gui,Submit,Nohide line. In other words:

Code: Select all

Gui,Submit,Nohide
; barcode text is now in gtx var - split it at XYZ to get the ArtworkID and put it back into the gtx var
DataArray:=StrSplit(gtx,"XYZ")
gtx:=DataArray[2]
That's it! You don't need anything else. Now all code after that in the script will have the gtx value and will operate as it did in the days of having only one piece of data from the scan. Regards, Joe

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 15:31

Thank you so much, that actually works out great and just what we needed. Thinking we might have some old barcodes floating around is it possible to put an if statement in there? would it be..

if (DataArray = "XYZ")
{
DataArray:=StrSplit(gtx,"XYZ")
gtx:=DataArray[2]
}

gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: Separating Scanned Data

Post by gregster » 26 Nov 2022, 15:32

@bivanchan, I just sent you a personal message about using code tags. But then I saw in my outbox that you still didn't open my last message from April - which was about the same thing :problem: . That's why I'd like to draw your attention to it in this topic (if you scroll up, you will see that I already added a few tags for you - please do that yourself in future posts):
gregster via PM wrote:Hi bivanchan,
please use [code][/code] tags when posting code. That will add those fancy and useful code boxes.
There is even a button for it in the post editor - the fifth from the left, either saying </> or code. Just select your code, then push the button.

Questions? Please don't hesitate to ask!
Thank you

bivanchan
Posts: 29
Joined: 10 Feb 2022, 10:01

Re: Separating Scanned Data

Post by bivanchan » 26 Nov 2022, 15:40

Sorry, I should have known better. Thank you for the reminder.

Code: Select all

if (DataArray = "XYZ")
{
DataArray:=StrSplit(gtx,"XYZ")
gtx:=DataArray[2]
}

User avatar
mikeyww
Posts: 26875
Joined: 09 Sep 2014, 18:38

Re: Separating Scanned Data

Post by mikeyww » 26 Nov 2022, 15:57

Noted:

Code: Select all

gtx := trimEx(gtx)

trimEx(str) {
 Return RegExReplace(str, ".+XYZ")
}

Post Reply

Return to “Ask for Help (v1)”