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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Windows Forms
  4. Parsing problem string to int

Parsing problem string to int

Scheduled Pinned Locked Moved Windows Forms
jsonhelpquestion
5 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.
  • R Offline
    R Offline
    RanaSohail
    wrote on last edited by
    #1

    AOA Dears! When I parse TextBox1.text into int or Int32 The exception accurs "Input String is not in correct formate" How can i resolve this Problem. Thanks

    C L R 3 Replies Last reply
    0
    • R RanaSohail

      AOA Dears! When I parse TextBox1.text into int or Int32 The exception accurs "Input String is not in correct formate" How can i resolve this Problem. Thanks

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

      Sohail Ahmad wrote:

      When I parse TextBox1.text into int or Int32 The exception accurs "Input String is not in correct formate" How can i resolve this Problem.

      Don't type stuff in the text box that isn't an integer. Seriously, if you expect that the input may not be in the correct format use TryParse instead as it will return a boolean value to indicate if the string could be parsed or not. Alternatively, catch the exception and handle it. (That much should not have been hard to figure out. Should it?)

      Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Different ways to add point data in SQL Server 2008 * Spatial References in SQL Server 2008 My website |

      1 Reply Last reply
      0
      • R RanaSohail

        AOA Dears! When I parse TextBox1.text into int or Int32 The exception accurs "Input String is not in correct formate" How can i resolve this Problem. Thanks

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

        one of the things most Parse() methods don't like is an empty string. maybe your app is somehow executing your parse code before the box got filled? :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


        1 Reply Last reply
        0
        • R RanaSohail

          AOA Dears! When I parse TextBox1.text into int or Int32 The exception accurs "Input String is not in correct formate" How can i resolve this Problem. Thanks

          R Offline
          R Offline
          RanaSohail
          wrote on last edited by
          #4

          I want to get no of Rectengle from user: Private void Button1_Click(Object sender, MouserEventsArg e) { int No_Rect; No_Rect=int.Parse(Textbox1.text); for(int i=0;i { e.Graphics.DrawRectanle(............); } } In this Situation "Input String is not in coorect Format" Exception Rais. is any other way of parse string to int? :confused::confused::confused:

          L 1 Reply Last reply
          0
          • R RanaSohail

            I want to get no of Rectengle from user: Private void Button1_Click(Object sender, MouserEventsArg e) { int No_Rect; No_Rect=int.Parse(Textbox1.text); for(int i=0;i { e.Graphics.DrawRectanle(............); } } In this Situation "Input String is not in coorect Format" Exception Rais. is any other way of parse string to int? :confused::confused::confused:

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

            Hi, I recommend you try and understand what goes wrong, rather than look for another approach. There is nothing wrong with the approach, so it must be in the details. First and forall, look at the symptoms and describe them in full detail when asking this kind of questions. Did you check the content of Textbox1.Text? Add some code right where you need it, and show the value to yourself. Do not assume everything is all-right, since it clearly is not, otherwise you would not ask for help. is it a valid number (no more no less)? is it empty? does it contain non-digits? why don't you use a try-catch block and show the exception.ToString()? that should tell a lot. BTW: you should not draw things in a button click handler, anyway e.Graphics will not be available there. Seems to me you are a novice in C#, and could benefit a lot from buying and reading in introductory book on C#. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


            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