Hey guys! I'm having trouble with my code. I want it to calculate the weight of the user on other planets. I want it to calculate as soon as they click the planet from the drop-down-list. The kicker is i have to go through and select it from the list twice to get the correct calculation. Ive been looking around to no avail. Please help. thanks!
Code:
Public Class frmMain
Private Sub CalcMerc(PLANET_GRAV)
Dim strEarthWeight As String
Dim dblEarthWeight As Double
Dim dblPlanetWeight As Double
strEarthWeight = txtEarth.Text
Double.TryParse(strEarthWeight, dblEarthWeight)
dblPlanetWeight = dblEarthWeight * PLANET_GRAV
txtConverted.Text = dblPlanetWeight.ToString
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cboBox.Items.Add("Mercury")
cboBox.Items.Add("Venus")
cboBox.Items.Add("Mars")
cboBox.Items.Add("Jupiter")
cboBox.Items.Add("Saturn")
cboBox.Items.Add("Uranus")
cboBox.Items.Add("Neptune")
cboBox.Items.Add("Pluto")
cboBox.SelectedIndex = 3
End Sub
Private Sub cboBox_MouseClick(sender As Object, e As MouseEventArgs) Handles cboBox.MouseClick
Const MERCURY_GRAV As Double = 0.38
Const VENUS_GRAV As Double = 0.9
Const MARS_GRAV As Double = 0.38
Const JUPITER_GRAV As Double = 2.5
Const SATURN_GRAV As Double = 0.91
Const URANUS_GRAV As Double = 0.89
Const NEPTUNE_GRAV As Double = 1.14
Const PLUTO_GRAV As Double = 0.08
If cboBox.SelectedIndex = 0 Then
CalcMerc(MERCURY_GRAV)
ElseIf cboBox.SelectedIndex = 1 Then
CalcMerc(VENUS_GRAV)
ElseIf cboBox.SelectedIndex = 2 Then
CalcMerc(MARS_GRAV)
ElseIf cboBox.SelectedIndex = 3 Then
CalcMerc(JUPITER_GRAV)
ElseIf cboBox.SelectedIndex = 4 Then
CalcMerc(SATURN_GRAV)
ElseIf cboBox.SelectedIndex = 5 Then
CalcMerc(URANUS_GRAV)
ElseIf cboBox.SelectedIndex = 6 Then
CalcMerc(NEPTUNE_GRAV)
ElseIf cboBox.SelectedIndex = 7 Then
CalcMerc(PLUTO_GRAV)
End If
End Sub
End Class
Comment