Generate text from form

Asked

Viewed 244 times

2

inserir a descrição da imagem aqui

How can I make sure that when filling in the fields, they appear in the textbox by replacing the values "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
  • Post the code that you have or that gave trouble... Enough so we can help you

  • Have you tried the Getvalue method? 'https://msdn.microsoft.com/en-us/library/b05d59ty(v=vs.110). aspx? Cs-save-lang=1&Cs-lang=Vb#code-snippet-1'

  • It’s not a problem. I would like to know how to generate a form from the fields I would fill in and clicking "Generate Warning MP" would generate that text aside. Get it? Anyway, I added the current code, but I don’t think it’s going to be useful at all.

  • I’ll go see this Getvalue.

  • I didn’t quite understand... but I don’t think that’s it.

  • https://www.youtube.com/watch?v=MWsMqOE1o9E - This is what I wanted in the textbox and not in a word document.

Show 1 more comment

3 answers

3


It is not the most efficient method, but in my 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 the type {type} using {using}, be attentive.

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 click of the button.

  • Note: In the text you can have as many {name} (or other strings declared) as you want.

  • Obs2: I used Richtextbox because I found it better to work with this type of text than common Textbox.

  • http://prntscr.com/8nnu7o. Gave these errors. How can I resolve? / code: http://pastebin.com/RrTcdsJy

  • Right. I did that, but the errors continue. / edited code: http://pastebin.com/a10H3tkZ

  • Code as follows: http://pastebin.com/62E9eBkW

  • Any other mistake let me know.

  • I was here testing, but I noticed a small problem. We filled everything right, clicked on generating, so far so good, all right. But when we generate a second time, it doesn’t work.

  • Sorry I forgot the VR.Clear() underneath the Richtextbox1.Text = finalT

  • Now yes! That’s all, thank you for clearing up my doubts. I’m kind of learning VB.net

Show 4 more comments

0

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


Behold:

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 that’s it.

-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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.