9 Replies - 455 Views - Last Post: 05 February 2013 - 06:59 AM Rate Topic: -----

#1 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

10 Use Trial

Posted 04 February 2013 - 10:54 AM

Hi all. I am trying to put a 15 uses trial on my application.
The following is my code I am using...:
Private Sub frmmain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label3.Text = My.Settings.Trial
        If My.Settings.Trial = "0" = True Then
            Label3.Text = "This Trial has expired. Please Purchase Product Key"
            Button1.Enabled = False
        End If
        If My.Settings.TrialD = "Yes" = True Then
            Form2.Show()
            Me.Close()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If My.Settings.Trial = "0" = True Then
            Button1.Enabled = False
        Else
            My.Settings.Trial -= 1
            My.Settings.Save()
            Form2.Show()
        End If
        Label3.Text = My.Settings.Trial
        Me.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If TextBox1.Text = "A-Number" = True Then
            My.Settings.TrialD = "Yes"
            Form2.Show()
            Me.Close()
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        PurchaseKey.Show()
        PurchaseKey.Opacity = 1
        PurchaseKey.Height.Equals(Me.Height)
        PurchaseKey.Width.Equals(Me.Width)
        PurchaseKey.SetDesktopLocation(Me.DesktopLocation.X(), Me.DesktopLocation.Y())
        Me.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()

    End Sub



But when I debug it, and enter the Product Key to test if it activates, it does not seem to do so. When I stop Debugging it, the activation screen still comes up, when it is not supposed to. Can Anyone help me please?

Is This A Good Question/Topic? 0
  • +

Replies To: 10 Use Trial

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,879
  • Joined: 12-December 12

Re: 10 Use Trial

Posted 04 February 2013 - 11:06 AM

Don't do this:
If My.Settings.Trial = "0" = True Then

it is a poor practice and can yield odd results. I presume you intend:
If My.Settings.Trial = "0" Then

Correct these lines first.

Also, you can store an Integer in Settings, which will obviously make it easier to increment and check its value/size.

This post has been edited by andrewsw: 04 February 2013 - 11:07 AM

Was This Post Helpful? 0
  • +
  • -

#3 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: 10 Use Trial

Posted 04 February 2013 - 11:08 AM

View Postandrewsw, on 04 February 2013 - 11:06 AM, said:

Don't do this:
If My.Settings.Trial = "0" = True Then

it is a poor practice and can yield odd results. I presume you intend:
If My.Settings.Trial = "0" Then

Correct these lines first.

Also, you can store an Integer in settings, which will obviously make it easier to increment and check its value/size.


I have corrected the part by removing the "True" and debugged the program again, but it still asks to register again...

How can I use and Integer?
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,879
  • Joined: 12-December 12

Re: 10 Use Trial

Posted 04 February 2013 - 11:11 AM

You are also attempting to subtract from Trial, even though it is a string:

My.Settings.Trial -= 1

I'm surprised you don't receive errors, but perhaps it bails before it gets to this line.

Quote

How can I use and Integer?

Go to the Project menu, YourProject.. Properties, then Settings. Create a Setting, chose Integer, Scope of User, and an initial value of 0.
Was This Post Helpful? 0
  • +
  • -

#5 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: 10 Use Trial

Posted 04 February 2013 - 11:13 AM

View Postandrewsw, on 04 February 2013 - 11:11 AM, said:

You are also attempting to subtract from Trial, even though it is a string:

My.Settings.Trial -= 1

I'm surprised you don't receive errors, but perhaps it bails before it gets to this line.

Quote

How can I use and Integer?

Go to the Project menu, YourProject.. Properties, then Settings. Create a Setting, chose Integer, Scope of User, and an initial value of 0.


Should I remove that My.Settings.Trial -= 1 ?
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,879
  • Joined: 12-December 12

Re: 10 Use Trial

Posted 04 February 2013 - 11:27 AM

View PostMafiaAndre, on 04 February 2013 - 11:13 AM, said:

Should I remove that My.Settings.Trial -= 1 ?

If you convert the Setting to an Integer then you won't need to.
Was This Post Helpful? 0
  • +
  • -

#7 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: 10 Use Trial

Posted 04 February 2013 - 12:02 PM

View Postandrewsw, on 04 February 2013 - 11:27 AM, said:

View PostMafiaAndre, on 04 February 2013 - 11:13 AM, said:

Should I remove that My.Settings.Trial -= 1 ?

If you convert the Setting to an Integer then you won't need to.



okay. how do i continue now? because it is still doing what it did at the start. not activating and asking to be activated the whole time?
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,879
  • Joined: 12-December 12

Re: 10 Use Trial

Posted 04 February 2013 - 12:13 PM

Add this line to the Form_FormClosed event to persist the Settings each time:

My.Settings.Save()

It needs to run on closing the form otherwise it forgets to save.

Re-start VS (or re-boot the computer) and check that your Setting is still available.

Post the code that you now have.
Was This Post Helpful? 0
  • +
  • -

#9 MafiaAndre  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 18-January 13

Re: 10 Use Trial

Posted 05 February 2013 - 06:48 AM

View Postandrewsw, on 04 February 2013 - 12:13 PM, said:

Add this line to the Form_FormClosed event to persist the Settings each time:

My.Settings.Save()

It needs to run on closing the form otherwise it forgets to save.

Re-start VS (or re-boot the computer) and check that your Setting is still available.

Post the code that you now have.


Current Code: (P.S: I am not sure if I did the Form_FormClosed Event part)

Public Class Register

    Private Sub Register_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs) Handles MyBase.FormClosed
        My.Settings.Save()

    End Sub

    Private Sub Register_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label2.Text = My.Settings.Trial2
        If My.Settings.Trial2 = "0" Then
            Label2.Text = "This Trial has expired. "
            Button1.Enabled = False

            If My.Settings.TrialG = "Yes" Then
                frmMain.Show()
                Me.Close()
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If My.Settings.Trial2 = "0" Then
            Button1.Enabled = False
        Else
            My.Settings.Save()
            frmMain.Show()
        End If
        Label3.Text = My.Settings.Trial2
        Me.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If TextBox1.Text = "000-000-000" Then
            My.Settings.TrialG = "Yes"
            frmMain.Show()
            Me.Close()
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        PurchaseKey.Show()
        PurchaseKey.Opacity = 1
        PurchaseKey.Height.Equals(Me.Height)
        PurchaseKey.Width.Equals(Me.Width)
        PurchaseKey.SetDesktopLocation(Me.DesktopLocation.X(), Me.DesktopLocation.Y())
        Me.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()

    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#10 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,879
  • Joined: 12-December 12

Re: 10 Use Trial

Posted 05 February 2013 - 06:59 AM

If you changed the setting to be an integer then you should no longer be comparing it as text:

If My.Settings.Trial2 = "0" Then
'should be
If My.Settings.Trial2 = 0 Then


BTW I don't know if this correction would mean that your code works; I haven't run or examined it in detail.

Learn some basic debugging techniques, there are tutorials at DIC I believe.

This post has been edited by andrewsw: 05 February 2013 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1