Page 1 of 2

restrict barcode

Posted: February 16th, 2017, 12:42 pm
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

Re: restrict barcode

Posted: February 17th, 2017, 2:32 pm
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;

Re: restrict barcode

Posted: February 18th, 2017, 5:16 am
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

Re: restrict barcode

Posted: February 19th, 2017, 1:43 pm
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;

Re: restrict barcode

Posted: February 19th, 2017, 1:56 pm
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?

Re: restrict barcode

Posted: February 20th, 2017, 3:13 am
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.

Re: restrict barcode

Posted: February 20th, 2017, 4:04 pm
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;

Re: restrict barcode

Posted: February 21st, 2017, 8:00 am
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;

Re: restrict barcode

Posted: February 21st, 2017, 8:01 am
by MrTaco
Thanks Saint it worked wonders

Re: restrict barcode

Posted: February 21st, 2017, 3:58 pm
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.