updating label

mattgoody

New member
Joined
Oct 11, 2006
Messages
2
Programming Experience
Beginner
im writing a program that downlaods poker hand historys for personal use, anyway, i havea label that iw ant to update me with what hand number the program is working on at the moment. anyway, the label does not update. it does not even output a number until the msg box comes up telling me the program is finished running. im going to be looking through a lot of hands so i want to be able to know progress. any ideas why the label wont update
VB.NET:
[FONT=Arial]    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hand1, hand2 As String
        Dim hh, hn As Integer

        Dim wc As New WebClient
        Dim FILE_NAME As String = "C:\findch.txt"
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME, False)
        CompTime = Environment.TickCount
        hn = 1118519943
        hh = 0
        'Do While hn < 1210000000
        For hn = 1118529943 To 1118529946

            'updateHN(hn)
            Label1.Text = hn

            Dim sr As New StreamReader(wc.OpenRead("http://www.pokernetwork.co.uk/games/handhistory/?gameCode=P4&handNumber=" & hn))
            hand1 = StripHTML(sr.ReadToEnd)

            hand2 = hand1.IndexOf("rake", 0, hand1.Length)


            If hand2 <> -1 Then

                objWriter.WriteLine(hn)
                hn = hn + 1
            End If



        Next
        objWriter.Close()
        MsgBox("Done")

    End Sub
[/FONT]

ive also tried using a textbox to no avail

any help would be greatly appreciated

-Matt
 
i'm not 100% sure what's happening here, but i've noticed that you've got the code in a button's click event, perhaps you could put it in a timer's tick event, thus allowing the code to execute on it's own periodically
 
VB.NET:
If hand2 <> -1 Then

                objWriter.WriteLine(hn)
                hn = hn + 1
            End If


At a guess it's because this line of code isn't executing. It's the only part that updates the label. So stick a breakpoint in there somewhere and see if the program breaks, if it doesn't you know that the code in that if block isn't being run. Then you can start thinking about why.
 
mattgoody, try Application.Doevents right after the label.text is set, this will allow application window to process OS messages like painting the label etc while still in loop.

Edit: note that Application.DoEvents will slow down the processing of the loop. The other option is running the work in a separate thread, see my reply here about using the BackGroundWorker for easy multithread job with progress.
 
thank you JohnH. putting the Application.DoEvents worked great, and i dont think it significantly slows the program down enough to be a bother.
Juggalo- i tried using a timer, but i couldnt figure out hwo to call the function, or pull the variable frmo one sub to the timer sub. if there is an easy thing im overlooking, id like to know what it is :)
vis- actually that part of the code is an error, i was using a while loop, but changed to a for so i dont need the hn = hn + 1 anymore, and the other part is writing to a text file.

thanx everyone!
 
add a timer to your form then in the code window add this ", Timer1.Tick" to the end of the "handles clause" so it'll look like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Timer1.Tick

also be sure to start the timer either in the design editor or in the form's load event (in code)
 
Back
Top