Posted By

brandonio21 on 07/29/10


Tagged

VBNet


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nelsonamaya


Vb.net Check for 30 day trial


 / Published in: VB.NET
 

URL: http://brandonsoft.com

Created by Brandon

  1. Public Class Form1
  2. Public day As String 'Creates all the variables
  3. Public month As String
  4. Public year As String
  5.  
  6. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7. day = My.Computer.Clock.LocalTime.Day 'Declares day,month,and year as the current Day Month and Year
  8. month = My.Computer.Clock.LocalTime.Month
  9. year = My.Computer.Clock.LocalTime.Year
  10. If My.Settings.checked = False Then 'Checks if this is the first time the program has run, if it is, save the current date into a setting.
  11. My.Settings.day = day
  12. My.Settings.month = month
  13. My.Settings.year = year
  14. My.Settings.checked = True
  15. Else
  16. Try
  17. If year = My.Settings.year Then 'If the year is the same, check the month
  18. If month = My.Settings.month Then
  19.  
  20. Else
  21. 'If the month is not the same then check if the day is
  22. If month = My.Settings.month + 1 Then
  23. If day = My.Settings.day Then
  24. msgbox("trial expired!")
  25. Else 'If the day is bigger than the current day, the trial is expired
  26. If day > My.Settings.day Then
  27. MsgBox("Trial expired!")
  28. End If
  29. End If
  30. Else
  31. If month = My.Settings.month + 2 Then
  32. msgbox("Trial Expired!")
  33. Else
  34. If month <> My.Settings.month + 1 Then
  35. MsgBox("Trial Expired!")
  36. End If
  37. End If
  38. End If
  39. End If
  40. Else
  41. 'If the year is different, the trial has expired
  42. MsgBox("Trial Expired!")
  43. End If
  44. 'If there is an error, make a msgbox containing the error
  45. Catch ex As Exception
  46. MsgBox(ex.Message)
  47. End Try
  48. End If
  49.  
  50. End Sub
  51. End Class

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: breakskater on August 28, 2010

This code could be reduced to a couple lines of code using the TimeSpan class.. This code is written way too complicated for handling this simple task.

You need to login to post a comment.