How to average values from 6 different drop downs in a separate text box?

Discussion in 'Word Tables' started by jscranton, Oct 8, 2012.

  1. jscranton

    jscranton Guest

    I have a form with six different content control fields (all drop downs
    that allow a user to rate an employee from 1 to 5. Each has a uniqu
    name.

    What I would like to do is average all six values and put the result i
    a text box elsewhere on the form. Ideally, this would updat
    dynamically.

    I tried initially to accomplish this with the code below. This almos
    works. This creates a array for each of the six values [I have onl
    pasted one below] and then populates the value with 1 to 5 depending o
    the user's selection.

    The problem is that the sub resets after each event (On Exit) so th
    array only contains the most recently selected value.

    Is there a fix to this or another way entirely to accomplish this task?


    Code
    -------------------

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)


    Dim averageValues(0 To 5) As Integer
    Dim i As Integer
    Dim totalFields As Integer
    Dim totalValue As Long



    Select Case ContentControl.Title

    'this is the first of six drop downs

    Case "Project Knowledge"

    If ContentControl.Range.Text = "Poor" Then

    averageValues(0) = 1

    ElseIf ContentControl.Range.Text = "Needs Improvement" Then

    averageValues(0) = 2

    ElseIf ContentControl.Range.Text = "Satisfactory" Then

    averageValues(0) = 3

    ElseIf ContentControl.Range.Text = "Good" Then

    averageValues(0) = 4

    ElseIf ContentControl.Range.Text = "Excellent" Then

    averageValues(0) = 5

    End If

    'loop through the array and find all populated values
    For i = 0 To 5

    If averageValues(i) <> 0 Then

    totalFields = totalFields + 1
    totalValue = totalValue + averageValues(i)

    End If
    Next i


    If totalFields <> 0 Then

    MsgBox totalValue / totalFields
    Else
    Exit Sub
    End If


    End Su
    -------------------


    --
    jscranton
     
    jscranton, Oct 8, 2012
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    1
    Views:
    92
    Suzanne S. Barnhill
    Apr 1, 2004
  2. || cypher ||
    Replies:
    2
    Views:
    96
    || cypher ||
    Nov 10, 2004
  3. LarryMcIntyre

    How do I marry text in 2 separate columns?

    LarryMcIntyre, Jan 20, 2005, in forum: Word Tables
    Replies:
    3
    Views:
    103
    Charles Kenyon
    Jan 20, 2005
  4. Jaye

    Associating drop downs?

    Jaye, Feb 12, 2005, in forum: Word Tables
    Replies:
    2
    Views:
    172
    Doug Robbins
    Feb 13, 2005
  5. TimmyVee
    Replies:
    3
    Views:
    115
    Cindy M -WordMVP-
    Dec 14, 2005
  6. Ben
    Replies:
    2
    Views:
    108
  7. ComputerLady
    Replies:
    1
    Views:
    123
    Lene Fredborg
    Dec 7, 2007
  8. Replies:
    0
    Views:
    104
Loading...