Click to See Complete Forum and Search --> : int to a textbox


maitopoika
January 16th, 2009, 03:32 PM
on a windows application I have a txttable that I am trying to write an int in.
It works fine when i send a string to it, it prints it by doing the following

txtTable.Text = "Hello dealer";


but when i try to send an int variable to it like so
[code]
int x=10;
txtTable.text=x;
[code]

i get the following error
Cannot implicitly convert type 'int' to 'string'
how then can i put this int out to the text box?
Thanks

foamy
January 16th, 2009, 03:35 PM
Just a thought: The ToString method of the Int32 structure perhaps?!
msdn (http://msdn.microsoft.com/en-us/library/6t7dwaa5.aspx)
sheesh!

maitopoika
January 16th, 2009, 03:45 PM
well thanks
the sarcasm is not needed, I am not an idiot
just new to C# and asking a question, and i did not know about the msdn site
if you are too good for such an answer... then just don't answer
Sheesh

BigEd781
January 16th, 2009, 03:45 PM
Check out the beginner's tutorials.

Foamy is snarky because you have obviously not tried to fix it yourself. It is one of the most basic concepts in programming; data types.

maitopoika
January 16th, 2009, 03:52 PM
like I said if you don't want to answer a basic question then don't answer it. It is a message board, anyone can answer who wants to. I did not call him up or send a personal email.
And I did try to fix it my self but got stuck, but I did not know how the txttable works thats why I ask for help.

BigEd781
January 16th, 2009, 04:00 PM
It's ok, I didn't mean to sound rude, it's just that it is *very* basic. If you look at the textbox's "Text" property, you can see that it is of type string. So, that means that you cannot assign an integer to it. A simple search for "Convert integer to string" would have pulled up thousands of results.

Talikag
January 16th, 2009, 09:09 PM
Use the ToString() method in order to convert the int variable into string, i.e.:

int num = 10;
myTextBox.Text = num.ToString();
//myTextBoxText is no containing the value "10" (and NOT 10, which is numerical)

TheCPUWizard
January 16th, 2009, 09:41 PM
well thanks
the sarcasm is not needed, I am not an idiot
just new to C# and asking a question, and i did not know about the msdn site
if you are too good for such an answer... then just don't answer
Sheesh

Not knowing about the MSDN site means you did NOT read the documentation that comes with the product.

So that would either indicate that you already believe you know Everything about the product or ...... well' lets just say your post has an inaccuracy....

I am sure this post has added you to the ignore list of many many people.

JonnyPoet
January 18th, 2009, 11:19 AM
Looking to your former posts i have seen you obviously changed from C++ to C# now.So you have to know: C# is different to C++ in a lot of things. Therefor I would recommand you ( even if you are maybe an expierenced programmer in another language ) take a beginners book like 'MS Visual C# 2005 Step by Step' ( Maybe in between its Visual C#2008 step by step :D , I dont know ) It will not need for long to get all this basics in and after that it will be much easier for you to use C#.

In comparing C# to older languages like VB 6.0 where it was no problem to do
Dim x as Integer
Textbox1.Text = X
This is not possible in C#. C# is very exact in types and as you see and will learn to love,the intellisense is very pregnant and exact. If your intellisense doesn't show you the variable you already have defined when typing the first few letters of it, something is wrong like you may have defined the variable within a loop or an ' if ' condition and now trying to use it outside of it, or something others which isn't allowed in C# and was no problem in C++ or VB.
Trying to compile you will get the errormessages, but you can see problems very often before even compiling by having an eye on the intellisense.

This should only be a hint for some very new C# users. :wave: