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. C#
  4. Converting Texbox.Text to int 32

Converting Texbox.Text to int 32

Scheduled Pinned Locked Moved C#
data-structuresquestion
7 Posts 4 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.
  • D Offline
    D Offline
    djkno3
    wrote on last edited by
    #1

    I have a dll I made and have a set property to accept an int. I would like to fill this property by using the textbox class in a form. I call the Convert.ToInt32 like this property = Convert.ToInt32(TextBox.Text); now I get a stack overflow in the dll at the public int property { set {property = value;} //This throws the exeption } Am I calling everything correctly? Or am I missing somthing?

    P R 2 Replies Last reply
    0
    • D djkno3

      I have a dll I made and have a set property to accept an int. I would like to fill this property by using the textbox class in a form. I call the Convert.ToInt32 like this property = Convert.ToInt32(TextBox.Text); now I get a stack overflow in the dll at the public int property { set {property = value;} //This throws the exeption } Am I calling everything correctly? Or am I missing somthing?

      P Offline
      P Offline
      Pyt
      wrote on last edited by
      #2

      It looks like the value entered in the TextBox is too big for an Int32. MDSN: The Int32 value type represents signed integers with values ranging from negative 2,147,483,648 through positive 2,147,483,647. Pyt Pyt.

      D 1 Reply Last reply
      0
      • D djkno3

        I have a dll I made and have a set property to accept an int. I would like to fill this property by using the textbox class in a form. I call the Convert.ToInt32 like this property = Convert.ToInt32(TextBox.Text); now I get a stack overflow in the dll at the public int property { set {property = value;} //This throws the exeption } Am I calling everything correctly? Or am I missing somthing?

        R Offline
        R Offline
        Rickard Andersson20
        wrote on last edited by
        #3

        djkno3 wrote: public int property { set {property = value;} //This throws the exeption } You're assigning the value to the property itself which is wrong. You'll need a member varible of type int, so change the code to this:

        public int MyPropertyName
        {
        set{ myMemberInt = value; }
        }

        Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

        D 1 Reply Last reply
        0
        • R Rickard Andersson20

          djkno3 wrote: public int property { set {property = value;} //This throws the exeption } You're assigning the value to the property itself which is wrong. You'll need a member varible of type int, so change the code to this:

          public int MyPropertyName
          {
          set{ myMemberInt = value; }
          }

          Rickard Andersson@Suza Computing C# and C++ programmer from SWEDEN! UIN: 50302279 E-Mail: nikado@pc.nu Speciality: I love C#, ASP.NET and C++!

          D Offline
          D Offline
          djkno3
          wrote on last edited by
          #4

          Thanks that was the problem. To get the value do I use the same variable eg return myMemberInt? It works like this but is it the correct way?

          K 1 Reply Last reply
          0
          • P Pyt

            It looks like the value entered in the TextBox is too big for an Int32. MDSN: The Int32 value type represents signed integers with values ranging from negative 2,147,483,648 through positive 2,147,483,647. Pyt Pyt.

            D Offline
            D Offline
            djkno3
            wrote on last edited by
            #5

            I guess I should have said that the value was less then the max for an int 32 (eg It was 32) sorry:(

            1 Reply Last reply
            0
            • D djkno3

              Thanks that was the problem. To get the value do I use the same variable eg return myMemberInt? It works like this but is it the correct way?

              K Offline
              K Offline
              kaschimer
              wrote on last edited by
              #6

              To create the read/write property you want, you will want to create a get: public int MyPropertyName { set{ myMemberInt = value; } get{ return myMemberInt; } } RabidK

              D 1 Reply Last reply
              0
              • K kaschimer

                To create the read/write property you want, you will want to create a get: public int MyPropertyName { set{ myMemberInt = value; } get{ return myMemberInt; } } RabidK

                D Offline
                D Offline
                djkno3
                wrote on last edited by
                #7

                thanks that's what I have I was just wondering if it was correct :-D or if I was just getting the right answer by chance and have a nice bug pop up later because of it. thanks

                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