How to Write A Condiotion In CAPI Questions

Discussions about CSEntry
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

How to Write A Condiotion In CAPI Questions

Post by munirmdee1 »

Hi to all,

I'm developing a CAPI Application but I'm facing a problem here I need help. Consider two CAPI questions, Q102 by which a user is asked to enter a product name ("Enter product name"), and Q103 by which a user is asked to enter a quantity of a product ("Whats a quantity of %name% available?") he/she entered in Q102. Now for example if a user entered "Rice" in Q102, I need Q103 to display "What quantity of Rice available?". That is replacing %name% with a product name entered in Q102that is my question, how do I make that happen?

Help please, Thanks in advanced
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: How to Write A Condiotion In CAPI Questions

Post by josh »

If the product name that they enter is an alphanumeric variable then you can use it directly in the question text. For example if you have Q102 as your dictionary variable then you would set your question text to "What quantity of %Q102% is available?".

If your dictionary variable is numeric and you want to use the label from the value set for the value chosen in Q102 then you can use a logic variable of type string from PROC global in the CAPI text to represent the product name. For example:
PROC GLOBAL
string productName;

PROC Q103
onfocus
productName =
getlabel(Q102_VS1, Q102);
Then in the question text for Q103 you would have "What quantity of %productName% is available?"
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: How to Write A Condiotion In CAPI Questions

Post by munirmdee1 »

Thanks Josh,

Actually I know that one. But what I meant here is when I define two languages, for example ENG for English, and SW for Swahili. So if you go to the CAPI Questions options in the toolbar where you can see three panels, one for English, second for Swahili and the last one for Conditions.

Now I'm talking about the third panel for putting conditions. Can I implement what I stated above here?

Actually that is what I meant....
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: How to Write A Condiotion In CAPI Questions

Post by josh »

You could use the conditions window for this but the fill in the question text is a better fit for your situation since you want only part of the text to vary based on the condition not the entire question text.

To use the condition you would add conditions like "Q102=1", "Q102=2", "Q102=3",... in the conditions window, each on a separate line. Then for each of the conditions, click on it in the third panel and then enter the text to display for that condition where you would normally enter question text.
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: How to Write A Condiotion In CAPI Questions

Post by munirmdee1 »

Thanks Josh, I understand. But I have another concern, if I want to change the whole text of the question using condition, for example assuming I have three questions Q101 which asks "How many years ago did this shop start business?", and a second question Q102 which asks "How many years ago did this shop stop business?", now I want question Q103 to display text by checking both Q101 and Q102. For example how to write a condition to check this: Q101 = 3 AND Q102 = 3?

In short I don't know how to use AND(&) in the condition, help me on that please.

Thanks
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: How to Write A Condiotion In CAPI Questions

Post by josh »

You should be able to just use "and" in the condition exactly as you wrote it. Is that not working correctly?
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: How to Write A Condiotion In CAPI Questions

Post by munirmdee1 »

Yes Josh,

I tried to use & it didnt work, then I used AND, also it didnt work, I thought maybe there is another way. Is there another way or its the same as I wrote above? If its the same then it gives me an error?
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How to Write A Condiotion In CAPI Questions

Post by Gregory Martin »

Unfortunately you can only do the most basic conditional checks in the CAPI question text.

What you can do is create a variable and use it in the conditional checks. For example, in PROC GLOBAL, you might add a variable named something like CapiConditionalQ103. Then in the preproc of Q103 you would add:
PROC Q103

    CapiConditionalQ103 = ( Q101 =
3 and Q102 = 3 );
The in your CAPI question text, the condition CapiConditionalQ103 = 1 would be where Q101 and Q102 both equaled 3. CapiConditionalQ103 = 0 would be when that didn't occur.
munirmdee1
Posts: 75
Joined: August 17th, 2015, 9:32 am
Location: Dar es Salaam, Tanzania

Re: How to Write A Condiotion In CAPI Questions

Post by munirmdee1 »

Thanks Josh, the last solution you game me works fine, thank you very much.

Now can you help on another issue here, I have two application, first one has two files, Menu.pen and Menu.pff. And the second one also has two files, Household.pen and Household.pff. How do they works, when a user run the CSEntry, Menu Application runs, and enters City, District, and Ward. Soon after finish entering them, a menu option pops up asking if; A user wants to enter new data, or Modify An Existing data, or Quit an application.
So when a user select "Add New Data" then the Household.pff runs in add mode and a user is able to add new data. also in modify, same a user can modify existing data, now my question is, I want after a user select "Add New Data" or "Modify Existing Data" Household application should run and Menu Application should close, how do I do that?, because in My Tablet, Menu Application is still running, it does not close, until I press back button on the home screen then I will be able to see Household application.
I wrote this in logic of a Menu application:

PROC WARD
Stop(-1);

But its doesn't work, Menu Application still covers the Tablet screen, so to see the Household Application, I must tap the BACK button untill Menu Application goes away then I can see the Household Application. Please how to solve this problem, Thanks in advanced
Munir Mdee
Software Programmer
National Bureau of Statistic (NBS)
Jakaya Kikwete Road,
P.O.Box 2683,
Dodoma,TANZANIA
Mob: +255 755 740090
Email: munir.mdee@nbs.go.tz
munirmdee@gmail.com
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: How to Write A Condiotion In CAPI Questions

Post by josh »

Use the "stop" parameter in the call execpff. See the help on execpff for details.
Post Reply