I was wondering if i would be able have the saved items as a way to "login" to my program. in the first form (form1) i have a masked textbox and a button. you type your "pin" into the masked textbox and click the button to enter. i would like to check the masked textbox against listbox for a correct "pin". my code for that is:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Form4.ListBox1.Items.Contains(MaskedTextBox1.Text) Then
            Button3.Visible = True
            Button3.Enabled = True
            MsgBox("Your Pin was incorrect. Please try again.")
            Button3.Visible = False
            Button3.Enabled = False
            MaskedTextBox1.Text = ""
        End If
    End Sub

I cant check the masked textbox against the other form (form4) to have the "pins" in the listbox to work when saved with this cods:

Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs)
    Dim filePath As String = "C:\Myfile.txt"
    'use your path!
    If Not File.Exists(filePath) Then
        Dim fs As FileStream = File.Create(filePath)
    End If
    Using fs As New FileStream(filePath, FileMode.CreateNew, FileAccess.Write)
        Using sw As New StreamWriter(fs)
            For Each item As String In listBox1.Items
        End Using
    End Using
End Sub

any ideas on how to fix this?

Edited by Dani: Fixed formatting

5 Years
Discussion Span
Last Post by Gé48

Have a look at the thread searching then reading a line in a text file
there are some ideas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.