Results 1 to 3 of 3

Thread: Saving Automatic Login Information [Advanced]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Saving Automatic Login Information [Advanced]

    I am trying to create a program that will have an option to automatically log you into a couple sites when you press the Start button. I have a separate form that you can open and put in your Username and Password for each site. There is a button that when you press it it is supposed to write to a file (C:\Desktop\Accounts.txt) you username and password so that when it is opened again you will not have to type them again. I had it working perfectly until I added some code so that it will remember if you had the check box checked and have the text box as read only (if check box is not checked). I even tried deleting the new code but it still will not write to the file, but it can read from it if I put the information in manually. Any help on what I did wrong would be great.

    Here is what I have so far:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Save As New SaveFileDialog()
            Dim myStreamWriter As System.IO.StreamWriter
    
            Try
                myStreamWriter = System.IO.File.AppendText("C:\Desktop\Accounts.txt")
                myStreamWriter.WriteLine(TextBox1.Text)
                myStreamWriter.WriteLine(TextBox2.Text)
                myStreamWriter.WriteLine(TextBox3.Text)
                myStreamWriter.WriteLine(TextBox4.Text)
                myStreamWriter.WriteLine(TextBox5.Text)
                myStreamWriter.WriteLine(TextBox6.Text)
                myStreamWriter.WriteLine(TextBox7.Text)
                myStreamWriter.WriteLine(TextBox8.Text)
                myStreamWriter.WriteLine(TextBox9.Text)
                myStreamWriter.WriteLine(TextBox10.Text)
                myStreamWriter.WriteLine(TextBox11.Text)
                myStreamWriter.WriteLine(TextBox12.Text)
                myStreamWriter.WriteLine(TextBox13.Text)
                myStreamWriter.WriteLine(TextBox14.Text)
                myStreamWriter.WriteLine(TextBox15.Text)
                myStreamWriter.WriteLine(TextBox16.Text)
                myStreamWriter.WriteLine(TextBox17.Text)
                myStreamWriter.WriteLine(TextBox18.Text)
                myStreamWriter.WriteLine(TextBox19.Text)
                myStreamWriter.WriteLine(TextBox20.Text)
                myStreamWriter.Flush()
            Catch ex As Exception
                ' Do Nothing
            End Try
        End Sub
    
        Private Sub accounts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim Open As New OpenFileDialog()
            Dim myStreamReader As System.IO.StreamReader
    
            Try
                myStreamReader = System.IO.File.OpenText("C:\Desktop\Accounts.txt")
                TextBox1.Text = myStreamReader.ReadLine()
                TextBox2.Text = myStreamReader.ReadLine()
                TextBox3.Text = myStreamReader.ReadLine()
                TextBox4.Text = myStreamReader.ReadLine()
                TextBox5.Text = myStreamReader.ReadLine()
                TextBox6.Text = myStreamReader.ReadLine()
                TextBox7.Text = myStreamReader.ReadLine()
                TextBox8.Text = myStreamReader.ReadLine()
                TextBox9.Text = myStreamReader.ReadLine()
                TextBox10.Text = myStreamReader.ReadLine()
                TextBox11.Text = myStreamReader.ReadLine()
                TextBox12.Text = myStreamReader.ReadLine()
                TextBox13.Text = myStreamReader.ReadLine()
                TextBox14.Text = myStreamReader.ReadLine()
                TextBox15.Text = myStreamReader.ReadLine()
                TextBox16.Text = myStreamReader.ReadLine()
                TextBox17.Text = myStreamReader.ReadLine()
                TextBox18.Text = myStreamReader.ReadLine()
                TextBox19.Text = myStreamReader.ReadLine()
                TextBox20.Text = myStreamReader.ReadLine()
            Catch ex As Exception
    
            End Try
            If TextBox1.Text = "" Then
                CheckBox1.Checked = False
            ElseIf TextBox1.Text > "" Then
                CheckBox1.Checked = True
            End If
            If TextBox3.Text = "" Then
                CheckBox2.Checked = False
            ElseIf TextBox3.Text > "" Then
                CheckBox2.Checked = True
            End If
            If TextBox5.Text = "" Then
                CheckBox3.Checked = False
            ElseIf TextBox5.Text > "" Then
                CheckBox3.Checked = True
            End If
            If TextBox7.Text = "" Then
                CheckBox4.Checked = False
            ElseIf TextBox7.Text > "" Then
                CheckBox4.Checked = True
            End If
            If TextBox9.Text = "" Then
                CheckBox5.Checked = False
            ElseIf TextBox9.Text > "" Then
                CheckBox5.Checked = True
            End If
            If TextBox11.Text = "" Then
                CheckBox6.Checked = False
            ElseIf TextBox11.Text > "" Then
                CheckBox6.Checked = True
            End If
            If TextBox13.Text = "" Then
                CheckBox7.Checked = False
            ElseIf TextBox13.Text > "" Then
                CheckBox7.Checked = True
            End If
            If TextBox15.Text = "" Then
                CheckBox8.Checked = False
            ElseIf TextBox15.Text > "" Then
                CheckBox8.Checked = True
            End If
            If TextBox17.Text = "" Then
                CheckBox9.Checked = False
            ElseIf TextBox17.Text > "" Then
                CheckBox9.Checked = True
            End If
            If TextBox19.Text = "" Then
                CheckBox10.Checked = False
            ElseIf TextBox19.Text > "" Then
                CheckBox10.Checked = True
            End If
        End Sub
    The code near the bottom is for the Check box and read only.
    Last edited by VisualBasic2008; Dec 6th, 2009 at 06:31 PM.

  2. #2
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    Re: Saving Automatic Login Information [Advanced]

    If you want to find out what's wrong, don't use try without even handling catching it. Try this for saving your data.

    Code:
    Dim SW As New IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\Accounts.txt", False)
            For i As Int32 = 1 To 20
                SW.WriteLine(Me.Controls("TextBox" & i.ToString).Text)
            Next
            SW.Close()
    You can do the same with your checkboxes.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Posts
    71

    Re: Saving Automatic Login Information [Advanced]

    I couldn't get it to work. I tried placing that code in the Button1 section but it didn't save anything. And I was also wondering how I could do it to read from the file when the Form is opened? So I could get the account info.

    Thanks though!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width