Forum > General

Looking for advice - Parse a string from a TEdit


Hi Folks,

i'm preparing a migration/port of an Excel-VBA-Script to FPC/Lazarus.

Current Situation:
We have bins/containers in our CleanRoom.
Each bin has 2 Barcodes: PartNumber and StockLocation --> A bin will never change content and location

The current Excel-Script offers two textFields: one for PartNumber, one for Location, meaning the ladies have to scan each bin twice
Issue: If the Ladies are not careful, they scan the Location into the PartNumber-Field and vice versa

Example Part-No.: 123456 (always 6 Characters)
Example Location: RR5012 (always 6 Characters)

With the Migration i'll propose a change of the Barcode-Labels on the Bins: One Barcode containing "123456RR5012"
(To save the ladies the second scan, and avoiding the "scanned into the wrong TEdit")

Question: Any ideas/advice on efficient parsing?
The proposed change of labels will probably be a "running" change, meaning: The labels will not get changed in one go,
since the Cleanroom has extremely restricted Access.
Meaning: i'll have to provide for both versions of the Barcode(s)

I was thinking:
1) Check for Length of Text
2) If Length=12 Then NewLabel --> Split it up, the left 6 Chars being PartNo, the right 6 Chars being Location
3) If Length=6 Then OldLabels --> Check if text starts with "RR". If Yes Location Else PartNo. (Optional: If PartNo Then tryToConvertToInteger If Yes Everything OK Else Error)
3b) The Ladies would still have to scan a second time. I was thinking keeping a Flag "FirstScan was PartNo. Second Scan must be Location" or some such

All "correctly" scanned Barcodes will be collected into a StringGrid, separated by PartNo., Location (and some more Data from a Database, but having nothing to do with the Barcodes)

Is my logic sound?
Note: I'm asking for the Logic.
Code is not a problem once i know which road leads to Rome.....

logic sound good..

read barcode if 12 then split loc and num
if 6? starts with rr? then loc else num
if either loc or bin is empty message need the missing one
loop until both loc and num are set or user aborted

non compile code

--- Code: ---binloc ='';
  binnumb ='';
  userabort = false;
  finished = false;
  barcode_aborted = false;  set to true to abort the scan; either in readbarcode function or via gui
  while not finished  do
    bc:=readbarcode;  // allow for abort of barcode
    if barcode_aborted then finished=true
      if length(bc)=12 then
      if length(bc)=6 then
        if leftstr(bc,2)='RR' then binloc:=bc
        else binnum:=bc;
      if binnum='' then display please scan bin number
      if binloc='' then display please scan bin location
      finished:=((binnum<>'') and (binloc<>''));
  if not barcodeaborted do
    // code got valid barcode
--- End code ---

Thx Josh,
so i am on the right path...


[0] Message Index

Go to full version