Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 51,701 times

Contents

Related Categories

TextBox Control - Setting the text

Setting the text

To set the text in a textbox you use the following syntax:

TextBox1.Text = Text

Where Text is a string containing the text to be used. The code below sets Text1's text to Hello!

TextBox1.Text = "Hello"

If you want to have more than one line of text in a text box you need to set its multiline property to True. Because text boxes uses a carriage return (Chr(10) + Chr(13)) you need to use vbCrLf as the return text, instead of Chr(vbKeyReturn) as you might think. The following example will put the text

An error occured
Please try again

into TextBox1.

TextBox1.Text = "An Error occured" & vbCrLf & "Please try again"

Note that if you are running a long section of code, the text box will not be updated until there is 'free time' in windows. To give the textbox time to update, use the DoEvents function:

For  i = 0 To 10000
    Text1.Text = "Loop number" & i
    DoEvents 'give windows a chance to breath!
Next

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [76] TextBox Control Flickering Problem in C#

    Posted by bishnupatro on 12 Feb 2008

    Hi,


         In my C# application there is a multiline textbox with vertical scrollbar. When the multiline textbox get updated with new ...

  • Posted by bmahler on 15 Nov 2005

    [quote][1]Posted by [b]RueprtR[/b] on 12 Feb 2004 10:23 PM[/1]
    Private Sub optSelect_Click()
    ' place the insertion point at the beginning
    txtDisplay.SelStart = 0
    ' find the length of t...

  • Plz Help (Textbox)

    Posted by Dipti22 on 26 May 2005

    Hello all
    I am doing my project in asp.net . when a page gets loaded at that time i dont want a image control lie beside the taxtbox. but whenever a textbox got the focus , the image control...

  • Display Data in Textbox

    Posted by Col on 16 May 2005

    Hi, sorry but Newbie here,
    From an excel workbook I want to display the data from cell A1 & B1 next to each other in a textbox in my Visual Basic 6 project. The...

  • Textboxes - knowing when a scroll happens

    Posted by johnm on 27 Nov 2004

    I have hit a dead stop.

    (although while typing this I thought of a book and now about something which I guess will be called en_vscroll)
    I'm still asking though because this may not be the answe...