Pompey1991
Pompey1991

Reputation: 1

How to get an int value out of textbox in Visual Studio 2005

I'm a decent programmer in Java, but all my classes use eclipse so this Christmas I wanted to play around with Visual Studio so that I could build actual GUI's. So I downloaded Visual Studio 2005 cause it includes J#. Right now just trying to play around with getting values from textboxes and setting values there. My only problem is that the only command I can see that will return the value of the textbox is texBox1.get_Text(), which returns a String value. I want an int value though. Is this even possible from a textbox? The only methods that I saw that return ints are get_Right() and such, but i'm guessing thats for tree building. Any help would be really appreciated, even if the answer is no. Maybe you can tell me another way I can get int values from users? Thanks,

Upvotes: 0

Views: 1987

Answers (2)

bitbonk
bitbonk

Reputation: 49609

You will have to parse the string yourself, using Int32.Parse() or Int32.TryParse() like so:

Int32 value = Int32.Parse(texBox1.get_Text());

This is by the way the same way you'd do it in Java (swing, SWT).
Also J# ist a discontinued product. You should not start new projects using J#.

Upvotes: 0

Yossi Dahan
Yossi Dahan

Reputation: 5357

A texbox's Text property is string, so you won't be able to get an integer directly out of that, but you could use one .net's many approaches to casting/conversions to do that. if you know for sure the value is an integer you can use int.Parse(); if you're not sure than use int.TryParse()

Upvotes: 1

Related Questions