Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have problem in calling selected item from combobox that has been converted into double data type.

What I have tried:

VB
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, OS1.SelectedIndexChanged, CSA1.SelectedIndexChanged, ICS1.SelectedIndexChanged, MC1.SelectedIndexChanged, PM1.SelectedIndexChanged, PF1.SelectedIndexChanged, PSPD1.SelectedIndexChanged
        If sender.Text = "A+" Then
            Text = "4.0"
        End If
        If sender.Text = "A" Then
            Text = "4.0"
        End If
        If sender.Text = "A-" Then
            Text = "3.67"
        End If
        If sender.Text = "B+" Then
            Text = "3.33"
        End If
        If sender.Text = "B" Then
            Text = "3.0"
        End If
        If sender.Text = "B-" Then
            Text = "2.67"
        End If
        If sender.Text = "C+" Then
            Text = "2.33"
        End If
        If sender.Text = "C-" Then
            Text = "2.0"
        End If
        If sender.Text = "D" Then
            Text = "1.67"
        End If
        If sender.Text = "D-" Then
            Text = "1.33"
        End If

        Dim total As Double
        total = ((CDbl(3.0 * OS1.SelectedItem) + CDbl(3.0 * CSA1.SelectedItem) + CDbl(2.0 * PM1.SelectedItem) + CDbl(3.0 * MC1.SelectedItem) + CDbl(3.0 * ICS1.SelectedItem) + CDbl(2.0 * PSPD1.SelectedItem) + CDbl(3.0 * PF1.SelectedItem)) / 19.0)
        TextBox1.Text = total
    End Sub
End Class
Posted
Updated 28-Aug-18 4:31am
v2
Comments
Richard MacCutchan 28-Aug-18 5:17am    
What problem? Apart from the fact that your code is making assumptions about the selection in each combobox. And 7 different combos in one application looks quite excessive.

1 solution

Consider this instead:

total = ((3.0 * CDbl(OS1.SelectedItem)) + ... etc 


Assuming ALL .SelectedItems are not null.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900