473,394 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

count click

11
I am trying to count the amount of times that a button is clicked and when it is clicked 10 times I want to bring a message box.

I have tried doing this with an if statement and a loop. with the if statement i can't seem to assign it to the button.

If count < 10 Then
Else
finalscore = score
MessageBox.Show("you final score is" & finalscore)
end if


can any1 help?
Mar 28 '07 #1
16 10540
ansumansahu
149 100+
I am trying to count the amount of times that a button is clicked and when it is clicked 10 times I want to bring a message box.

I have tried doing this with an if statement and a loop. with the if statement i can't seem to assign it to the button.

If count < 10 Then
Else
finalscore = score
MessageBox.Show("you final score is" & finalscore)
end if


can any1 help?
Hi,
Can we have a global variable and have that incremented each time the button is cliecked. Then when the value is 10 we can display a message that the final score is ...

thanks
ansuman sahu
Mar 28 '07 #2
I am trying to count the amount of times that a button is clicked and when it is clicked 10 times I want to bring a message box.

I have tried doing this with an if statement and a loop. with the if statement i can't seem to assign it to the button.

If count < 10 Then
Else
finalscore = score
MessageBox.Show("you final score is" & finalscore)
end if


can any1 help?
try out dis
if count=10 then
msgbox("score is"&finalscore)
else
count=count+1
end if
Mar 28 '07 #3
Lavs
16
Halu! :-) Create a project in vb. Add 1 button on the form, also add a textbox.
The textbox just show you the number of clicked you've done. If the number of clicked is equal to 10, a msgbox will be displayed, and the counter variable A is set back to its initial value which is zero(0).


Dim a As Integer

Private Sub Command1_Click()
a = a + 1
Text1.Text = a
If a = 10 Then
MsgBox "You click the button " & a & " times"
a = 0
Text1.Text = a
End If
End Sub

Private Sub Form_Load()
a = 0
End Sub
Mar 28 '07 #4
spud379
11
hi
thanks for all you help but still not quite what i want. the thing is im doing it for a assignment at uni. although most of the thing u been saying work does not quite fit in with the assignment.

I have emailed my tutor and he has emailed this back

Each time the user submits there answer to a question (ie clicks
on a button) treat this as one step or increment of a counter. Thus the
counter starts at 0 and the first time they click the button the
counter is incremented ie counter=counter + 1. If you increment the
counter inside the event handler ie the click event then every time the
user submits the answer the counter will increase by one.

If you add a selection statement within the event handler to disable
the button after 10 clicks (ie the counter reaches 10) and then print
the result you have the necessary control structures to complete the
test.


still not sure what to do with event handler. any help would be great thanks
Mar 28 '07 #5
SammyB
807 Expert 512MB
>not sure what to do with event handler
While you are designing your form, if you double-click on the button, VB creats an event handler that is called whenever you press the button. That is where you put your original If Then Else statement.

>the counter starts at 0
That is what you called "count". It should be dimmed as static at the top of the event handler. Normally variables are reinitialized each time a routine is called, but VB static variables are initialized to 0 the first time and kept from call to call.

>click the button the counter is incremented ie counter=counter + 1
You forgot to do this in your If

>disable the button after 10 clicks
This would replace the stuff in your else clause. Do you remember how to disable a button?
Mar 28 '07 #6
Killer42
8,435 Expert 8TB
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR
Mar 29 '07 #7
spud379
11
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR

I was not looking for the answers more to b pointed in the right direction and to understand some of the termonology.

I will be quoting this website in my biblography.
Apr 4 '07 #8
SammyB
807 Expert 512MB
I was not looking for the answers more to b pointed in the right direction and to understand some of the termonology.

I will be quoting this website in my biblography.
But, does it work? :D --Sam
Apr 4 '07 #9
vijaydiwakar
579 512MB
But, does it work? :D --Sam
:D nice Jo
Apr 4 '07 #10
spud379
11
But, does it work? :D --Sam
sorry mate have not tried it yet had a lot on. i try it 2day.
Apr 11 '07 #11
spud379
11
no its not working i tried count=count+1 and declairing as static. i must be doing something simple wrong i no that it is going into the if statement because it comes up with the messagebox after statement. and buttons disabled but not looping 10 times.
Apr 11 '07 #12
SammyB
807 Expert 512MB
no its not working i tried count=count+1 and declairing as static. i must be doing something simple wrong i no that it is going into the if statement because it comes up with the messagebox after statement. and buttons disabled but not looping 10 times.
So, show us the code.
Apr 11 '07 #13
Killer42
8,435 Expert 8TB
no its not working i tried count=count+1 and declairing as static. i must be doing something simple wrong i no that it is going into the if statement because it comes up with the messagebox after statement. and buttons disabled but not looping 10 times.
You do realise, I hope, that a variable declared within a procedure (a Sub or Function) only exists within that procedure? It may be static (remains between calls to the procedure, so doesn't get wiped each time) but it still cannot be accessed from outside of that procedure.

If you have declared a static variable within a procedure and then used the same name outside of the procedure, VB is probably just automatically creating a new variable for you, with the specified name.

You should always keep the "require explicit variable declaration" option turned on, to prevent this sort of problem.

On a simpler note, did you realise that in the code Lavs originally posted, a was set to zero just before displaying it?
Apr 11 '07 #14
SammyB
807 Expert 512MB
no its not working i tried count=count+1 and declairing as static. i must be doing something simple wrong i no that it is going into the if statement because it comes up with the messagebox after statement. and buttons disabled but not looping 10 times.
Make sure you followed Killer's suggestions and show us the code.
Apr 16 '07 #15
Exactly what i was looking for. Thanks dude.


Halu! :-) Create a project in vb. Add 1 button on the form, also add a textbox.
The textbox just show you the number of clicked you've done. If the number of clicked is equal to 10, a msgbox will be displayed, and the counter variable A is set back to its initial value which is zero(0).


Dim a As Integer

Private Sub Command1_Click()
a = a + 1
Text1.Text = a
If a = 10 Then
MsgBox "You click the button " & a & " times"
a = 0
Text1.Text = a
End If
End Sub

Private Sub Form_Load()
a = 0
End Sub
May 3 '07 #16
Thanks guys. I am new to this site, but I read some messages in this forum and it helped me complete my assignment. I knew the concepts of counting clicks, I just didn't know how to do it. Thanks! This forum helped a lot!
Sep 7 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alan Little | last post by:
I have a table with links, a log table to record clicks, and a vote table to record votes on the links. Is it possible to get the link data, the click count, vote count and vote total in one...
3
by: C. Homey | last post by:
I have an Access 2000 database (42,000+ records) for which I need a count of records by state (AL=320, AK=92, NY=1,932, etc). Obviously, I don't want to (and probably can't...) do the count...
1
by: James | last post by:
Access 2003, trying to count the number of records that meet a criteria. According to Help: "In the Database window, click Queries under Objects, and then click New on the database window...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
9
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
8
by: novus | last post by:
Hi, In ASP.net 2.0 I make a control which add the same controls dynamically. In the oninit event I add the controls to the controls collection. After that the loadviewstate event fills in the...
5
by: Marshallp24 | last post by:
Hi, I need to be able to display a count of records in a message box but with a criteria of the just ones where there is a yes in a certain field. so the message box will pop up saying something...
7
by: Chris | last post by:
I am trying to increase/decrease the value of $_SESSION by 1 after clicking on a link e.g index.php?gotoWk=nxtWk and index.php? gotoWk=lstWk. I'm sure you will get the drift if you look at the code...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.