Source language: Translate to:

Checkboxes - What am I doing wrong?

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Checkboxes - What am I doing wrong?

Postby seanie » Thu Jun 06, 2013 3:43 pm

Hello fellow Neobookers,

I'm testing an exam practice app that gives students immediate feedback when they are finished. At the end, they get their total score as well as buttons to click on to check their answers against the correct answers. Everything works except the test had one flaw: For the sections with checkboxes, if they selected all the the text boxes - in addition to the correct checkbox - they still got the point. Hmmm... so then I decided to make it so that if they chose the correct checkbox plus another one (or two), they would LOSE a point. I did it like this:

If "[CheckBox18]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[Checkbox16]" "=" "Checked"
While "[Checkbox18]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox17]" "=" "Checked"
While "[Checkbox18]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

This was for a question with 3 possible answers, and Checkbox18 represents the correct answer.

Everything worked out fine EXCEPT when students chose Checkbox16 or Checkbox17 WITHOUT choosing Checkbox18. Instead of just getting zero points, the app deducted anywhere from 10 to 20 points. If anyone can tell me why this is happening, I'd be most grateful for your insight. (I'll copy and paste the complete action script below)

Finally - and please forgive my ignorance - it seems that radiobuttons can be set up so that when you click one in a set, it automatically deselects the others. How can I do that with checkboxes? If I could do that, I think that might save me this headache:) I know it might sound kind of dumb, but I'm using checkboxes as opposed to radiobuttons, because I want the app to look exactly like the paper exam which has boxes:). Since I want to learn, I'd also like to know why the problem explained above happens.

Thanks for reading!


SetVar "[Right]" "0"


If "[CheckBox18]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf


If "[CheckBox19]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox24]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox25]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox28]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[Checkbox16]" "=" "Checked"
While "[Checkbox18]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf


If "[Checkbox17]" "=" "Checked"
While "[Checkbox18]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf


If "[Checkbox20]" "=" "Checked"
While "[Checkbox19]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox21]" "=" "Checked"
While "[Checkbox19]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox22]" "=" "Checked"
While "[Checkbox24]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox23]" "=" "Checked"
While "[Checkbox24]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox26]" "=" "Checked"
While "[Checkbox25]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox27]" "=" "Checked"
While "[Checkbox25]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox30]" "=" "Checked"
While "[Checkbox28]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox31]" "=" "Checked"
While "[Checkbox28]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[TextEntry3]" "=" "h"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry4]" "=" "d"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry5]" "=" "b"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry6]" "=" "e"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry7]" "=" "f"
SetVar "[Right]" "[Right] +1"
EndIf


If "[CheckBox34]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox37]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox38]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox47]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[CheckBox51]" "=" "Checked"
SetVar "[Right]" "[Right] +1"
EndIf

If "[Checkbox32]" "=" "Checked"
While "[Checkbox34]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox33]" "=" "Checked"
While "[Checkbox34]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox35]" "=" "Checked"
While "[Checkbox37]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox36]" "=" "Checked"
While "[Checkbox37]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox39]" "=" "Checked"
While "[Checkbox38]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox40]" "=" "Checked"
While "[Checkbox38]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox48]" "=" "Checked"
While "[Checkbox47]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox49]" "=" "Checked"
While "[Checkbox47]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox50]" "=" "Checked"
While "[Checkbox51]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[Checkbox52]" "=" "Checked"
While "[Checkbox51]" "=" "Checked"
SetVar "[Right]" "[Right] -1"
EndIf

If "[TextEntry8]" "=" "Monday"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry9]" "=" "January"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry10]" "=" "9:15"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry10]" "=" "9.15"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry11]" "=" "57"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry12]" "=" "station"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry12]" "=" "the station"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry13]" "=" "9:30"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry13]" "=" "9.30"
SetVar "[Right]" "[Right] +1"
EndIf


If "[TextEntry14]" "=" "4:00"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry14]" "=" "4.00"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry14]" "=" "4 o'clock"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry15]" "=" "Sunday"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry15]" "=" "Sundays"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry16]" "=" "21"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry17]" "=" "60"
SetVar "[Right]" "[Right] +1"
EndIf

If "[TextEntry17]" "=" "60p"
SetVar "[Right]" "[Right] +1"
EndIf
seanie
 
Posts: 47
Joined: Tue Jul 31, 2007 9:33 am

Re: Checkboxes - What am I doing wrong?

Postby mishem » Thu Jun 06, 2013 4:30 pm

Finally - and please forgive my ignorance - it seems that radiobuttons can be set up so that when you click one in a set, it automatically deselects the others. How can I do that with checkboxes?


http://rghost.ru/46568184
Last edited by mishem on Thu Jun 06, 2013 4:43 pm, edited 1 time in total.
mishem
 
Posts: 575
Joined: Mon Oct 08, 2012 1:51 pm

Re: Checkboxes - What am I doing wrong?

Postby seanie » Thu Jun 06, 2013 4:43 pm

Thanks mishem,

Please don't hate me, but I'm a bit scared to click on that link:-)

S
seanie
 
Posts: 47
Joined: Tue Jul 31, 2007 9:33 am

Re: Checkboxes - What am I doing wrong?

Postby mishem » Thu Jun 06, 2013 4:45 pm

In general, it is file sharing. There's a zip archive file with the example of a pub.

Well fear further.
What more can I say.
There I added a version with images.
Who will be interesting, will download. :)
mishem
 
Posts: 575
Joined: Mon Oct 08, 2012 1:51 pm

Re: Checkboxes - What am I doing wrong?

Postby dpayer » Fri Jun 07, 2013 7:30 am

it seems that radiobuttons can be set up so that when you click one in a set, it automatically deselects the others. How can I do that with checkboxes?


The two do not have the same properties. In fact typically you would use radio button for that exclusive selection and checkboxes for a multiple select.

Having said that, there is (as is often the case!) a workaround:

In the "CLICK" section of the actions for the checkbox you could call a subroutine that would go through your list of checkboxes and set their variable to be empty.
Code: Select all
.this would be the subroutine's code. create it first and then call it from the click section of your checkbox
.I always use a consistent naming for my counters  - Where In Loop Locator = WILL

Loop "1" "[NumOfCheckboxes]" "[WILL]"
            SetVar "[Checkbox[WILL]]" ""
Endloop
SetVar "[[Self]]" "Checked"

---------------
So if your checkboxes are all named sequentially as Checkbox1, Checkbox2, Checkbox3, etc and their variables are named [Checkbox1], [Checkbox2], [Checkbox3] you will reset them all to empty but afterward, using the [self] variable - this is a global variable that contains the name of the object that executed the currently running Action script, you will set the variable of the selected checkbox object to be checked.

(note the double brackets in the final SetVar statement - it resolves the name of the checkbox initiating the action first and then uses that name as the name of the variable. The value of the variable is then set to be 'checked').
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Checkboxes - What am I doing wrong?

Postby seanie » Sun Jun 09, 2013 10:00 pm

Thank you dpayer for your response/help.

What you say about checkboxes being intended for ticking multiple options makes perfect sense now that I think about it. I was just going for aesthetics over essentials, since the paper exam has checkboxes.

I thought my work-around (taking off a point) was ever so clever, but it has been **** :D

I tried using your code, but what it did was - when I chose all three options for an item (checking all three checkboxes for a multiple choice item) - made it impossible to uncheck them hehe.

I don't think that's what you were going for... or was it? :D

In any case, I'm grateful you took the time and effort to help a fellow (NB) traveller.

Peace.

S
seanie
 
Posts: 47
Joined: Tue Jul 31, 2007 9:33 am

Re: Checkboxes - What am I doing wrong?

Postby dpayer » Mon Jun 10, 2013 7:10 am

seanie wrote:I tried using your code, but what it did was - when I chose all three options for an item (checking all three checkboxes for a multiple choice item) - made it impossible to uncheck them hehe.

I don't think that's what you were going for... or was it? :D
S


No, that was not my goal but I had not incorporated the idea that you had groups of checkboxes for each question. I modified my code a bit and tested it, now it works. With this system, you cannot give deductions for wrong answers though for you will only be allowing one selection per 'set' or per question. Each question will have code similar to this (below) in the 'click' section of actions.

Code: Select all
SetVar "[set]" "1,2,3"
StrParse "[set]" "," "[set_a]" "[SetCnt]"
Loop "1" "[SetCnt]" "[WILL_S]"
SetVar "[checkbox[set_a[WILL_S]]]" ""
Endloop
SetVar "[[self]]" "Checked"


For each question you will have to identify the set of checkboxes that go with that question.(example above: Checkbox1, Checkbox2, Checkbox3 would set the variable as 1,2,3. Separate values by commas. The script parses that set and then blanks all checked boxes in that set and then resets the [[self]] checkbox variable.

Here is a demo app (proof of concept). Copy this code into a blank 800x600 pub.
Code: Select all

{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=12
Name=CheckBox1
X=90
Y=92
W=62
H=49
Anchor=0
Text=Blue
Align=1
VarName=[CheckBox1]
InitState=0
ObjAction=SetVar "[set]" "1,2,3"¶StrParse "[set]" "," "[set_a]" "[SetCnt]"¶Loop "1" "[SetCnt]" "[WILL_S]"¶SetVar "[checkbox[set_a[WILL_S]]]" ""¶Endloop¶SetVar "[[self]]" "Checked"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=12
Name=CheckBox2
X=90
Y=122
W=62
H=49
Anchor=0
Text=Red
Align=1
VarName=[CheckBox2]
InitState=0
ObjAction=SetVar "[set]" "1,2,3"¶StrParse "[set]" "," "[set_a]" "[SetCnt]"¶Loop "1" "[SetCnt]" "[WILL_S]"¶SetVar "[checkbox[set_a[WILL_S]]]" ""¶Endloop¶SetVar "[[self]]" "Checked"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=12
Name=CheckBox3
X=90
Y=153
W=62
H=49
Anchor=0
Text=Yellow
Align=1
VarName=[CheckBox3]
InitState=0
ObjAction=SetVar "[set]" "1,2,3"¶StrParse "[set]" "," "[set_a]" "[SetCnt]"¶Loop "1" "[SetCnt]" "[WILL_S]"¶SetVar "[checkbox[set_a[WILL_S]]]" ""¶Endloop¶SetVar "[[self]]" "Checked"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=8
Name=Text1
X=90
Y=81
W=218
H=23
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 What color is Blue?}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
TabOrder=5
ObjectType=12
Name=CheckBox4
X=84
Y=232
W=62
H=49
Anchor=0
Text=Right
Align=1
VarName=[CheckBox4]
InitState=0
ObjAction=SetVar "[set]" "4,5,6"¶StrParse "[set]" "," "[set_a]" "[SetCnt]"¶Loop "1" "[SetCnt]" "[WILL_S]"¶SetVar "[checkbox[set_a[WILL_S]]]" ""¶Endloop¶SetVar "[[self]]" "Checked"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=12
Name=CheckBox5
X=83
Y=262
W=62
H=49
Anchor=0
Text=In
Align=1
VarName=[CheckBox5]
InitState=0
ObjAction=SetVar "[set]" "4,5,6"¶StrParse "[set]" "," "[set_a]" "[SetCnt]"¶Loop "1" "[SetCnt]" "[WILL_S]"¶SetVar "[checkbox[set_a[WILL_S]]]" ""¶Endloop¶SetVar "[[self]]" "Checked"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=7
ObjectType=12
Name=CheckBox6
X=83
Y=293
W=62
H=49
Anchor=0
Text=Up
Align=1
VarName=[CheckBox6]
InitState=0
ObjAction=SetVar "[set]" "4,5,6"¶StrParse "[set]" "," "[set_a]" "[SetCnt]"¶Loop "1" "[SetCnt]" "[WILL_S]"¶SetVar "[checkbox[set_a[WILL_S]]]" ""¶Endloop¶SetVar "[[self]]" "Checked"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=8
ObjectType=8
Name=Text2
X=83
Y=221
W=218
H=23
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Which way is up?}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
TabOrder=9


David P.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Checkboxes - What am I doing wrong?

Postby seanie » Mon Jun 10, 2013 5:24 pm

Works perfectly, David!

You, sir, area a genius.

Gratitude:-)

S
seanie
 
Posts: 47
Joined: Tue Jul 31, 2007 9:33 am

Re: Checkboxes - What am I doing wrong?

Postby dpayer » Tue Jun 11, 2013 9:00 am

seanie wrote:Works perfectly, David!

You, sir, area a genius.

S



Could I give you my wife's email address so you could send that comment to her please? :lol:

David
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Checkboxes - What am I doing wrong?

Postby seanie » Wed Jun 12, 2013 10:57 pm

Show her your brilliant contributions here. I doubt she'd be impressed with my typos. :-)
seanie
 
Posts: 47
Joined: Tue Jul 31, 2007 9:33 am

Re: Checkboxes - What am I doing wrong?

Postby smokinbanger » Sat Jun 15, 2013 9:58 pm

More tips:
dpayer wrote:...In fact typically you would use radio button for that exclusive selection and checkboxes for a multiple select...
This is true however the main menu lacks radios so the checkbox method is required. Also in some situations that have available options something like;

Option A
Option B
Option C
None

where the user can simultaneously select any combination of A, B, or C or the None option which would deselect all other options.

dpayer wrote:So if your checkboxes are all named sequentially as Checkbox1, Checkbox2, Checkbox3, etc and their variables are named [Checkbox1], [Checkbox2], [Checkbox3] you will reset them all to empty but afterward, using the [self] variable - this is a global variable that contains the name of the object that executed the currently running Action script, you will set the variable of the selected checkbox object to be checked...
If they are all named sequentially like mentioned, skip the loop use:
Code: Select all
DeleteArray "CheckBox" "All"
the use the [self] method. I recommend using something else besides the default Checkbox name.

try these:
Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=12
Name=CheckBox2
X=20
Y=15
W=29
H=19
Anchor=0
Text=A
Align=1
VarName=[Opt1]
InitState=0
AutoSize=Yes
ObjAction=If "[Opt1]" "=" "Checked"¶   SetVar "[None]" ""¶EndIf
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=12
Name=CheckBox3
X=20
Y=40
W=29
H=19
Anchor=0
Text=B
Align=1
VarName=[Opt2]
InitState=0
AutoSize=Yes
ObjAction=If "[Opt2]" "=" "Checked"¶   SetVar "[None]" ""¶EndIf
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=12
Name=CheckBox4
X=20
Y=65
W=29
H=19
Anchor=0
Text=C
Align=1
VarName=[Opt3]
InitState=0
AutoSize=Yes
ObjAction=If "[Opt3]" "=" "Checked"¶   SetVar "[None]" ""¶EndIf
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=12
Name=CheckBox5
X=20
Y=90
W=50
H=19
Anchor=0
Text=None
Align=1
VarName=[None]
InitState=0
AutoSize=Yes
ObjAction=If "[None]" "=" "Checked"¶   DeleteArray "[Opt]" "All"¶EndIf
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
Just Sayin'...
smokinbanger
 
Posts: 198
Joined: Mon Jan 16, 2012 9:53 am
Location: United States


Return to NeoBook Action Commands

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron