Advertisement
Haulien

Wait Procedure VB.NET

May 6th, 2011
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.09 KB | None | 0 0
  1. '' Put this where ever you want to wait for a certain amount of time
  2.  
  3.  
  4. '' amount of time you want to wait for
  5. Dim timeamount As Double = 50
  6.  
  7. '' the type of time you want.
  8. '' Possible types:   Milliseconds, Seconds, Minutes, Hours, Days, Months, Years
  9. '' if you dont put something in, its default in the procedure will be "Milliseconds"
  10.  
  11. Dim timeType as String = "Milliseconds"
  12.  
  13. '' code you put if you want to wait
  14.  
  15. Wait (timeamount, timeType)
  16.  
  17.  
  18. '' you can also change timeamount to a certain integer (eg. 40)
  19. '' you can also set timeType to a certain string, possible types are above.
  20. '' E.G.
  21. Wait (5000, "Milliseconds")  '' 5 seconds
  22.  
  23.  
  24.  
  25. '' You can also remove the timeType, but if done, it will default to milliseconds
  26. ''Example of that:
  27. Wait (5000)     '' wait for 5 seconds
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  36. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  37. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  38. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  39.  
  40.  
  41.  
  42.  
  43.  
  44. ''  procedure Wait
  45.  
  46. Public Sub Wait(ByVal amountOfTime As Double, Optional ByVal interval As String = "Milliseconds")
  47.         Const time As Double = 1.0# / (1400.0# * 60.0#)
  48.         Dim waitUntil As Date
  49.  
  50.         If interval = "Milliseconds" Or interval = "milliseconds" Then
  51.         '' sets milliseconds as an option
  52.             Now.AddMilliseconds(time)
  53.             waitUntil = Now.AddMilliseconds(time).AddMilliseconds(amountOfTime)
  54.         ElseIf interval = "Seconds" Or interval = "seconds" Then
  55.         '' sets seconds as an option
  56.             Now.AddSeconds(time)
  57.             waitUntil = Now.AddSeconds(time).AddSeconds(amountOfTime)
  58.         ElseIf interval = "Minutes" Or interval = "minutes" Then
  59.         '' sets minutes as an option
  60.             Now.AddMinutes(time)
  61.             waitUntil = Now.AddMinutes(time).AddMinutes(amountOfTime)
  62.         ElseIf interval = "Hours" Or interval = "hours" Then
  63.         '' sets hours as an option
  64.             Now.AddHours(time)
  65.             waitUntil = Now.AddHours(time).AddHours(amountOfTime)
  66.         ElseIf interval = "Days" Or interval = "days" Then
  67.         '' sets days as an option
  68.             Now.AddDays(time)
  69.             waitUntil = Now.AddDays(time).AddDays(amountOfTime)
  70.         ElseIf interval = "Months" Or interval = "months" Then
  71.         '' sets months as an option
  72.             Now.AddMonths(time)
  73.             waitUntil = Now.AddMonths(time).AddMonths(amountOfTime)
  74.         ElseIf interval = "Years" Or interval = "years" Then
  75.         '' sets years as an option
  76.             Now.AddYears(time)
  77.             waitUntil = Now.AddYears(time).AddYears(amountOfTime)
  78.         Else
  79.         '' defaults to milliseconds if inputted wrong
  80.             Now.AddMilliseconds(time)
  81.             waitUntil = Now.AddMilliseconds(time).AddMilliseconds(amountOfTime)
  82.         End If
  83.  
  84.     '' pauses until amount of time has passed
  85.         Do Until Now > waitUntil
  86.         '' allows windows messages and events to continue while pausing
  87.             Application.DoEvents()
  88.         Loop
  89.  
  90.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement