I do apologise for the simplicity of this post, but I am seeking help in something I have not encountered before.

While I have my splash screen and program humming perfectly, I am trying to run a date check while starting and exit the program if it is too old. In simple terms:

  1. Run the splash screen
  2. Check todays date
  3. If todays date is later than a given date, exit the program prior to my Form1 becoming visible.

Can anyone help with this please?

4 Years
Discussion Span
Last Post by DM Galaxy
If DateDiff(DateInterval.Day, CDate("2013-10-01"), Now) > 10 Then
    MsgBox("program too old")
End If

If you want to save a date, for example, the date the program was first run, you could create an application level settings variable and give it a known initial value like 2013-01-01 then do

If My.Settings.FirstRun = Cdate("2000-01-01") Then
    My.Settings.FirstRun = Now
End If

If DateDiff(DateInterval.Day, My.Settings.FirstRun, Now) > 10 Then
    MsgBox("program too old")
End If

this is similar to trial version product:
you can do this with the settings (create settings)
This feature will store data in the application itself
Secondly, You can also use the registry for this

as reverend jim told you that you can do or you can do this too:
(your application name: MyPro; trial version for: 30 days) change the day to 1 (according to your help needed)
Create a Function: (type below Public Class Form1)

Private Function HandleRegistry() As Boolean
        Dim firstRunDate As Date
        firstRunDate = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "FirstRun", Nothing)
        If firstRunDate = Nothing Then
            firstRunDate = Now
            My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "FirstRun", firstRunDate)
        ElseIf (Now - firstRunDate).Days > 30 Then
            Return False
        End If
        Return True
End Function

now called this handled report to your application
type code in the form1_loadevent

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim result As Boolean = HandleRegistry()
        If result = False Then 'something went wrong
            MsgBox("Trial expired")
            MsgBox("Trial version")
        End If
End Sub

what we did:?
We just create a registry entry value and that registry entry value will be stored on your FirstRun. and the data will be save
so that whenever you opened the application, then your application will count days left. if you have passed all trial days then your application will just opened and tell popup with msgbox (trial expired) and then application will end...

still having doubt inform me

Edited by DM Galaxy: minor changes

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.