Solved

vb.net - pressing button

Posted on 2011-03-15
9
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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