Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
May 18, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Quicker Textbox Additions

Consider these two examples of code that add a string to a textbox.

Example 1:

	Text1.text = Text1.text & MyString
	Text1.SelStart = Len(Text1.text)

Example 2:

	Text1.SelStart = Len(Text1.text)
	Text1.SelText = MyString

In the first example, you must copy the complete text from the textbox into a separate buffer to perform concatenation with the string MyString. You then need to copy the resulting string back to the textbox. This code requires allocating additional memory and performing two copy operations.

The code in the second example does not need an additional buffer. The concatenation of strings is executed inside the textbox buffer without transferring the text first outside the textbox and then back inside. This code is much faster and less memory-extensive. This second approach has an additional advantage of setting an insertion point directly at the end of the displayed text. In the first example, the insertion point is initially set to the beginning of the text, then transferred to the end, causing the control to flicker on the screen.

Krystyna Zyzdryn
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date