Forcase and Do/While

Discussions about CSEntry
htuser
Posts: 317
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Forcase and Do/While

Postby htuser » March 7th, 2018, 12:18 pm

Dear all,

Does it's impossible to use forcase with do/while?

Code: Select all

if $="" then
numeric nbreCase=countcases(RAPPORT_EXT_DICT where CODE_ENUMERATEUR<>"");

forcase RAPPORT_EXT_DICT  where CODE_ENUMERATEUR<>"" do
        ctr = 1 while ctr <=nbreCase
            if CODE_ENUMERATEUR(ctr)=$ then
         Else
      warning ("Le code saisi: %v, est invalide!",$);
               stop(1);

   endif;
   
   endfor;
endif;

This code display errors..: ERROR: Expecting ';' or operator near line 45 in CODE_OPERATEUR procedure
Thanks in advance.

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

Re: Forcase and Do/While

Postby Gregory Martin » March 7th, 2018, 12:37 pm

This code is mixing a forcase loop with a do/while loop. You can write it like this:

if $="" then

    numeric nbreCase = countcases(RAPPORT_EXT_DICT where CODE_ENUMERATEUR<>"");

    forcase RAPPORT_EXT_DICT  where CODE_ENUMERATEUR <> "" do

        do ctr = 1 while ctr <= nbreCase
            if CODE_ENUMERATEUR(ctr)=$ then
            Else
                warning ("Le code saisi: %v, est invalide!",$);
                stop(1);
            endif;
        enddo;

    endfor;

endif;


Or you can eliminate the second loop like this:

if $="" then

    numeric nbreCase = countcases(RAPPORT_EXT_DICT where CODE_ENUMERATEUR<>"");

    forcase RAPPORT_EXT_DICT  where CODE_ENUMERATEUR <> "" do

        if not CODE_ENUMERATEUR(ctr) in 1:nbreCase then
            warning ("Le code saisi: %v, est invalide!",$);
            stop(1);
        endif;

    endfor;

endif;

htuser
Posts: 317
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: Forcase and Do/While

Postby htuser » March 7th, 2018, 3:29 pm

Thank you Greg for your very prompt response and support.
It seem that my approach isn't well since this code display errors...CODE_ENUMERATEUR(ctr) doesn't accept subscript in the compiler.
Here's in attached a sample of my work.
I would like to use lookup file to fill users code, name, surname and password in login.This will replace many lines if then else/elseif of previous applications.

I've an external file (Excel to be converted in Csdb to be sync on Csweb). So it's easy to change this excel file by adding names etc during fieldwork.
In the future when sqlquery can fully work on Csdb file, it will be very easy... Now, i can't do it using forcase...where.

However, i've a more complicated database (more than 20 columns with lot of string (alpha) values) to lookup in a survey. This will reduce greatly field work times. It's why i need to finalize this sample.

Please help!

Lookup_register.zip
(27.62 KiB) Downloaded 47 times

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

Re: Forcase and Do/While

Postby Gregory Martin » March 8th, 2018, 12:02 pm

Can't you just use loadcase? Why do you have to loop through the cases? Assuming that the operator ID is supposed to match CODE_1, it would simply be like this:

CODE_1 = tonumber(getoperatorid());

if loadcase(LISTE_ENUM_DICT,CODE_1) = 0 then
    errmsg("Le code saisi: %v, est invalide!",$);
    stop(1);
endif;

htuser
Posts: 317
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: Forcase and Do/While

Postby htuser » March 8th, 2018, 12:20 pm

Hi Greg,
Thanks you for response.
I've never use loadcase before. But, in all Workshop's notes or example, it's often used for few items, mainly with numeric data structure.
So, i would like to know:
a) Can i use it with multiple alpha items (an Excel file with 25 columns)...?
b) Do you think that it's more convenient, simple to use slquery with sqlite (.slite, .db3) file to perform this task?
c) In the event we have a password protected sqlite file, does Cspro can open it using credentials?

Thanks in advance for your precious support!

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

Re: Forcase and Do/While

Postby Gregory Martin » March 8th, 2018, 1:37 pm

Loadcase is used with external dictionaries, and it can work with numeric and alpha ID items. It's used for loading single cases from data files. Once you load the case, you can access any of the data stored in that case.

In your example, it's like doing: select * from LISTE_ENUM_DICT where CODE_1 = tonumber(getoperatorid())

This is the traditional way of using external reference files in CSPro.

htuser
Posts: 317
Joined: December 19th, 2011, 6:26 pm
Location: HAITI

Re: Forcase and Do/While

Postby htuser » March 8th, 2018, 6:46 pm

Thank you Greg. The problem has been solved using loadcase!


Return to “Entry”