SR1092 SR1092 - 6 months ago 12
Vb.net Question

Drop down values sending '0' instead of value to message box in VB.net

I am using VB 2013 and trying to send values from a dropdown to a message box, but it's returning 0. My code is as below :

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim value1 As String
Dim value2 As String

value1 = Val(Project_Name.SelectedItem)
value2 = Val(ComboBox2.SelectedItem)
Windows.Forms.MessageBox.Show(value1, value2)

End Sub


enter image description here

Where have I gone wrong? Appreciate any help / suggestion. I am completely new to Vb.net

Answer

You can use String.Format like :

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim value1 As String
            Dim value2 As String
            value1 = Project_Name.SelectedItem.ToString()
            value2 = ComboBox2.SelectedItem.ToString()
          Dim s As String = String.Format("Value 1: {0}  value2 : {1}", value1 , value2)
            Windows.Forms.MessageBox.Show(s)

        End Sub