Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DISPLAYING AN INCREMENTING COUNT
 

DISPLAYING AN INCREMENTING COUNT

I want to display an incrementing count and have tried the following method

but with a problem.

My form has the following items:-

A label, lblCount and a textbox, txtCount to display an incrementing count.

A textbox, txtSet to select the count number, initially set to 5000.

A button, btnStart to start the procedure.

A button btnReset to reset on the completion of the procedure before

repeating the procedure.

A button btnCancel to exit the program.

The code for the form is as follows:-

********************************************************************

Public Class Form1

' Declare working variables

Dim i, s As Integer

____________________________________________________________________

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e _

As System.EventArgs) Handles MyBase.Load

Clear()

End Sub

____________________________________________________________________

Private Sub Clear()

' Set the Label states to Ready

lblCount.Text = "..."

txtCount.Text = "..."

btnReset.Text = "Reset"

btnStart.Text = "Start"

btnCancel.Text = "Cancel"

txtSet.Text = "5000"

End Sub

____________________________________________________________________

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e _

As System.EventArgs) Handles btnStart.Click

Clear()

s = txtSet.Text ' Set the cycle count

' Incrementing counter

For i = 1 To s

lblCount.Text = i ' Updates label at each count

txtCount.Text = i ' Updates textbox at each count

' When the program runs, I want lblLabel and txtCount

' to be updated and display each count, but they only show

'the final count, when, the process completes.

' How can I make them show an incrementing count?

Next

End Sub

____________________________________________________________________

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e _

As System.EventArgs) Handles btnReset.Click

Clear()

End Sub

____________________________________________________________________

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e _

As System.EventArgs) Handles btnCancel.Click

End

End Sub

End Class

____________________________________________________________________

********************************************************************

The procedure operation is as follows:-

The procedure is quite simple, it increments a counter to display the

counter setting via lblCount and txtCount.

The procedure is initiated by clicking the btnStart button.

At each step of the counter, lblCount and txtCount should display the incrementing counter setting but when the program is run they only show the final setting, when the process completes.

My question is, how can I get lblCount and txtCount to display an incrementing count of the counter?

Konker  Sunday, June 08, 2008 1:51 PM
Adding Application.DoEvents will give the form a chance to update the textbox and label to show the new value

For i = 1 To s

lblCount.Text = i ' Updates label at each count

txtCount.Text = i ' Updates textbox at each count

Application.DoEvents

' When the program runs, I want lblLabel and txtCount

' to be updated and display each count, but they only show

'the final count, when, the process completes.

' How can I make them show an incrementing count?

Next


Ken Tucker  Sunday, June 08, 2008 3:06 PM
Adding Application.DoEvents will give the form a chance to update the textbox and label to show the new value

For i = 1 To s

lblCount.Text = i ' Updates label at each count

txtCount.Text = i ' Updates textbox at each count

Application.DoEvents

' When the program runs, I want lblLabel and txtCount

' to be updated and display each count, but they only show

'the final count, when, the process completes.

' How can I make them show an incrementing count?

Next


Ken Tucker  Sunday, June 08, 2008 3:06 PM

Hello Ken

Your solution works. So simple when you know how.

Thanks for your help Ken

Konker

Konker  Sunday, June 08, 2008 5:10 PM

You can use google to search for other answers

Custom Search

More Threads

• bind property to selected row from datagridview
• How to initialize a value field?
• DBNull and string variable
• changing the connectionstring at runtime using an Open dialog box?
• DataGridView bounded to List of custom objects, what property attribute sets the datagridview column edit control
• Find a substring then display that string in a data grid view
• RowValidating and the origional values in a DGV row
• Treestyleview in a datagridview?
• DataGridViewImageCell
• Listview load from button click