Recent

Author Topic: Looking for advice - Parse a string from a TEdit  (Read 605 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Looking for advice - Parse a string from a TEdit
« on: April 27, 2022, 02:23:54 pm »
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.....
« Last Edit: April 27, 2022, 02:27:08 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Josh

  • Hero Member
  • *****
  • Posts: 1274
Re: Looking for advice - Parse a string from a TEdit
« Reply #1 on: April 27, 2022, 03:10:53 pm »
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: [Select]
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
  begin
    bc:=readbarcode;  // allow for abort of barcode
    if barcode_aborted then finished=true
    else
    begin
      if length(bc)=12 then
      begin
        binloc:=leftstr(bc,6);
        binnum:=rightstr(bc,6);
      end
      if length(bc)=6 then
      begin
        if leftstr(bc,2)='RR' then binloc:=bc
        else binnum:=bc;
      end;
      if binnum='' then display please scan bin number
      if binloc='' then display please scan bin location
      finished:=((binnum<>'') and (binloc<>''));
    end;
  end;
  if not barcodeaborted do
  begin
    // code got valid barcode
  end;
« Last Edit: April 27, 2022, 03:16:29 pm by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: Looking for advice - Parse a string from a TEdit
« Reply #2 on: April 27, 2022, 03:27:18 pm »
Thx Josh,
so i am on the right path...
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

 

TinyPortal © 2005-2018