simple counter question

  • Thread starter Thread starter Rodger Arndt
  • Start date Start date
R

Rodger Arndt

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?
 
Is this a program you have created ? Or do you want to keep track of clicks
on a third party software?
 
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
 
no, all within the program, either a do/while or a for next. whatever. I am
displaying the average on the form in a label right under the total sales
for the day.
 
this is what I was looking for.

intClicked +=1
Label1.Text = "$" & intClicked


Thank you
 
What if the user quit your program before end of the day or break out then
how do you get back your intClicked value?

chanmm
 
chanmmn,

See my previous post on this thread & it will tell you how to do it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top