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:

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

My.Settings.blnEnabled = False <-- This is called in the If condition above the If where u want to close.

Why call another if? since its obvious its false, call the me.close in the first if.
ur msg box merge those 2 make it 2 lined, first line bln status thingy 2nd line say demo reach thingy.

Code:

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)

        [B]If DateDiff(DateInterval.Day, My.Settings.dteStartDate, Now) > 12 Then
            My.Settings.blnEnabled = False
        MsgBox("blnEnabled = " & My.Settings.blnEnabled & vbCrLf & "The Demo has reached the end of it's trial.")
            Me.Close()
        End If[/B]

        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

still does not shut down the application
somehow it jumps out of the sub and moves to the next sub and runs it?
but the of'course there is an error since the dataset is not filled, it kinda jumps over that

This article has been dead for over six months. Start a new discussion instead.