check duplicate value of data string

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
vanndy
Posts: 30
Joined: May 10th, 2012, 10:45 pm

check duplicate value of data string

Post by vanndy »

Hello,

I have a text box to entry number (alpha type).

for example: in the field box that have a number separate by comma: 2,52,4,5,52

how can I check a duplicate value for any number in one field box? Any advices please share.

Best regards,

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

Re: check duplicate value of data string

Post by Gregory Martin »

You can do this, though you will have to use logic to parse the string. In the following example, I use a multiply occurring value in the working storage dictionary to keep track of all the numbers entered on the line and then check if there are duplicates. See the attached application and the following code, and let me know if you have any questions.
PROC LONG_STRING

    
numeric numberValues,
            commaPos,
            currentPos =
1,
            stringLength =
length(strip(LONG_STRING));
    
    commaPos =
pos(",",LONG_STRING);
    
    
do while commaPos

        
numeric thisValue = tonumber(LONG_STRING[currentPos:(commaPos - currentPos)]);
        
        
if numberValues > 0 and seek(VALUE = thisValue) in 1:numberValues then
            
errmsg("You entered %d more than once!",thisValue);
            
reenter;
        
endif;
        
        
inc(numberValues);
        VALUE(numberValues) = thisValue;
        
        
if commaPos < stringLength then // search for the next entry
            currentPos = commaPos + 1;
            commaPos =
pos(",",LONG_STRING[currentPos]);
            
            
if commaPos then
                commaPos = currentPos -
1 + commaPos;
            
else
                commaPos = stringLength +
1; // trick the program into thinking that there is a comma at the end of the string
            endif;
        
        
else
            commaPos =
0; // break out of the loop
            
        
endif;
    
    
enddo;
Attachments
commaParser.zip
(2.79 KiB) Downloaded 538 times
vanndy
Posts: 30
Joined: May 10th, 2012, 10:45 pm

Re: check duplicate value of data string

Post by vanndy »

Hello,

Could you explain me about seek function? and I wonder that the VALUE, is it a built-in function or something else?

seek(VALUE = thisValue)
VALUE(numberValues)

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

Re: check duplicate value of data string

Post by Gregory Martin »

VALUE is not built in. It is an item in the working storage dictionary. The working storage dictionary allows us to add temporary variables to our program.

The seek function loops through a repeating group and returns the occurrence number where the conditional statement is true, or 0 if it is never true.

So in the above example, VALUE is a item that repeats because it is on a repeating record. I extract each number from your comma-separated string (thisValue) and then search to see if it has already been added (seek(VALUE = thisValue)). If seek returns any value but 0, that means that it has already been added because it returned the occurrence number where it was found in the group of VALUEs.

Does this help?
vanndy
Posts: 30
Joined: May 10th, 2012, 10:45 pm

Re: check duplicate value of data string

Post by vanndy »

oh, I see. the working storage dictionary executed during tabulation. but there is still a problem with the VALUE while I add it to WS_DICT already. below is the error message occurs.

ERROR: 'VALUE' is not a declared variable or is a misspelled dictionary entry
ERROR: Invalid function call (Single variable in Mult-group, or Multiple variable expected) near line 17 in Q1_MA procedure

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

Re: check duplicate value of data string

Post by Gregory Martin »

The working storage can exist in data entry applications as well. You select File -> Add Files and then click the checkbox next the Working Storage Dictionary.

Did you add value to the working storage record and then set the record to repeat?
vanndy
Posts: 30
Joined: May 10th, 2012, 10:45 pm

Re: check duplicate value of data string

Post by vanndy »

Hello,

After working storage generated in Tabulation, there are a default WS_DICT and the item SYSTEM_TOTAL. So I renamed this item to VALUE. or do I need to add an item in new record separately the default one?

Another way I just do in data entry application as your advise, There is no error with the VALUE. But there is still an error for calling the SEEK function

if numberValues > 0 and seek(VALUE = thisValue) in 1:numberValues


ERROR: Invalid function call (Single variable in Mult-group, or Multiple variable expected) near line 18 in Q1_MA procedure
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: check duplicate value of data string

Post by khurshid.arshad »

Dear Vanndy

Can you share your data entry program or follow these steps in your same program.

step one >File >New >other and then select data dictionary and press ok .
step two: give dictionary name like: "SYSTEM_TOTAL" in same folder where your program is save.
step three: Add new item as "Value" in "SYSTEM_TOTAL_REC". This is a new Record under new dictionary.
Step four: first remove your course from new dictionary "SYSTEM_TOTAL" and then Press>File >add file, you will see small window with external dictionary options. Add your dictionary.

NOTE FOR STEP FOUR: YOU COULD NOT ADD NEW DICTIONARY IF YOUR COURSE IS FOCUS ON "SYSTEM_TOTAL".

I hope it works.

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

Re: check duplicate value of data string

Post by Gregory Martin »

Your initial posting was about "check duplicate value of data string." Are you doing this in data entry or in a tabulation application? I assumed data entry.

You can add a working storage dictionary to any kind of application, including a data entry application. You only get the SYSTEM_TOTAL value if you have a tabulation application.

Did you ever download the application that I posted (commaParser.zip)? Does that work on your machine? If not, you may be using an old version of CSPro. It works using 4.1.002.
vanndy
Posts: 30
Joined: May 10th, 2012, 10:45 pm

Re: check duplicate value of data string

Post by vanndy »

Yes. I downloaded that commaPazer already. and I tested your application, It works fine in my machine. But I used CSPro version 4.1.001. so it means that ver 4.1.001 not recognize the seek function.
Post Reply