Results 1 to 7 of 7

Thread: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Location
    Belgium
    Posts
    4

    '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

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    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,...

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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"
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: 'Unhandled exception: Cast from string "click" to type 'integer' is not valid

    Moved To VB.NET

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    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

  7. #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
  •  



Click Here to Expand Forum to Full Width