Generate text from form

2

HowcanIdothatbyfillinginthefields,theyappearinthetextboxbyreplacingthevalues"USER NAME", "WARNING TYPE" and "TOPIC LINK"?

    Private Sub bemvindo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bemvindo.Click

    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        Application.ExitThread()
    End Sub

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub

    Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
        Form1.Show()
        Me.Hide()
    End Sub

    Private Sub body_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles body.Paint

    End Sub
End Class
    
asked by anonymous 04.10.2015 / 16:13

3 answers

3

It is not the most efficient method, but in my point of view it is one of the best.

 Dim GeralTF As String = ""
 Dim V As New List(Of System.Text.RegularExpressions.Regex)
 Dim VR As New List(Of String)
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        GeralTF = RichTextBox1.Text

        'O que substituir
        V.Add(New System.Text.RegularExpressions.Regex("{nome}"))
        V.Add(New System.Text.RegularExpressions.Regex("{tipo}"))
        V.Add(New System.Text.RegularExpressions.Regex("{usando}"))
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Substituir pelo que (em ordem)
        VR.Add(TextBox1.Text) 'Text Box de    nome
        VR.Add(TextBox2.Text) 'Text Box de    tipo
        VR.Add(TextBox3.Text) 'Text Box de    usando


        Dim finalT As String = GeralTF
        Dim i As Int16 = 0
        For Each regexi As System.Text.RegularExpressions.Regex In V
            finalT = regexi.Replace(finalT, VR(i))
            i += 1
        Next
        RichTextBox1.Text = finalT
        VR.Clear()
    End Sub
  

Hello {name},

     

I would like to test the program and bla bla bla of type {type} using   {using}, watch out.

In Form Load adds new Regex to a list, each Regex is a String that will have in the text and should be replaced by another one in which it will be added to another list IN THE SAME ORDER in the event of the button click.

    
04.10.2015 / 18:19
0

Now, you can also use the .Replace ("Old String" or Integer, "New String" or Integer) method

See:

Private Sub btnGerarMP_Click(sender As Object, e As EventArgs) Handles btnGerarMP.Click
Dim strMP as String
strMP = txtMP.text.Replace("NOME DO USUÁRIO", txtNomeUsuario.text).Replace("TIPO DE ADVERTÊNCIA", txtAdvertencia.text).Replace("LINK DO TÓPICO", txtTopico.text)

I hope this is it.

    
01.11.2015 / 17:40
-1
dim usuario as string = txtUsuario.Text
dim advertencia as string = txtAdvertencia.Text
dim topico as string = txtTopico.Text
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    txtMensagem.Text = "Olá " & usuario & " ," 'Escreva aqui toda sua mensagem, e quando precisar das informações digitadas, use a string.
End Sub
    
08.02.2016 / 03:23