devxlogo

Quicker Textbox Additions

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist