Home All Groups Group Topic Archive Search About

simple counter variable.

Author
6 Jul 2005 12:58 AM
Casey
I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
answers = answers+1
When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
Thanks for any help.
--



Casey

Author
6 Jul 2005 1:44 AM
Ralph
Step through your code.
"If optButtonX.Value" is likely not True.

  "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
  I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
  answers = answers+1
  When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
  I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
  Thanks for any help.
  --



  Casey
Author
6 Jul 2005 1:58 AM
Casey
By having the value of true, doesn't that mean that it  is checked/selected?  If that's the case, and I put that code into the command button, wouldn't that be true assuming the options button mentioned in the command buttons code was selected?
Thanks

--


Casey


"Ralph" <nt_consultin***@yahoo.com> wrote in message news:7vqdnX9wpdYuqlbfRVn-2Q@arkansas.net...
Step through your code.
"If optButtonX.Value" is likely not True.

  "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
  I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
  answers = answers+1
  When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
  I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
  Thanks for any help.
  --



  Casey
Author
6 Jul 2005 2:10 AM
Ralph
Yeap, that sounds correct, but apparently it may not be happening.
Hard to guess without more code.

You did define 'Answer' as 'Public' - correct?
And you are using Option Explicit - correct?
(If not each Form might have its own 'Answer')

Stepping thru the code usually points out problem spots rather quickly.
Another technigue when playing with comparisons is to spread the code out over multiple lines, so you can see exactly what is happening. For example...

Dim bJunk as Boolean
Dim vJunk As Variant      ' There is some advantage to a variant as you can test 'type'
                                     ' eg, you accidently are assuming a 'value' to be a boolean when in fact
                                     ' it is returning 0, 1, 2, ...
bJunk = optButtonX.Value
Debug.Print bJunk
If bJunk = true Then
.....
or
vJunk = optButtonX.Value
debug.Print vJunk & "   " & VarType(vJunk)    ' CStr(VarType(vJunk)
  "Casey" <csm***@cfl.rr.com> wrote in message news:uCL284cgFHA.2880@TK2MSFTNGP14.phx.gbl...
  By having the value of true, doesn't that mean that it  is checked/selected?  If that's the case, and I put that code into the command button, wouldn't that be true assuming the options button mentioned in the command buttons code was selected?
  Thanks

  --


  Casey


  "Ralph" <nt_consultin***@yahoo.com> wrote in message news:7vqdnX9wpdYuqlbfRVn-2Q@arkansas.net...
  Step through your code.
  "If optButtonX.Value" is likely not True.

    "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
    I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
    answers = answers+1
    When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
    I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
    Thanks for any help.
    --



    Casey
Author
6 Jul 2005 2:40 AM
Casey
Yes, Answer is public.  and I did use Option Explicit. 
The strange thing is I tried it in a form, and it worked.  but the same tactic isn't working when I try and  use it across the entire app.

--


Casey


"Ralph" <nt_consultin***@yahoo.com> wrote in message news:1NmdnWzaXvJSoFbfRVn-uw@arkansas.net...
Yeap, that sounds correct, but apparently it may not be happening.
Hard to guess without more code.

You did define 'Answer' as 'Public' - correct?
And you are using Option Explicit - correct?
(If not each Form might have its own 'Answer')

Stepping thru the code usually points out problem spots rather quickly.
Another technigue when playing with comparisons is to spread the code out over multiple lines, so you can see exactly what is happening. For example...

Dim bJunk as Boolean
Dim vJunk As Variant      ' There is some advantage to a variant as you can test 'type'
                                     ' eg, you accidently are assuming a 'value' to be a boolean when in fact
                                     ' it is returning 0, 1, 2, ...
bJunk = optButtonX.Value
Debug.Print bJunk
If bJunk = true Then
.....
or
vJunk = optButtonX.Value
debug.Print vJunk & "   " & VarType(vJunk)    ' CStr(VarType(vJunk)
  "Casey" <csm***@cfl.rr.com> wrote in message news:uCL284cgFHA.2880@TK2MSFTNGP14.phx.gbl...
  By having the value of true, doesn't that mean that it  is checked/selected?  If that's the case, and I put that code into the command button, wouldn't that be true assuming the options button mentioned in the command buttons code was selected?
  Thanks

  --


  Casey


  "Ralph" <nt_consultin***@yahoo.com> wrote in message news:7vqdnX9wpdYuqlbfRVn-2Q@arkansas.net...
  Step through your code.
  "If optButtonX.Value" is likely not True.

    "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
    I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
    answers = answers+1
    When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
    I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
    Thanks for any help.
    --



    Casey
Author
6 Jul 2005 2:34 AM
Randy Birch
This may provide you with some ideas ...
http://vbnet.mvps.org/code/project/kidzquiz1.htm

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



"Casey" <csm***@cfl.rr.com> wrote in message
news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
I am designing a multiple choice test application.  I created a module and
declared a public variable called Answers.  Within each form under the
command button's click code I have if optButtonX.value = true then
answers = answers+1
When I get to the end of the program, where the answer should display the
number of questions answered correctly, the program reports that 0 answers
were correct?
I have tried setting answers to 0 in the beginning of the program, but it
didn't seam to help.
Thanks for any help.
--



Casey
Author
6 Jul 2005 2:42 AM
Casey
wow, thanks.  I'll certainly take a look.

--


Casey


"Randy Birch" <rgb_removet***@mvps.org> wrote in message
news:OttFINdgFHA.4000@TK2MSFTNGP12.phx.gbl...
This may provide you with some ideas ...
http://vbnet.mvps.org/code/project/kidzquiz1.htm

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



"Casey" <csm***@cfl.rr.com> wrote in message
news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
I am designing a multiple choice test application.  I created a module and
declared a public variable called Answers.  Within each form under the
command button's click code I have if optButtonX.value = true then
answers = answers+1
When I get to the end of the program, where the answer should display the
number of questions answered correctly, the program reports that 0 answers
were correct?
I have tried setting answers to 0 in the beginning of the program, but it
didn't seam to help.
Thanks for any help.
--



Casey
Author
6 Jul 2005 11:46 AM
Steve Easton
Why do you even need:  if optButtonX.value = true then

If it is in the click event for the button all you need is: answers = answers + 1



--
Steve
95isalive
This site is best viewed............
........................with a computer

  "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
  I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
  answers = answers+1
  When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
  I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
  Thanks for any help.
  --



  Casey
Author
6 Jul 2005 12:28 PM
Casey
Because, if I understand this, I don't want the user to be able to repeatedly check the option button to rack up their score. 

--


Casey


"Steve Easton" <ad***@95isalive.com> wrote in message news:uXXLgDigFHA.2444@tk2msftngp13.phx.gbl...
Why do you even need:  if optButtonX.value = true then

If it is in the click event for the button all you need is: answers = answers + 1



--
Steve
95isalive
This site is best viewed............
........................with a computer

  "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
  I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
  answers = answers+1
  When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
  I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
  Thanks for any help.
  --



  Casey
Author
6 Jul 2005 12:31 PM
Al Reid
>"Casey" <csm***@cfl.rr.com> wrote in message news:eKkYHZigFHA.2916@TK2MSFTNGP14.phx.gbl...
>Because, if I understand this, I don't want the user to be able to repeatedly check the option button to rack up their score.
>
>--
>
>
>Casey

Why don't you post some code so we can see what you are trying to accomplish.  Without it all you are going to get is wild guesses.

--

Al Reid
Author
6 Jul 2005 2:38 PM
Casey
Right.  Ok I have created a public variable within Module1.
Public Answers As Integer
I have 53 forms.  Each form has a read only text box.  Next to the text box
is three option buttons contained within a frame.  Also on the form is a
command button.
When the command button is clicked I have the following code.
unload me
If OptStart.Value = True Then
Answers = Answers + 1
End If
FrmQ2.Show
End Sub

Oh shoot!  Now I see it, I should put the unload me statement below the end
if statement.  I swear I have looked at it for about 8 hours, and I didn't
get it until I tried to explain it.
I am very sorry for taking up all of your time.
I guess I shouldn't quit my day job.
--


Casey


"Al Reid" <arei***@reidDASHhome.com> wrote in message
news:eOo%23WbigFHA.3296@TK2MSFTNGP10.phx.gbl...

>"Casey" <csm***@cfl.rr.com> wrote in message
>news:eKkYHZigFHA.2916@TK2MSFTNGP14.phx.gbl...
>Because, if I understand this, I don't want the user to be able to
>repeatedly check the option button to rack up their score.
>
>--
>
>
>Casey

Why don't you post some code so we can see what you are trying to
accomplish.  Without it all you are going to get is wild guesses.

--

Al Reid
Author
6 Jul 2005 5:03 PM
Larry Serflaten
"Casey" <csm***@cfl.rr.com> wrote

> I have 53 forms.  Each form has a read only text box.  Next to the text box
> is three option buttons contained within a frame.  Also on the form is a
> command button.

Pssst, think re-useable code!!!

Why so many forms?  If they are all the same, can you not just re-use the
same form over and over?

For a quick example, add a button to a new form and paste in the code
below, then run it and read the caption on the 'different' forms...

LFS


Option Explicit
Private Number As Long
Private Questions


Private Sub Command1_Click()
Dim q As New Form1

  If Number < 5 Then
    q.ShowNext Number + 1, Questions(Number)
  End If
  Unload Me

End Sub

Private Sub Form_Load()
  Caption = "This is the start of the Quiz"
  Command1.Caption = "OK"
  Move (Screen.Width - Width) \ (Number + 2), (Screen.Height - Height) \ (Number + 2)
  BackColor = QBColor(Number)

  ' Questions from file or wherever
  Questions = Array("Form1 for Question 1", _
                    "Form1 again for Question 2", _
                    "Form1 yet again for Question 3", _
                    "Form1 one more time for Question 4", _
                    "This is the end of the test!")

End Sub

Public Sub ShowNext(ByVal QNumber As Long, Question)
  Number = QNumber
  Caption = Question
  Show
End Sub
Author
7 Jul 2005 2:17 AM
Casey
I didn't realize I could do that.  I eventually would like to take the wrong
answers and generate a text file, or html file with the wrong answers and
the correct answer.  Would I still be able to do that by using one form with
an array?

--


Casey


"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:e%239ZBwkgFHA.2472@TK2MSFTNGP15.phx.gbl...

"Casey" <csm***@cfl.rr.com> wrote

> I have 53 forms.  Each form has a read only text box.  Next to the text
> box
> is three option buttons contained within a frame.  Also on the form is a
> command button.

Pssst, think re-useable code!!!

Why so many forms?  If they are all the same, can you not just re-use the
same form over and over?

For a quick example, add a button to a new form and paste in the code
below, then run it and read the caption on the 'different' forms...

LFS


Option Explicit
Private Number As Long
Private Questions


Private Sub Command1_Click()
Dim q As New Form1

  If Number < 5 Then
    q.ShowNext Number + 1, Questions(Number)
  End If
  Unload Me

End Sub

Private Sub Form_Load()
  Caption = "This is the start of the Quiz"
  Command1.Caption = "OK"
  Move (Screen.Width - Width) \ (Number + 2), (Screen.Height - Height) \
(Number + 2)
  BackColor = QBColor(Number)

  ' Questions from file or wherever
  Questions = Array("Form1 for Question 1", _
                    "Form1 again for Question 2", _
                    "Form1 yet again for Question 3", _
                    "Form1 one more time for Question 4", _
                    "This is the end of the test!")

End Sub

Public Sub ShowNext(ByVal QNumber As Long, Question)
  Number = QNumber
  Caption = Question
  Show
End Sub
Author
7 Jul 2005 7:06 AM
Larry Serflaten
"Casey" <csm***@cfl.rr.com> wrote
> I didn't realize I could do that.  I eventually would like to take the wrong
> answers and generate a text file, or html file with the wrong answers and
> the correct answer.  Would I still be able to do that by using one form with
> an array?


Of course, you can store your questions and answers in global variables
(declared as Public in a .BAS module) so that they are available to your
entire application.  When the test is done you can use them to build
whatever type of report you like....

LFS
Author
7 Jul 2005 7:31 AM
J French
On Thu, 7 Jul 2005 02:06:10 -0500, "Larry Serflaten"
<serfla***@usinternet.com> wrote:

>
>"Casey" <csm***@cfl.rr.com> wrote
>> I didn't realize I could do that.  I eventually would like to take the wrong
>> answers and generate a text file, or html file with the wrong answers and
>> the correct answer.  Would I still be able to do that by using one form with
>> an array?
>
>
>Of course, you can store your questions and answers in global variables
>(declared as Public in a .BAS module) so that they are available to your
>entire application.  When the test is done you can use them to build
>whatever type of report you like....

Or even better you store your questions and answers in a Text file
that you maintain with say Notepad

- read that on App startup and your system can be 'reprogrammed'
without touching a line of code.
Author
6 Jul 2005 1:01 PM
Rick Rothstein
> Because, if I understand this, I don't want the user to
> be able to repeatedly check the option button to rack
> up their score.

Unless something is different on your version of VB, that won't happen.
Put this statement in your OptionButton's Click event...

    Debug.Print "Hello"

and run your program. The "Hello" text will only print when the
OptionButton clicked provided it is not the currently selected
OptionButton in the group. If you click the OptionButton to select it,
and then repeatedly keep clicking it, the "Hello" text will only print
one time.

Rick
Author
6 Jul 2005 3:47 PM
95isalive
If each question is on it's own form as the last statement for the button add


Buttonx.enabled = false


--
Steve
95isalive
This site is best viewed..................
...............................with a computer
"Casey" <csm***@cfl.rr.com> wrote in message news:eKkYHZigFHA.2916@TK2MSFTNGP14.phx.gbl...
Because, if I understand this, I don't want the user to be able to repeatedly check the option button to rack up their score. 

--


Casey


"Steve Easton" <ad***@95isalive.com> wrote in message news:uXXLgDigFHA.2444@tk2msftngp13.phx.gbl...
Why do you even need:  if optButtonX.value = true then

If it is in the click event for the button all you need is: answers = answers + 1



--
Steve
95isalive
This site is best viewed............
........................with a computer

  "Casey" <csm***@cfl.rr.com> wrote in message news:udNgZXcgFHA.3448@TK2MSFTNGP12.phx.gbl...
  I am designing a multiple choice test application.  I created a module and declared a public variable called Answers.  Within each form under the command button's click code I have if optButtonX.value = true then
  answers = answers+1
  When I get to the end of the program, where the answer should display the number of questions answered correctly, the program reports that 0 answers were correct?
  I have tried setting answers to 0 in the beginning of the program, but it didn't seam to help.
  Thanks for any help.
  --



  Casey