SoloCodigo
CLR: .Net / Mono / Boo / Otros CLR => VB .NET => Mensaje iniciado por: Baliam en Domingo 30 de Marzo de 2008, 23:03
-
Imports System.IO
Public Class Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim alg As Integer
Dim blo As Integer
alg = FreeFile()
blo = FreeFile()
If TextBox1.Text = "" Then
MsgBox("no registro su nombre")
TextBox1.Focus()
TextBox1.Text = ""
ElseIf TextBox2.Text = "" Then
MsgBox("Ponga una contraseña")
TextBox2.Focus()
Else
If OpenFileDialog1.FileName <> vbNullString Then
FileOpen(alg, "c:\not.txt", OpenMode.Append)
PrintLine(alg, TextBox1.Text)
FileClose(alg)
FileOpen(blo, "c:\carin.txt", OpenMode.Append)
PrintLine(blo, TextBox2.Text)
FileClose(blo)
MsgBox("Archivo almacenado")
Me.Hide()
Form2.Show()
End If
End If
End Sub
Hasta aquí voy bien
Quiero agregar el siguiente código para que no se repita la misma palabra en el texto not pero me origina un problema con las líneas vacías, ya que no se detiene hasta que revisa todas las líneas y me sigue mandando el mensaje de ya existe el usuario.
FileOpen(alg, "c:\not.txt", OpenMode.Input)
While Not EOF(alg)
slinea = LineInput(alg)
If slinea = slinea Then
slinea = LineInput(alg)
MsgBox("el usuario ya existe")
TextBox1.Focus()
TextBox1.Text = ""
End If
End While
FileClose(alg)
¿Existe alguna forma de ignorar las líneas que no contengan texto?
-
Más informacion ya encontre el error, y queda así
FileOpen(alg, "c:\not.txt", OpenMode.Input)
Dim slinea As String
While Not EOF(alg)
slinea = LineInput(alg)
If slinea = TextBox1.Text Then
MsgBox("el usuario ya existe")
TextBox1.Focus()
TextBox1.Text = ""
End If
End While
FileClose(alg)
End Sub
Ahora solo me falta meterlo en forma correcta ya que se abre dos veces el archivo not.txt
-
Bueno parece que en este foro nadie ayuda, todos vienen a buscar su tarea o no planteo bien mis preguntas, despues de mucho investigar y preguntar quedo asi:
Imports System.IO
Public Class Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim alg As Integer
Dim blo As Integer
alg = FreeFile()
blo = FreeFile()
Dim slinea As String
Dim z As Integer
z = 10
If OpenFileDialog1.FileName <> vbNullString Then
If TextBox1.Text = "" Then
MsgBox("no registro su nombre")
TextBox1.Focus()
TextBox1.ResetText()
ElseIf OpenFileDialog1.FileName <> vbNullString Then
FileOpen(alg, "c:\not.txt", OpenMode.Input)
While Not EOF(alg) And z = 10
slinea = LineInput(alg)
If slinea = TextBox1.Text Then
MsgBox("el usuario ya existe")
TextBox1.Focus()
TextBox1.Text = ""
z = 9
End If
End While
End If
End If
FileClose(alg)
z = z + 1
If z = 11 Then
If OpenFileDialog1.FileName <> vbNullString Then
FileOpen(alg, "c:\not.txt", OpenMode.Append)
PrintLine(alg, TextBox1.Text)
MsgBox("Usuario Registrado")
FileClose(alg)
Me.Hide()
Form2.Show()
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
Form1.Show()
End Sub
End Class