Page 1 of 1

Read Data From Bar Code Scanner

Posted: Tue Mar 26, 2013 4:51 pm
by US_Helpdesk
We have a code bar scaner and decicated software which put data from the scanned barcode(part name name and it's number) to txt file:
file layout is:

Code: Select all

part_name    part_no
aaa        001
bbb        002
ccc        003
Can cmm mgr's vb script function can grab these two values and put it automatically to the current program run?
(instead typing it each time running the program)

Re: Read Data From Bar Code Scanner

Posted: Tue Mar 26, 2013 4:55 pm
by US_Helpdesk
Yes this is possible… Here is the VB Script I put in a CMMM project to make this work. After writing the file to an Array you can access the data like this:

MyData = PrtNmb(#) or MyOtherData = PrtNm(#) ------- where # equals the line number of the file.


Here is a message box showing an Array Variable for Part Name and Part Number. This Array data can be used anywhere you can recall a Variable such as Report Header (Customer Data), DDE, etc. This Msg Box is displayed after this VB Script line:
MsgBox("Part Name: " + PrtNm(2)+" Part Number: "+PrtNmb(2))
MsgBox.jpg

Code: Select all

dim PrtNmb(100)
dim PrtNm(100)

Open "c:\barcode.txt" For Input As #1   ' Open file.
i =1
    Do While Not EOF(1)                   ' Loop until end of file.
                Line Input #1, TextLine   ' Read line into variable.
                FndSpc = InStr(TextLine, "   ")  ' Find series of spaces
                PlcHldr = FndSpc - 1
                PrtNm(i) = Left(TextLine, PlcHldr)  ' write text to Array


                StrReverse(TextLine)                  ' repeat for right side of string
                FndSpc = InStr(TextLine, "   ")
                PlcHldr = FndSpc - 1
                PrtNmb(i) = Right(TextLine, PlcHldr)

     i = i +1
    Loop
    Close #1           ' Close file.


'Message Box Output(s)
MsgBox("Part Name: " + PrtNm(2)+"  Part Number: "+PrtNmb(2))
MsgBox("Part Name: " + PrtNm(3)+"  Part Number: "+PrtNmb(3))
MsgBox("Part Name: " + PrtNm(4)+"  Part Number: "+PrtNmb(4))


'Create Variable(s) for use in Report Output
'Use Customer Data Field(s) in Report Properties
RptData = PrtNm(4)
RptData2 = PrtNmb(4)

Re: Read Data From Bar Code Scanner

Posted: Tue Mar 26, 2013 4:58 pm
by US_Helpdesk
Here is the project file...

Re: Read Data From Bar Code Scanner

Posted: Tue May 14, 2019 5:45 pm
by CrashN8
Here is a quick video I've created that shows a new USB based barcode reader working with CMM-Manager.

I used a Zebra DS4308 scanner - Buy here on Amazon