String concatenation into a textbox

maxhavoc

Registered User.
Local time
Today, 16:30
Joined
Dec 12, 2005
Messages
14
This really is more of a VB than an Access question, but I need it answered, and I don't know a good VB forum so....

I have a text box that I'm trying to add text to, I have a loop, and every time through the loop it's supposed to concatenate new text into the text box by appending it to the end. I can't seem to be able to find a way to do this. I can't use the <&> operator, and VB doesn't have a <+=> operator (I wish I could do this in C/C++, but oh well). Any ideas? Or do I have to set the existing text to a string, concatenate the new text onto that, and then set it to the textbox?
 
maxhavoc said:
This really is more of a VB than an Access question, but I need it answered, and I don't know a good VB forum so....

I have a text box that I'm trying to add text to, I have a loop, and every time through the loop it's supposed to concatenate new text into the text box by appending it to the end. I can't seem to be able to find a way to do this. I can't use the <&> operator, and VB doesn't have a <+=> operator (I wish I could do this in C/C++, but oh well). Any ideas? Or do I have to set the existing text to a string, concatenate the new text onto that, and then set it to the textbox?

Why can't you use the & operator? Is this in VB6 or VB.Net?
 
It should work with the «&».
MyTextBox = MyTextBox & " This is the end!"
If it still doesn't work, write down a piece of your code so that we can take a better look at it.
 
Here is a method without using the & operator.

Code:
Sub addNewText()
    Dim sTextToAdd      As String
    Dim sCurrentText    As String
    Dim sNewText        As String
    Dim lTextToAdd      As Long
    Dim lCurrentText    As Long
    
    sTextToAdd = Nz(txtTextToAdd.Value)
    sCurrentText = Nz(txtCurrentText.Value)
    
    If sTextToAdd <> "" Then
        lTextToAdd = Len(sTextToAdd)
        lCurrentText = Len(sCurrentText)
        sNewText = Space(lCurrentText + lTextToAdd)
        Mid$(sNewText, 1, lCurrentText) = sCurrentText
        Mid$(sNewText, lCurrentText + 1, lTextToAdd) = sTextToAdd
        txtTextToAdd.Value = ""
        txtCurrentText.Value = sNewText
    End If

End Sub
 

Users who are viewing this thread

Back
Top Bottom