Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Input String

Input String

Scheduled Pinned Locked Moved C#
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    minniemooo
    wrote on last edited by
    #1

    Hi, I have the following code private void checkBox2_CheckedChanged(object sender, System.EventArgs e) { if(checktables.Checked == true) { int tables = Convert.ToInt32(txtqtables.Text); listBox1.Items.Add(35 * tables); } } If I click on my CheckBox, I want the number in the txtqtables.text to be multiplied by 35 and the results to be place in a listbox. I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format. Please help.

    C L 2 Replies Last reply
    0
    • M minniemooo

      Hi, I have the following code private void checkBox2_CheckedChanged(object sender, System.EventArgs e) { if(checktables.Checked == true) { int tables = Convert.ToInt32(txtqtables.Text); listBox1.Items.Add(35 * tables); } } If I click on my CheckBox, I want the number in the txtqtables.text to be multiplied by 35 and the results to be place in a listbox. I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format. Please help.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      paullet wrote:

      I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format.

      Then the value that is put in the text box is not an integer. You need to validate the contents of the text box first, then attempt to convert it. You can also use Int32.TryParse to attempt to convert it and return a boolean to indicate if the conversion succeeded.


      Upcoming FREE developer events: * Glasgow: Agile in the Enterprise Vs. ISVs, db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

      1 Reply Last reply
      0
      • M minniemooo

        Hi, I have the following code private void checkBox2_CheckedChanged(object sender, System.EventArgs e) { if(checktables.Checked == true) { int tables = Convert.ToInt32(txtqtables.Text); listBox1.Items.Add(35 * tables); } } If I click on my CheckBox, I want the number in the txtqtables.text to be multiplied by 35 and the results to be place in a listbox. I am getting an error on "int tables = Convert.ToInt32(txtqtables.Text);" Input string is not in a correct format. Please help.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, if TextBox is empty or contains something that Convert does not recognize you would get that exception.

        Luc Pattyn [Forum Guidelines] [My Articles]


        this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups