Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Averge of Check boxes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shaneman - 19 Oct 2005 21:08 GMT
I have a form were users need to select a cyheckbox that correspondes to a
rating of 1 thru 4 and I need to get the average score of all.

Example:

1   2   3    4
 0  X  0  0

1   2   3    4
x   0  0  0

Average = 1.5

How can I do this? Can I do this?
Jean-Guy Marcil - 19 Oct 2005 22:46 GMT
Shaneman via OfficeKB.com was telling us:
Shaneman via OfficeKB.com nous racontait que :

> I have a form were users need to select a cyheckbox that correspondes
> to a rating of 1 thru 4 and I need to get the average score of all.
[quoted text clipped - 10 lines]
>
> How can I do this? Can I do this?

Name each series of checkbox using a pattern like:
One1, One2, One3, One4
Two1, Two2, Two3, Two4
etc.

The actual letters do not matter, as long as each name is unique and that it
finishes with the digits 1 to 4.

Then, set each textbox to calculate on exit and to call the macro called
"Calculate" on Exit.

Finally, have a textbox named "Result" and disable its option "Fill-in
enabled".

But really, it would be easier with a userform and option buttons which are
mutually exclusive....

'_______________________________________
Sub Calculate()

ActiveDocument.FormFields("Result").Result = CStr(GetAverage)

End Sub
'_______________________________________

'_______________________________________
Function GetAverage() As Single

Dim myFormField As FormField
Dim myTotal As Single
Dim myCount As Single

For Each myFormField In ActiveDocument.FormFields
   If myFormField.Type = wdFieldFormCheckBox Then
       If myFormField.CheckBox.Value = True Then
           myTotal = myTotal + CSng(Right(myFormField.Name, 1))
       End If
       myCount = myCount + 1
   End If
Next

GetAverage = Format((myTotal / (myCount / 4)), "#0.0")

End Function
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Shaneman - 20 Oct 2005 15:52 GMT
Thanks for the reply.

You said it would be easier with user form and option buttons. Can you tell
me more? I want to do this the easiest way and would appreciate any
assistance.

>Shaneman via OfficeKB.com was telling us:
>Shaneman via OfficeKB.com nous racontait que :
[quoted text clipped - 50 lines]
>End Function
>'_______________________________________
Jean-Guy Marcil - 20 Oct 2005 19:52 GMT
Shaneman via OfficeKB.com was telling us:
Shaneman via OfficeKB.com nous racontait que :

> Thanks for the reply.
>
> You said it would be easier with user form and option buttons. Can
> you tell me more? I want to do this the easiest way and would
> appreciate any assistance.

It is just that with a userform you can use OptionButtons. By using the
Group property or by putting them into frames (easier with the Group
property) they become automatically mutually exclusive.
With a Word protected form you have to add code to make the checkboxes
mutually exclusive...

You would use the same approach I have already outlined, but call the code
with the Option button Change event.

If you have never done a userform, then it may be more difficult.

I just mentioned it in case you knew about using userforms but had not
considered that possibility for your project.

For more info on userform see:
   http://word.mvps.org/faqs/Userforms/index.htm

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.