dcsimg
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,646

    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
    18,091

    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

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

    Moved To VB.NET
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,261

    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
  •  



Featured


Click Here to Expand Forum to Full Width