restrict barcode

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

restrict barcode

Post by MrTaco »

Good day

I want to restrict barcode number to only allow Alphanuremic that starts with
SV19194
SV20967
so that captures cant enter any number

Thanks
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: restrict barcode

Post by Gregory Martin »

If you just want to make sure that the number starts with SV, you could write something like this:
PROC BARCODE

    if BARCODE[1:2] <> "SV" then
        errmsg("The barcode must start with SV.");
        reenter;
    endif;
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Re: restrict barcode

Post by MrTaco »

Thanks Greg

IT works though i want to be able pass as a missing

Code: Select all

 if BARCODE[1:2] <> "SV" then
        errmsg("The barcode must start with SV.");
        reenter;

 elseif BARCODE =  "" then skip to QN136A;
 endif;
i tried that but it can't pass as missing, i want to also allow captures to pass if there's no barcode
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: restrict barcode

Post by Gregory Martin »

The problem is that you first do the SV check. You need to switch the checks:
if BARCODE = "" then
    skip to QN136A;

elseif BARCODE[1:2] <> "SV" then
    errmsg("The barcode must start with SV.");
    reenter;

endif;
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: restrict barcode

Post by Saint »

Why would you want to bother to enter the first two characters if you know for certain that all valid BARCODES will start with SV?
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Re: restrict barcode

Post by MrTaco »

Dear Greg

let's say for instance i also want to restrict numeric after SV to allow only 5 numeric numbers not less than 5 digits

thanks it worked well though.


Dear Saint

Some ppl don't use a scanner when they collect data so it becomes a problem when they type it in

eg. others capture 9874 or sv432

and that's not what we expect from barcode number.
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: restrict barcode

Post by Saint »

Mr. Taco I get your point.
If you want to restrict the numeric after SV to be 5 digits, then you full code can look something like this:

Code: Select all

if BARCODE = "" then
    skip to QN136A;
elseif BARCODE[1:2] <> "SV" then
    errmsg("The barcode must start with SV.");
    reenter;
elseif length(strip(BARCODE)) <> 7 then 
    errmsg("Full barcode must be 7 characters long")
    reenter;
else
  do i = 3 while i <= 7 
    if not tonumber(BARCODE[i:1]) in 0:9 then
      errmsg("Last five digits of barcode cannot contain a non-numeric character");
      reenter;
    endif;
  enddo;
endif;
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: restrict barcode

Post by Gregory Martin »

Another way of writing what Saint posted is this:
if BARCODE = "" then
    skip to QN136A;

elseif BARCODE[1:2] <> "SV" then
    errmsg("The barcode must start with SV.");
    reenter;

elseif not tonumber(BARCODE[3]) in 10000:99999 then
    errmsg("The barcode must be between SV10000 and SV99999.");
    reenter;

endif;
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Re: restrict barcode

Post by MrTaco »

Thanks Saint it worked wonders
Saint
Posts: 63
Joined: November 22nd, 2013, 4:59 am

Re: restrict barcode

Post by Saint »

My reservation with Gregory's code will be that it will flag something like SV01000 as an error although from what Mr. Taco says, it could be completely legit: there should be 5 numeric characters after SV.
Post Reply