You could just say:
Dim intClicked As Integer 'Public declaration
Behind the Button1 click event:
intClicked +=1
Label1.Text = "$" & intClicked
The above will be fine unless you close the form then 'intClicked' will be
set to zero.
-------------------------------------------------------------------
Another way is to hold the value in a text file
Do the same as above, but in the Form Closing Event put this:
Dim sw As New IO.StreamWriter("C:\Clicked.txt", False) ' Don't Append
sw.WriteLine(intClicked)
sw.Flush()
sw.Close
-----------------------------------
To read the above back into the program:
Dim sr As New IO.StreamReader("C:\Clicked.txt")
intClicked = CInt(sr.ReadLine)
sr.Close
Label1.Text = "$" & intClicked
-----------------------------------------------------------
Another way you could do it is store it in the registry (form closing event):
Imports Microsoft.Win32 ' Import used for registry
Dim reg As RegistryKey
reg = Registry.CurrentUser.OpenSubKey("Software\MyKey", True) 'True = Write
reg.SetValue("TimesClicled", intClicked)
reg.Close
-----------------------------------------------
To get the value from the registry:
Dim intTemp As Integer
Dim reg As RegistryKey
reg = Registry.CurrentUser.OpenSubKey("Software\MyKey", False) 'Read Only
intTemp = reg.GetValue("TimesClicled")
If (Not intTemp Is Nothing) Then
TimesClicled = intTemp
reg.Close
Label1.Text = "$" & TimesClicled
The above has been typed straight into here & not copied from the VS IDE.
I hope this has helped
"Rodger Arndt" wrote:
I have a program that is in need of keeping track of how many times the
command button has been clicked . I have a dollar amount totaled in a label,
every time the user clicks the command button represents 1 customers order.
I want to find the average per customer for daily sales. Is there a simple
way to just keep track of the number of times a command button has been
clicked?