Click here to Skip to main content
16,015,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
VB
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 22-Jan-20 6:40am
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.

1 solution

I would use a try Catch end catch instead of the on Error. However the on error is not the issue since it is executing the con.open and the writeerror is not prior to that.

I would suggest looking at the VALUE of IsFirstRun in your settings. When the program starts is it "TRUE" ? If you change it during your run, do you set it back prior to exit? Is it of a Boolean type? If not you will have to do a direct comparison to the value in the settings.

If a string then If My.Settings.IsFirstRun = "True" Then
If a Integer then If My.Settings.IsFirstRun = 1 Then

I would suggest in the form_load event that you test with a msgbox(My.Settings.IsFirstRun.tostring) Or a debug.print(My.Settings.IsFirstRun.tostring) and see what you are working with.

You could also place one of those in front of you if statement to see what you have so you will know the expected outcome.

debug.print(My.Settings.IsFirstRun.tostring)
If My.Settings.IsFirstRun then
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900