Hi i was hoping someone could help me as im new to programming.

Basically i have a form containing 6 combo boxes which have different options to select from the the drop down. Basically each of the options in each box are worth a different number of points eg one combo box asks for thier age and if there <21 thats 3 points and if there >35 thats 2 points. I need to do a code so these are added up when the user selects the options so when they press the button at the end it automatically calculates the number of points and either takes them to the next form if they are accepted ( <14 ) or brings up a message box informing them they are rejected if > 14. if anyone could help i would really appricate it.

The following code requires three combo boxes. Each contains the integers from one to five. the button btnNext will stay disabled until the sum of all three combo boxes is ten or greater. You coold always modify the AddCombo routine, perhaps, to display a string in the textbox something like:

you are still ## points short

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        btnNext.Enabled = False
    End Sub

    Private Function AddCombo() As Integer

        Dim sum As Integer = 0

        For Each cbx As ComboBox In Me.Controls.OfType(Of ComboBox)()
            If cbx.SelectedIndex >= 0 Then
                sum += CInt(cbx.Text)
            End If
        Next

        btnNext.Enabled = sum >= 10

        Return sum

    End Function

    Private Sub ComboBox1_SelectedValueChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
        TextBox1.Text = AddCombo()
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        TextBox1.Text = AddCombo()
    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        TextBox1.Text = AddCombo()
    End Sub

End Class

Edited 4 Years Ago by Reverend Jim

just declare a variable of int datatype then use if statements to check conditions at your combobox selected index changed event.like this

dim totPoints as integer 

'use if condition like this 
if val(combobox1.selectedvalue)  > 20 then 
totPoints = totPoints + 3
elseif  val(combobox1.selectedvalue)  > 30
totPoints = totPoints + 2
Endif

hope this will give you an idea to solve your prob.

Regards

I was a bit hasty in posting the first code. Waqas obviously understood your question better than I did. Here's my first sample with a few changes. Every time a combobox is changed, the value in the control's tag is updated. That still allows you to use a common summing routine and each combobox can have its own logic for mapping a selection to a point value. I tried it with the values 10, 20, 30, 40, 50 in the first combobox.

Public Class Form1

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        btnNext.Enabled = False
    End Sub

    Private Function AddCombo() As Integer

        Dim sum As Integer = 0

        For Each cbx As ComboBox In Me.Controls.OfType(Of ComboBox)()
            If IsNumeric(cbx.Tag) Then
                sum += cbx.Tag
            End If
        Next

        btnNext.Enabled = sum >= 10

        Return sum

    End Function

    Private Sub ComboBox1_SelectedValueChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

        Dim cbx As ComboBox = sender

        Select Case CInt(cbx.Text)
            Case Is < 21
                cbx.Tag = 3
            Case Is < 35
                cbx.Tag = 2
            Case Else
                cbx.Tag = 1
        End Select

        TextBox1.Text = AddCombo()

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

        Dim cbx As ComboBox = sender
        cbx.Tag = CInt(cbx.Text)
        TextBox1.Text = AddCombo()

    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged

        Dim cbx As ComboBox = sender
        cbx.Tag = CInt(cbx.Text)
        TextBox1.Text = AddCombo()

    End Sub

End Class
This article has been dead for over six months. Start a new discussion instead.