VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



IsExpired

by ignis (2 Submissions)
Category: Math/Dates
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

This code checks the difference between today and any expiration date. Using VB6 functions DateDiff and TimeValue it will evaluate the dates and tell you if we are past the expiration date or not. [Highly commented.]

Inputs
All you need to input is the expiration date and the expiration time. These can be in any format.
Assumes
This code can be used for many things, including shareware locks. You can set an expiration date (e.g. "30 days from today.") and check each day if it has expired. The simple boolean return will tell you if the shareware lock has expired or not.
Code Returns
This code returns True if we are past the expiration date. It returns False if it has not yet expired.

Rate IsExpired

Function IsExpired(ExpireDate As Date, ExpireTime As Date) As Boolean
 Dim lngDayDiff As Long
 Dim lngTimeDiff As Long
 
 ' Using DateDiff, a function unique to VB6, we check the
 ' difference between the current date (extracted from Now)
 ' and the expiration date.
 lngDayDiff = DateDiff("d", Now, ExpireDate)
 
 ' If the difference is a negative that means that we are
 ' past the expired date so of course it is expired.
 If lngDayDiff < 0 Then
  GoTo YesExpired
  
 ' If the difference is a zero that means we are ON the
 ' date of expiration. We check the time for a difference
 ' to determine if the time has expired.
 ElseIf lngDayDiff = 0 Then
 
  ' Get the time difference. Note that we use TimeValue(Now)
  ' instead of just Now because it will return the exact
  ' time, not the date/time.
  lngTimeDiff = DateDiff("n", TimeValue(Now), ExpireTime)
  
  ' If the time difference is a negative, we are past it so
  ' the date is expired.
  If lngTimeDiff <= 0 Then
   GoTo YesExpired
   
  ' Otherwise (if we are on the time, or before it) then
  ' we are not yet expired.
  Else
   GoTo NoExpired
  End If
 
 ' Otherwise (if we are on the date, or before it) then
 ' we are not yet expired.
 Else
  GoTo NoExpired
 End If
 
YesExpired:
 IsExpired = True
 Exit Function
NoExpired:
 IsExpired = False
 Exit Function
End Function

Download this snippet    Add to My Saved Code

IsExpired Comments

No comments have been posted about IsExpired. Why not be the first to post a comment about IsExpired.

Post your comment

Subject:
Message:
0/1000 characters