-
Apr 28th, 2010, 10:17 AM
#1
Thread Starter
New Member
'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
-
Apr 28th, 2010, 10:26 AM
#2
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....
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Apr 28th, 2010, 10:28 AM
#3
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"
-
Apr 28th, 2010, 10:28 AM
#4
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
-
Apr 28th, 2010, 10:43 AM
#5
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
-
Apr 28th, 2010, 11:04 AM
#6
Fanatic Member
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
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.
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
Apr 28th, 2010, 01:51 PM
#7
Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid
Or you could just use Integer.TryParse() to avoid any mistakes.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|