Hello I'm Rama
I ask for help,
how to validate Date (1234567890) and Day unit (day week month)
In this case I created Data Type Alpha and had to fill in the date and unit in a text box field.
the contents of the data must be the date and unit
example: 30 Days / 1 Week
my current logic is
postproc
string validChars1 = "1234567890 "; // day
string validChars2 = "BULANHARIMINGGU "; // unit of day
do numeric i = 1 while i <= length(strip($))
string char = $[i:1];
if pos(char, validChars1) = 0 AND pos(char, validChars2) = 0 then
errmsg("MASUKAN SATUAN HARI");
reenter;
ENDIF;
ENDDO;
I want both to be between the date and the unit of day
thanks very much
Valid Character
Re: Valid Character
If your time unit is day, week, or month (maybe year too?), then I'm not clear on what you're doing with this line of code:
I think what you want to do is allow someone to choose a unit of day, then enter some # of days (such as 1-30 or 1-31). If they want to enter weeks, then they would enter 1-52 or something. If months, probably 1-12. Assuming you are using these ranges, then
[A] if you ask for the unit field first (which is what I would do if you are able), then you can control via logic what the acceptable values should be for the duration using the SetValueSet function (https://www.csprousers.org/help/CSPro/s ... ction.html). Create 3 (or however many units are being allowed/used) in your dictionary and then refer to them as follows (note the logic is placed in the ONFOCUS):
If you have to take the duration field before asking for the unit, then I would block these two fields (https://www.csprousers.org/help/CSPro/blocks.html), and do the comparison afterwards to ensure they agree. In this scenario you would have to allow DURATION to be 1-52 (or whatever the maximum value is that pairs with a given unit).
If this is not what you want to do, please provide more detail, and/or a screenshot of the questionnaire you're working from.
Sherrell
Code: Select all
string validChars2 = "BULANHARIMINGGU "; // unit of day
[A] if you ask for the unit field first (which is what I would do if you are able), then you can control via logic what the acceptable values should be for the duration using the SetValueSet function (https://www.csprousers.org/help/CSPro/s ... ction.html). Create 3 (or however many units are being allowed/used) in your dictionary and then refer to them as follows (note the logic is placed in the ONFOCUS):
Code: Select all
PROC DURATION
onfocus
if UNIT="D" then SetValueSet ($, DURATION_VS_DAY); // this valueset = 1-31
elseif UNIT="W" then SetValueSet ($, DURATION_VS_WEEK); // this valueset = 1-52
elseif UNIT="M" then SetValueSet ($, DURATION_VS_MO); // this valueset = 1-12
else // etc.
endif;
If this is not what you want to do, please provide more detail, and/or a screenshot of the questionnaire you're working from.
Sherrell
-
- Posts: 4
- Joined: November 1st, 2021, 8:42 am
Re: Valid Character
sherrell wrote: ↑October 7th, 2022, 12:41 pm If your time unit is day, week, or month (maybe year too?), then I'm not clear on what you're doing with this line of code:
I think what you want to do is allow someone to choose a unit of day, then enter some # of days (such as 1-30 or 1-31). If they want to enter weeks, then they would enter 1-52 or something. If months, probably 1-12. Assuming you are using these ranges, thenCode: Select all
string validChars2 = "BULANHARIMINGGU "; // unit of day
[A] if you ask for the unit field first (which is what I would do if you are able), then you can control via logic what the acceptable values should be for the duration using the SetValueSet function (https://www.csprousers.org/help/CSPro/s ... ction.html). Create 3 (or however many units are being allowed/used) in your dictionary and then refer to them as follows (note the logic is placed in the ONFOCUS):
If you have to take the duration field before asking for the unit, then I would block these two fields (https://www.csprousers.org/help/CSPro/blocks.html), and do the comparison afterwards to ensure they agree. In this scenario you would have to allow DURATION to be 1-52 (or whatever the maximum value is that pairs with a given unit).Code: Select all
PROC DURATION onfocus if UNIT="D" then SetValueSet ($, DURATION_VS_DAY); // this valueset = 1-31 elseif UNIT="W" then SetValueSet ($, DURATION_VS_WEEK); // this valueset = 1-52 elseif UNIT="M" then SetValueSet ($, DURATION_VS_MO); // this valueset = 1-12 else // etc. endif;
If this is not what you want to do, please provide more detail, and/or a screenshot of the questionnaire you're working from.
Sherrell
in the questionnaire asked to enter the number of days of use but in one column, instructed to fill in the total days with units of day (CINCOS)
in the column can fill in various units (text box)
I want to make sure the enumerator fills in the number and unit of day
thanks Sherrell
- Attachments
-
- QX
- image_2022-10-08_083117758.png (25.22 KiB) Viewed 3349 times
Re: Valid Character
Hi Rama,
Sorry, I somehow missed your reply post.
>in the questionnaire asked to enter the number of days of use but in one column, instructed to fill in the total days with units of day (CINCOS)
>in the column can fill in various units (text box)
So do you want the enumerator to fill in both the number of days AND the unit in the single column, CINCOS? Which you could "join" two fields to make them appear in the same column (tho if collected on an Android device they won't appear together unless you block them), but you can't have a single field do double-duty and collect two types of data.
Did you try and incorporate the logic I provided before into your program? If so, and you're still having problems, why don't you zip up your program (using CSPro's "pack" utility in the tools dropdown) to post your application here.
Sherrell
Sorry, I somehow missed your reply post.
>in the questionnaire asked to enter the number of days of use but in one column, instructed to fill in the total days with units of day (CINCOS)
>in the column can fill in various units (text box)
So do you want the enumerator to fill in both the number of days AND the unit in the single column, CINCOS? Which you could "join" two fields to make them appear in the same column (tho if collected on an Android device they won't appear together unless you block them), but you can't have a single field do double-duty and collect two types of data.
Did you try and incorporate the logic I provided before into your program? If so, and you're still having problems, why don't you zip up your program (using CSPro's "pack" utility in the tools dropdown) to post your application here.
Sherrell