again with a question, the program works as it should, it generates random names depending on the restrictions that one puts on it, what I do not want is for it to delete the texts of the textboxes that I write, I put the example in images for better understanding because I can't get the last 2 textboxes to not be deleted
attached code
Public Class Form1
Dim texto1, texto2, texto3 As String
Dim caracter As Char
Dim tam As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
texto1 = TextBox1.Text
texto2 = TextBox2.Text
texto3 = TextBox3.Text
Label1.Text = texto1
Label2.Text = texto2
Label3.Text = texto3
tam = Len(texto1)
For i = 1 To tam
caracter = Mid(texto1, i, 1)
caracter = Mid(texto2, i, 1)
caracter = Mid(texto3, i, 1)
TextBox2.Text = texto2.Substring(0, 1)
TextBox3.Text = texto3.Substring(0, 1)
Label1.Text = TextBox1.Text & TextBox2.Text & "." & TextBox3.Text
Next
For i = 1 To tam
caracter = Mid(texto1, i, 1)
caracter = Mid(texto2, i, 1)
caracter = Mid(texto3, i, 1)
TextBox2.Text = texto2.Substring(0, 3)
TextBox3.Text = texto3.Substring(texto3.Length - 3, 3)
Label2.Text = TextBox1.Text & TextBox2.Text & TextBox3.Text
Next
For i = 1 To tam
caracter = Mid(texto1, i, 1)
caracter = Mid(texto2, i, 1)
caracter = Mid(texto3, i, 1)
TextBox2.Text = texto2.Substring(0, 1)
TextBox3.Text = texto3.Substring(texto3.Length - 1, 1)
Label3.Text = TextBox1.Text & "." & TextBox2.Text & TextBox3.Text
Next
End Sub
End Class
Every time you assign the property
Text
of aTextBox
, you are changing the value. That is, it does not delete itself, you are changing it yourself when you make an assignment like:You can use other variables to store and manipulate the value, if you need them, and never assign a value to
TextBox2.Text
niTextBox3.Text
, that way what the user has put in those fields will be respected.Edition
Taking an extra look at your code, I realize that most of it is redundant or just does operations that have no effect on the result, so it could boil down to this:
Variables
textoX
aren't actually absolutely necessary, but I left them out because they make the code more readable.