Hello everyone,
I am not a professional at vb.net so help me out. I have made a small program and a want to add a serial control to it.... here is my code....

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "12345" And TextBox2.Text = "12345" And TextBox3.Text = "12345" And TextBox4.Text = "12345" And TextBox5.Text = "12345" And TextBox6.Text = "12345" Then
Form2.Show()
Me.Hide()
Else
MsgBox("Incorrect Serial Number")
End If

End Sub
End Class

Now, that code is all fine, but every time i open up my program, it asks me for a serial... how do i make it "if the correct serial is typed in once, then the serialization window will never pop up again"? It would also be a great help if the text boxes had a limit of 5 characters, and when the 5 characters are typed, it would go to the next text box....

hello
you may use "settings" to store settings
project properties> settings> valid Boolean user false

then in the load event

If Not My.Settings.valid Then
            'ask for the serial
        End If

as for the auto focus after 5 chars i think this will do

Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged, TextBox5.TextChanged
        Dim _textBox As TextBox = sender
        If _textBox.TextLength = 5 Then
            Dim index = Val(_textBox.Name(7)) + 1
            Me.Controls.Find("TextBox" & index.ToString, True)(0).Focus()
        End If
    End Sub

be careful when renaming the textboxes .. "7" will likely have to be changed and also "TextBox"

thanks for the code, but I'm a bit confused.... i really don't know what goes where, so ill send you my project.... Please help me!!!

hello nv136,

Based on my understanding you are trying to do following -
create an activation window for a software, and once activated, never show the message again...


if this is correct, then a simple solution can be -

1.create a text file which will store a value (could be "True", "False", "1", "0" etc. and when your program starts, the program checks the value in the text file
2. Initially the value in the file should be "False" or "0" and once the user enters a correct serial number the value in file changes to "True" or "1"
3. Every time user starts your program, the program first checks the value in the text file and if value is "False" or "0", it prompts for the activation key. If text file has "True" or "1" , it doesnot ask for key and go to the required page.

now few things -
1. this is a very elementary method and users can change values in the text file easily.
2. you can code the "True" , "False" into something else, that users cannot decode.
3. better you can store these values in "Windows registry" somewhere instead of text file, for which you would need to understand how "windows registry" can be accessed etc.

hope this helps.

Pankaj

so, what exactly do i write in the text file?

well, first of all understand that text file will be used as a file which contains information if user has activated the software.
u will need to access the text file from your VB program to check if software is activated, so that the form asking for key doesnot reappear.

1. initially write "false" in your text file
2. when user will start the program, program will look in text file, if its false it will show form which asks for activation key
3. if the key entered is correct, replace "false" with "true" in the text file and show the required form
4. next time user will start the program, the program will again look into text file and will find "true", so it should not ask for activation key.

so first of all you need to find a way to read and write into a text file from VB...google it and u'll find that easily..

Pankaj

hello
you may use "settings" to store settings
project properties> settings> valid Boolean user false

then in the load event

If Not My.Settings.valid Then
            'ask for the serial
        End If

Just simplifying the above quote.

From the vb.net top Menu, click Project and select yourApplication Properties...
Locate the Settings Tab and add "valid" as your setting Name.
Change the Type to Boolean and set the Value to "False".

The following code should explain it's self.

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Settings.valid = True Then '// check if valid has been set to True
            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.valid = False Then
            If TextBox1.Text = "12345" And TextBox2.Text = "12345" And TextBox3.Text = "12345" _
                And TextBox4.Text = "12345" And TextBox5.Text = "12345" And TextBox6.Text = "12345" Then
                My.Settings.valid = True '// set the valid Setting to True
                My.Settings.Save() '// save your Settings
                Form2.Show()
                Me.Close()
            Else
                MsgBox("Incorrect Serial Number")
            End If
        Else
            Form2.Show()
            Me.Close()
        End If
    End Sub
End Class

The only way I could get the code to work was to set the Shutdown Mode to "When last form closes" in the Application Tab of the Project's Properties.

thanks, HUGE help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.