'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Thanks for helping me out: VB 2003
Combobox collection from -3 to +3
The goal of the message is to warn the user that the systems only covers +- 3 timezones, if he types in for example +4 or -4, he gets the message (by the way: how to protect the system if he types for instance a character?)
When I run the application: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
'if more more than 3 timezones
Dim utc As Integer
utc = ComboBox1.Text
If utc < -3 > 3 Then
MsgBox("Calculations only for maximum 3 Time Zones", MsgBoxStyle.OKOnly, "Info")
ComboBox1.Text = 0
End If
End Sub
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Try this line:
Code:
If utc < -3 OR utc > 3 Then
I think you are using VB.Net. I had informed a Mod to move this thread to the appropiate section, for getting more apt solutions....:wave:
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Well, two things
1. This is not the .Net forum. You will want to post additional question there, not here.
2. Combobox items are text not numeric values. I'm not a .Net person, but it appears Convert is what you want. Not sure if this is proper syntax.
Code:
utc = Convert.ToInt32(ComboBox1.Text)
3. You might get an error setting combobox1.text to 0 also. If so, change to "0"
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
change the combobox style to dropdownlist, prevent the user from entering anything other than what's in the combo box.
-tg
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Quote:
2. Combobox items are text not numeric values. I'm not a .Net person, but it appears Convert is what you want. Not sure if this is proper syntax.
Code:
utc = Convert.ToInt32(ComboBox1.Text)
utc = CInt(ComboBox1.Text)
I'd wrap that puppy in a try catch though, if alpha chars make it in there somehow it will crash and burn when it hits that conversion.
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Or you could just use Integer.TryParse() to avoid any mistakes.