Results 1 to 4 of 4

Thread: Weird error with my code???

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    5

    Question Weird error with my code???

    Here is a PIECE of my code, not the whole thing
    Code:
    Private Sub label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
            Dim serial As String
            Dim length As Integer
            Dim byteArray() As Byte
            Dim badboy = 0
            Dim badboy1 = 0
            Dim badboy2 = 0
            Dim badboy3 = 0
            Dim badboy4 = 0
            Dim seriall
    
    
    
            length = TextBox1.TextLength
            If length < 6 Then
                MsgBox("Name must have 6 letters! Closing to prevent patching in a debugger :P", MsgBoxStyle.Information)
                Me.Close()
            ElseIf length = 6 Or length > 6 Then
    
                serial = ""
    
                serial = serial & TextBox1.Text.Chars(3)
                serial = serial & TextBox1.Text.Chars(5)
    
                byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(serial)
                For i As Integer = 0 To byteArray.Length - 1
                    serial = serial + byteArray(i).ToString("x")
                Next
    
    
    
                serial = serial.ToUpper
                Dim xxx = serial
    
                If TextBox2.Text = serial Then
                    badboy = 0
                Else
                    badboy = 1
                    If badboy = 1 Then
                    Else
    
                        badboy = 1
    
                        MsgBox("Incorrect serial! Make sure all letters are capitalized!")
                        badboy1 = 1
                        badboy2 = 1
                        badboy3 = 1
                        badboy4 = 1
                        MsgBox(serial)
                    End If
                End If
    
            End If
    
            If badboy = 0 Then
                seriall = ""
    
                seriall = seriall & TextBox1.Text.Chars(4)
                seriall = seriall & TextBox1.Text.Chars(0)
                seriall = seriall & TextBox1.Text.Chars(1)
    
                byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(seriall)
                For ilaw As Integer = 0 To byteArray.Length - 1
                    seriall = seriall + byteArray(ilaw).ToString("x")
                Next
    
    
    
                seriall = seriall.ToUpper
                ilaw = 0
    
                If TextBox3.Text = seriall Then
                    ilaw = ilaw + 1
                Else
                    If badboy = 1 Then
    
                    Else
                        badboy = 1
                        badboy1 = 1
                        badboy2 = 1
    
                        MsgBox("Incorrect seriall! Make sure all letters are capitalized!")
                        badboy3 = 1
                        MsgBox(seriall)
    
                        badboy4 = 1
                    End If
                End If
    
                If badboy = 0 Then
    
                End If
            End If
        End Sub
    It is for a shareware program, but when i click on label 4, it freezes. If you want the full thing, i can give it to you, but it will be stripped of most things. Thanks in advance
    PS. the badboy1 - 4 are so debuggers get messed up, and can't serial phish.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Weird error with my code???

    Hi... Welcome to the forums...

    Add a Breakpoint on the "Next" statement and run it. Then check the value of "byteArray.Length". See if it is larger or not. If it is much larger, then that's the problem for frozen window. You have to either modify it to perform correctly (if you are not expecting a bigger value there) or try adding Application.DoEvents() line inside the loop.

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    5

    Question Re: Weird error with my code???

    Ok did that, but the validation is messed up. It just wont work, here is my code now.
    Code:
       Private Sub label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
            Dim serial As String
            Dim length As Integer
            Dim byteArray() As Byte
            Dim badboy = 0
            Dim badboy1 = 0
            Dim badboy2 = 0
            Dim badboy3 = 0
            Dim badboy4 = 0
            Dim seriall
            Dim letters = 6
    
    
            length = TextBox1.TextLength
            If length < 6 Then
                badboy = 1
                MsgBox("Name must have " & letters & " letters!", MsgBoxStyle.Information)
            ElseIf length = 6 Or length > 6 Then
    
                If badboy = 1 Then
    
                Else
                    serial = ""
    
                    serial = serial & TextBox1.Text.Chars(3)
                    serial = serial & TextBox1.Text.Chars(5)
    
    
                    byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(serial)
                    serial = ""
                    For i As Integer = 0 To byteArray.Length - 1
                        serial = serial + byteArray(i).ToString("x")
                    Next
    
                    serial = serial.ToUpper
    
                    If TextBox2.Text = serial Then
                        badboy = 0
                    Else
                        badboy = 1
                        If badboy = 1 Then
                        Else
    
                            badboy = 1
    
                            MsgBox("Incorrect serial! Make sure all letters are capitalized!")
                            badboy1 = 1
                            badboy2 = 1
                            badboy3 = 1
                            badboy4 = 1
                            MsgBox(serial)
                        End If
                    End If
    
            End If
    
    
    
            If badboy = 0 Then
                seriall = ""
    
                seriall = seriall & TextBox1.Text.Chars(4)
                seriall = seriall & TextBox1.Text.Chars(0)
                seriall = seriall & TextBox1.Text.Chars(1)
    
                    byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(seriall)
                    serial = ""
                For ilaw As Integer = 0 To byteArray.Length - 1
                    seriall = seriall + byteArray(ilaw).ToString("x")
                Next
    
    
    
                seriall = seriall.ToUpper
                ilaw = 0
    
                If TextBox3.Text = seriall Then
                    ilaw = ilaw + 1
                ElseIf badboy = 1 Then
    
    
                            badboy = 1
                            badboy1 = 1
                            badboy2 = 1
    
                            MsgBox("Incorrect seriall! Make sure all letters are capitalized!")
                            badboy3 = 1
                            MsgBox(seriall)
    
                            badboy4 = 1
                    End If
                End If
    
                If badboy = 0 Then
                    End If
                End If

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Weird error with my code???

    I don't know how it works or what you are expecting !

    I just trimmed off the extra code and tested the main part:
    vb.net Code:
    1. Private Sub Label4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
    2.         Dim serial As String
    3.         Dim length As Integer
    4.         Dim byteArray() As Byte
    5.  
    6.         length = TextBox1.TextLength
    7.         If length < 6 Then
    8.             MsgBox("Name must have 6 letters! Closing to prevent patching in a debugger :P", MsgBoxStyle.Information)
    9.             Me.Close()
    10.         ElseIf length >= 6 Then
    11.  
    12.             serial = TextBox1.Text.Chars(3) & TextBox1.Text.Chars(5)
    13.  
    14.             byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(serial)
    15.  
    16.             For i As Integer = 0 To byteArray.Length - 1
    17.                 serial = serial & byteArray(i).ToString("x")
    18.             Next
    19.  
    20.             serial = serial.ToUpper
    21.  
    22.             If TextBox2.Text = serial Then
    23.                 MessageBox.Show("Congratz! You have unlocked the product")
    24.             Else
    25.                 MessageBox.Show("Hmm... Doesn't match ! The code is: " & serial)
    26.             End If
    27.         End If
    28.     End Sub
    Are you expecting the same ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width