Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi, I have some issues with a button click event, practically, when pressed, should paste a string (this string is a combination of"any word" and a value, that it's a result of the text from a combobox, this one will change every time the index change). I have two textbox, one where the final result it's pasted and another one where I can put the links. In summary when I press the button only this part of the code work but what's before not.
BASIC
<pre> For counter = 0 To tempArray.Length - 1
            tempArray(counter) = "~!" & "img(" & tempArray(counter) & ")"
        Next
        TextBox2.Lines = tempArray
        TextBox2.Text &= vbCrLf & "!~" & " ~~~"
    End Sub

The code before this
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tempArray As String()
        Dim cbname As String
        tempArray = TextBox1.Lines
        cbname = ComboBox1.Text.ToString
        TextBox2.Text = "~~~img" & "(" & cbname & ")" & vbCrLf


What I have tried:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tempArray As String()
        Dim cbname As String
        tempArray = TextBox1.Lines
        cbname = ComboBox1.Text.ToString
        TextBox2.Text = "~~~img" & "(" & cbname & ")" & vbCrLf // like to put this one single time at the start of the textbox2 before starting the cicle.
        For counter = 0 To tempArray.Length - 1
            tempArray(counter) = "~!" & "img(" & tempArray(counter) & ")"
        Next
        TextBox2.Lines = tempArray
        TextBox2.Text &= vbCrLf & "!~" & " ~~~"
    End Sub
Posted
Updated 30-Dec-21 11:12am
v4

1 solution

Sorry again guys, I think I found some solution, but if anyone have an optimal way to do it,I will mark that as solution, now my code work with these
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim tempArray As String()
        Dim cbname As String
        Dim cbname2 As String
        cbname = ComboBox1.Text.ToString
        cbname2 = "~~~img" & "(" & cbname & ")"
        tempArray = TextBox1.Lines
        For counter = 0 To tempArray.Length - 1
            If counter = 0 Then
                tempArray(0) = cbname2
            Else
                tempArray(counter) = "~!" & "img(" & tempArray(counter) & ")"
            End If
        Next
        TextBox2.Lines = tempArray
        TextBox2.Text &= vbCrLf & "!~" & " ~~~"
    End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900