How can I properly read data from bar code scanner?

bar code or just go to a bar?

  • How could I write a macro to format my data like I need it? I have a text file of data (windows) that I have created with a portable bar code scanner, but the data is not in the format that I need it to be... What I have are boxes with folders in them. Each folder in the box is bar coded and each box has a bar code. My box bar code always begins with Z and the folder bar codes are random numeric and may have a space in the code. My current data looks like this.... Z00000000000123 675497765 580263739 878654737 67937 0883 6393 87833 Z00000000000124 8293618373 6364 99127 849437882 939384489 Z00000000000125 64636 0483 993746283 738399402 839304004 But what i need as an end result (after the macro) is two columns of related data such as.... Z00000000000123 , 675497765 Z00000000000123 , 580263739 Z00000000000123 , 878654737 Z00000000000123 , 67937 0883 Z00000000000123 , 6393 87833 Z00000000000124 , 8293618373 Z00000000000124 , 6364 99127 Any help from the hive is greatly appreciated.....

  • Answer:

    This is a quick and dirty vbscript which should do the job in most windows flavours. Copy it to a text file and save it as something.vbs. Double click to run - it will output another text file called final.txt to the same directory. You will need to change the name of the readfile from data.txt(take a copy first, of course). It assumes that this file, and the starting text file are in the same directory/folder. Hope this formatting works! ----------------------------dim filesys, text, readfile, contents, textFinal, currentZset filesys=CreateObject("Scripting.FileSystemObject")set readfile = filesys.OpenTextFile("data.txt", 1, false)Set textFinal=filesys.CreateTextFile("final.txt", True)Do While readfile.AtEndOfStream True contents=readfile.readline if inStr(contents, "Z") 0 Then currentZ = contents End If if currentZ contents Then textFinal.Write(currentZ & "," & contents & VbCr & VbLf) End ifloopreadfile.closetextFinal.close>>>

keep it tight at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

If I had to do this, I would use a spreadsheet. Put your data in column A. Copy A1 (Z00000000000123) to B1. In B2, put this formula: =if(left(A2,1)="Z",A2,B1). Copy that down column B. Now copy/paste column B in place, with Edit > Paste Special > Values. Copy column A over to column C. Now you have what you want in B and C, except that you have entries like Z00000000000124, Z00000000000124. Various ways to get rid of these. One would be to create column D as =exact(C1,D1). Then sort by column D and delete the rows with value 1. Good luck.

Perplexity

Did somebody say golf! perl -lne '/^Z.*/||print"$& , $_"' data.txt Z00000000000123 , 675497765 Z00000000000123 , 580263739 Z00000000000123 , 878654737 Z00000000000123 , 67937 0883 Z00000000000123 , 6393 87833 Z00000000000124 , 8293618373 Z00000000000124 , 6364 99127 Z00000000000124 , 849437882 Z00000000000124 , 939384489 Z00000000000125 , 64636 0483 Z00000000000125 , 993746283 Z00000000000125 , 738399402 Z00000000000125 , 839304004

zengargoyle

You could use regular expressions (patterned search, grep) to do the conversion. Your source data has a repeating pattern that would work suit a regular expression quite well. A text editor such as http://textpad.com/ could serve as your conversion tool, and you'd need to learn up on how to http://www.google.com/search?hl=en&q=regular+expressions&btnG=Google+Search&aq=2&oq=regular. It's basically a find and replace on steroids.

fauxtoes

http://cowbellemoo.is-a-geek.com/format.py the same in python (just install the interpreter http://www.python.org/download/)

cowbellemoo

Heh, cowbellemoo. I was gonna show off in a line or two of perl, but I figured "how many people are likely to have it installed." :-) I really must get around to finally learning some Python, though.

Sparx

Heh, I'm just waiting for someone to PHP the thing into a web form and be really helpful.

cowbellemoo

perl -ne 'if (/^Z/) { chomp; $prefix = $_; } else { print "$prefix , $_" }' yourData

harmfulray

Yay, Perl golf! -l for autochomp: perl -lne 'if (/^Z/) { $prefix = $_ } else { print "$prefix , $_\n" }' yourData

nicwolff

This is a classic Awk-type problem, but you're even less likely to have that available on a Windows box than perl, and harmfulray's perl oneliner is pretty similar to what an awk script would look like anyway...

hattifattener

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.