Form refuses to close

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I have a method where I am making a trial period.
When the date has exceded its trialperiod the program will not close.

The code looks like this:

VB.NET:
Public Sub DemoRestrict()

        If My.Settings.dteStartDate = Nothing Then
            My.Settings.dteStartDate = Now
        End If
        If My.Settings.intTime = Nothing Then
            My.Settings.intTime = intTime
        End If
        If My.Settings.blnEnabled = Nothing Then
            My.Settings.blnEnabled = blnEnabled
        End If
        My.Application.SaveMySettingsOnExit = True

        '*******************************************************************************


        MsgBox("blnEnabled = " & My.Settings.blnEnabled)
        MsgBox("Startdato = " & My.Settings.dteStartDate)

        If DateDiff(DateInterval.Day, My.Settings.dteStartDate, Now) > 12 Then
            My.Settings.blnEnabled = False
        End If

        MsgBox("blnEnabled = " & My.Settings.blnEnabled)

       If My.Settings.blnEnabled = False Then
            MsgBox("The Demo has reached the end of it's trial.")
            Me.Close()

        End If

        My.Settings.dteLastStart = Now
        If My.Settings.blnFirstTime = True Then
            My.Settings.blnFirstTime = False
        End If
        'Saves variable settings
        My.Settings.Save()
        My.Settings.lngTimeLeft = 12 - (DateDiff(DateInterval.Day, My.Settings.dteStartDate, Now))
        MsgBox("This is a 12 days Trial Demo." & vbCrLf & "You have " & CStr(My.Settings.lngTimeLeft) & " days left.", MsgBoxStyle.OkOnly, "Demo Trial")
        My.Settings.Save()


    End Sub

Why does the form not close? is just runs to the next method in the load sequence
 
Don't even create the main form if you don't want to show it. You should handle the Startup event of the application and check the date there. If it's passed then set e.Cancel to True and the app will exit without ever creating a main form.
 
Back
Top