• Viernes 10 de Mayo de 2024, 22:37

Autor Tema:  Problema Con Line Input  (Leído 1071 veces)

Baliam

  • Nuevo Miembro
  • *
  • Mensajes: 9
    • Ver Perfil
Problema Con Line Input
« en: Domingo 30 de Marzo de 2008, 23:03 »
0
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?

Baliam

  • Nuevo Miembro
  • *
  • Mensajes: 9
    • Ver Perfil
Re: Problema Con Line Input
« Respuesta #1 en: Lunes 31 de Marzo de 2008, 00:06 »
0
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

Baliam

  • Nuevo Miembro
  • *
  • Mensajes: 9
    • Ver Perfil
Re: Problema Con Line Input
« Respuesta #2 en: Miércoles 2 de Abril de 2008, 10:11 »
0
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