restrict barcode

Other discussions about CSPro
MrTaco
Posts: 127
Joined: November 18th, 2014, 1:55 am

restrict barcode

Postby MrTaco » February 16th, 2017, 12:42 pm

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: 852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: restrict barcode

Postby Gregory Martin » February 17th, 2017, 2:32 pm

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: 127
Joined: November 18th, 2014, 1:55 am

Re: restrict barcode

Postby MrTaco » February 18th, 2017, 5:16 am

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: 852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: restrict barcode

Postby Gregory Martin » February 19th, 2017, 1:43 pm

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: 62
Joined: November 22nd, 2013, 4:59 am

Re: restrict barcode

Postby Saint » February 19th, 2017, 1:56 pm

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: 127
Joined: November 18th, 2014, 1:55 am

Re: restrict barcode

Postby MrTaco » February 20th, 2017, 3:13 am

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: 62
Joined: November 22nd, 2013, 4:59 am

Re: restrict barcode

Postby Saint » February 20th, 2017, 4:04 pm

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: 852
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: restrict barcode

Postby Gregory Martin » February 21st, 2017, 8:00 am

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: 127
Joined: November 18th, 2014, 1:55 am

Re: restrict barcode

Postby MrTaco » February 21st, 2017, 8:01 am

Thanks Saint it worked wonders

Saint
Posts: 62
Joined: November 22nd, 2013, 4:59 am

Re: restrict barcode

Postby Saint » February 21st, 2017, 3:58 pm

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.


Return to “Other”