Click here to Skip to main content
14,242,633 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I have a problem with vb. The program skips lines of code.
It works in another program i did but in this program it doesn't work

The program goes from "On error.." directly to "dim frm.." and then to "con open"
Any idees?
On Error GoTo WriteError  

      If My.Settings.IsFirstRun Then
            Dim frm As New frmActivation
            frm.ShowDialog()
            My.Settings.IsFirstRun = False
        Else
            Dim sm As New SecurityManager
            If sm.CheckKey(frmActivation.PasswordDecrypt(tActivationKey, 
                              tEncryptionKey)) Then
            Else
                Dim frm As New frmActivation
                frm.ShowDialog()
            End If
        End If

       con.Open()
       ..


What I have tried:

I have tried removing the error handler.
Posted
Updated 5-Jun-19 3:23am
v2
Comments
RickZeeland 5-Jun-19 9:25am
   
Are you sure you have the settings defined in your project - Settings tab page ?
Member 14131979 5-Jun-19 9:35am
   
Yes. Double checked it. Deleted it and dit it again.
Richard MacCutchan 5-Jun-19 9:44am
   
Step through the code with the debugger so you can see the actual values of all variables that are referred to in your if statements.
Dave Kreskowiak 5-Jun-19 11:30am
   
It's not skipping lines of code. It may look like it, but it's not.

And why on earth are you using "On Error Goto" is a VB.NET app? That's an old VB6 way or doing things that is there only for backwards compatibility of imported code. It shouldn't be used in new development.

The debugger is going to show you that it is NOT skipping lines of code. It's going to show you that you're not understanding what the code is doing. The debugger is there to debug YOU and show you what's really going on.
CPallini 5-Jun-19 12:00pm
   
You used the On Error GoTo statement. Such statememt skips lines of code whenever an erro occurs. The WriteError, to honour its own name, should give you relevant info about the error.
cigwork 30-Jun-19 16:27pm
   
> If sm.CheckKey(frmActivation.PasswordDecrypt(tActivationKey, tEncryptionKey))

On the basis of the fragment shown on any run after FirstRun frmActivation will be null (nothing) when the line above is executed. Given this I'd expect a null reference exception to be thrown. That plus the prehistoric on error goto handling is likely to give interesting results.

If the code is genuinely going from the attempt to open the activation dialog on first ever run to connection open then that suggests the activation form is being closed without any user interaction, so an error condition in frmActivation, perhaps an exception being swallowed, resulting in the form closing before it has a chance to display anything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100