TheMac571
TheMac571

Reputation: 11

How would I add a string to textbox without clearing its contents VB6

How would I go about adding a string to this textbox without wiping it of it's contents?

For counter = 1 To 5 Step 1
If lengthofdeck(counter) >= length_user Then
  txtresult.Text = nameofdeck(counter)
  MsgBox ("Value: " & length_user & nameofdeck(counter) & " meets or exceeds the size requirement given")
End If
Next counter

Upvotes: 1

Views: 188

Answers (2)

Alex K.
Alex K.

Reputation: 175768

The best way to do this is:

txtresult.SelText = "New Text"

This efficiently appends new data to the TextBox without needing to reassign the whole string.

By default this inserts at the caret position, if you cannot guarantee this is at the end you make it so with:

txtresult.SelStart = Len(txtresult.Text)

Calling this also ensures that the most recently added text is visible and not bellow the current scroll position.

Upvotes: 2

puddinman13
puddinman13

Reputation: 1408

Change this line

txtresult.Text = nameofdeck(counter)

To this:

txtresult.Text = txtresult.Text & nameofdeck(counter)

This will allow you to append text.

See this article as well: Concatenate strings with vb6

Upvotes: 2

Related Questions