[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

vb.net - pressing button

Posted on 2011-03-15
9
Medium Priority
?
396 Views
Last Modified: 2012-05-11
hello there,
I would like to create a little function that can help me with pressing button many times..
for example if I press a button more than 5 times in 30 seconds to tell me "you cant press the button more than X times in less than X seconds"
how can I do something like that?
0
Comment
Question by:XK8ER
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35143993
Hi,

You can use 2 variables to control that,

In your Form Declarations

Public intPressedTimes as Integer = 0
Public dteStartTime as Datetime

In you button  CLICK  event, add this code

If intPressedTimes = 0 Then 'is the first time the button is pressed or is another cycle
    dteStartTime = Datetime.Now  'Get the start Time of the first time the buttons was pressed
End if

If intPressedTimes > 5 Then 'Validates the Maximun Number of Time
  If (Datetime.Now - dteStartTime).TotalSeconds > 30 Then 'Validate the maximun number of seconds
      Msgbox("you cannot press the button more than 5 times in less than 30 seconds")
      Exit sub
  End if
Else
   'Finally reset the variable if the Seconds are more than 30 and the Pressed Times is not reach the   Maximum
   If (Datetime.Now - dteStartTime).TotalSeconds > 30 Then
      intPressedTimes = 0
   End if
End If

Hope that helps
0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 2000 total points
ID: 35144001
Sorry one thing was missed, increment the intPressedTimes variable, here is the code of the CLICK event fixed

If intPressedTimes = 0 Then 'is the first time the button is pressed or is another cycle
    dteStartTime = Datetime.Now  'Get the start Time of the first time the buttons was pressed
End if

intPressedTimes += 1

If intPressedTimes > 5 Then 'Validates the Maximun Number of Time
  If (Datetime.Now - dteStartTime).TotalSeconds > 30 Then 'Validate the maximun number of seconds
      Msgbox("you cannot press the button more than 5 times in less than 30 seconds")
      Exit sub
  End if
Else
   'Finally reset the variable if the Seconds are more than 30 and the Pressed Times is not reach the   Maximum
   If (Datetime.Now - dteStartTime).TotalSeconds > 30 Then
      intPressedTimes = 0
   End if
End If
0
 
LVL 1

Author Comment

by:XK8ER
ID: 35144010
its not really showing the msgbox..
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:XK8ER
ID: 35144030
okay its supposed to be like this


>>If (DateTime.Now - dteStartTime).TotalSeconds < 30 Then 'Validate the maximun number of seconds
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35144076
Ok you are right, sorry for the wrong symbol

With that change, it was what you were looking for?
0
 
LVL 1

Author Comment

by:XK8ER
ID: 35144082
well for example if i set it to 30 seconds.. and I click 10 times every 45 seconds then click 8 times within 5 seconds it wont show the msgbox..
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35144106
ok, do you want that the button can be pressend 5 times every 30 seconds? this will mean that in a minute, you can pressed 4 times from 1 to the second number 30 and then other 4 times from second 31 to 60, and only if you try to press more than 5 times each 30 seconds cycle the messages shows up?

Or do you want that if the button was pressed 4 times before 30 seconds, and then is pressed 2 more times since 30 seconds has pass already, it will show the message?
0
 
LVL 1

Author Comment

by:XK8ER
ID: 35144122
ok got it.. had to change this too

>>If (DateTime.Now - dteStartTime).TotalSeconds <= 30 Then
0
 
LVL 13

Expert Comment

by:gamarrojgq
ID: 35144150
ok, that works the way you want it ?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question