Display a variable
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Display a variable

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Location
    .NET 4.0/VS 2010
    Posts
    11

    Display a variable

    Can someone help me?

    I have a variable

    int ten = 10;

    and i want to display it ive tried things like

    textbox1.text = ten;
    textbox1.text = (ten);

    and many other things but they didnt work :-(

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Display a variable

    Code:
    textbox1.Text = ten.ToString();
    The Text property of a TextBox is of type string, but you are trying to assign an int to it. The "ToString()" method of an object returns a string representation, so you can assign that to the Text property. It would probably be a good idea for you to go through some beginner C# tutorials to get the basic syntax and programming concepts down.
    Last edited by BigEd781; December 5th, 2008 at 01:23 AM.

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Display a variable

    Here is a list of good C++ books: http://www.codeguru.com/forum/showthread.php?t=367365.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Display a variable

    Gunnar,

    Also look at the String.Format(...) method, as I suspect sometimes you will want to display many variables at once:
    Code:
    textbox1.Text = String.Format("{0}", ten); 
    // output "10"
    
    textbox1.Text = String.Format("The number is {0}", ten); 
    // output "The number is 10"
    
    textbox1.Text = String.Format("My IQ is {0} and this is the end of the paragraph{1}{1}", ten * 15, Environment.NewLine); 
    // output "My IQ is 150 and this is the end of the paragraph" followed by 2 new lines.
    hope that helps. (I took care not to use 10 in the last statement
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center