Results 1 to 8 of 8

Thread: [RESOLVED] Code not Executing?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Resolved [RESOLVED] Code not Executing?

    Ok, my problem is very straightforward, but I have no idea why the code won't execute. The first 2 MsgBox-es popup fine, but after that it seems like the rest of the code doesn't get executed, and to be honest it's driving me crazy since I have no clue as to why it's happening.


    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Dim ProgramFiles As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
    4.         Dim LegLabs As String = ProgramFiles & "\Leg Labs"
    5.         Dim FileRenamer As String = LegLabs & "\File Renamer"
    6.  
    7.         If Directory.Exists(FileRenamer) Then
    8.             MsgBox("Add to Startup Check")
    9.             Using FileRead As StreamReader = New StreamReader(FileRenamer & "\Add to Startup.txt")
    10.                 If FileRead.ReadToEnd.ToString.Contains("True") Then
    11.                     Form3.StartupCheckBox.Checked = True
    12.                 Else
    13.                     Form3.StartupCheckBox.Checked = False
    14.                 End If
    15.                 FileRead.Close()
    16.             End Using
    17.         End If
    18.  
    19.         If Directory.Exists(FileRenamer) Then
    20.             MsgBox("Show Icon Tray Check") ' IT SEEMS LIKE THIS IS THE POINT WHERE THE CODE STOPS EXECUTING.
    21.             Using Fileread As StreamReader = New StreamReader(FileRenamer & "\Show Icon in Tray.txt")
    22.                 If Fileread.ReadToEnd.ToString.Contains("True") Then
    23.                     '           MsgBox("aaaaaaaa") THIS MSGBOX DOESN'T POPUP
    24.                     Form3.TrayIconBox.Checked = True
    25.                     '    NotifyIcon1.Visible = True
    26.                 Else
    27.                     Form3.TrayIconBox.Checked = False
    28.                     '      NotifyIcon1.Visible = False
    29.                 End If
    30.                 Fileread.Close()
    31.             End Using
    32.             MsgBox("zbzbz") ' THIS MSGBOX DOESN'T POPUP EITHER AND THE CODE BELOW DOESN'T EXECUTE
    33.         End If
    34.  
    35.         MsgBox(FileRenamer)
    36.  
    37.         If Directory.Exists(FileRenamer) Then
    38.             MsgBox("Always on Top Check")
    39.             Using FileRead As StreamReader = New StreamReader(FileRenamer & "\Always on Top.txt")
    40.                 If FileRead.ReadToEnd.ToString.Contains("True") Then
    41.                     Form3.AlwaysOnTopCheckBox.Checked = True
    42.                     '     MsgBox("Supposedly Done")
    43.                     Me.TopMost = True
    44.                 Else
    45.                     '    MsgBox("WHAT THE ****?")
    46.                     Form3.AlwaysOnTopCheckBox.Checked = False
    47.                     Me.TopMost = False
    48.                 End If
    49.  
    50.                 FileRead.Close()
    51.             End Using
    52.         End If
    53.  
    54.         MsgBox("File Renamer")
    55.         NotifyIcon1.Text = "File Renamer"
    56.         Timer1.Start()

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Code not Executing?

    Most likely an exception is being thrown. On 64-bit OSes, exceptions thrown in the Load event handler are swallowed. If you watch the Output window you should be able to see if that is the case. You can wrap the contents of the event handler in a Try...Catch block to catch the exception and determine what is happening and where.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: Code not Executing?

    Quote Originally Posted by jmcilhinney View Post
    Most likely an exception is being thrown. On 64-bit OSes, exceptions thrown in the Load event handler are swallowed. If you watch the Output window you should be able to see if that is the case. You can wrap the contents of the event handler in a Try...Catch block to catch the exception and determine what is happening and where.
    Yeah, I thought of that and did it, but no exception was thrown in the try blocks either.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Code not Executing?

    I don't see how that's possible. Perhaps you should show us the code that you tried that includes exception handling. Also, you might try adding a breakpoint at the top of the code and then stepping through it line by line. You can then see exactly where it does and doesn't go. From what I can see, most likely the file you're trying to open doesn't exist.

    By the way, you don't have to Close a StreamReader that you created with a Using statement. The whole point of a Using statement is that the object it creates is implicitly disposed at the End Using line.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: Code not Executing?

    By using the breakpoint method, when I get on the second using statement I will get an error of the file "Show Icon in Tray.txt" being opened in another process, which I don't know whom process could it be. Given that it's probably my own app who is using the file, I don't see how it's being opened by the app since this is the only place where I use that streamreader.
    Last edited by Legjendat; Oct 28th, 2012 at 08:33 PM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Code not Executing?

    You said in post #3 that no exception was being thrown but obviously one is. If the exception says that the file is open then I'm inclined to believe it. Maybe you've opened it elsewhere in the app and not closed it. I don't know but I believe that it's open.

    Having said all that, you appear to be using a rather horrible method to store application configuration. Separate text files containing Boolean text? Really not a good idea. The ability to store configuration data is built into .NET apps so you should use that functionality. You should open the Settings page of the project properties and add three settings of type Boolean named AddToStartup, ShowIconInTray and AlwaysOnTop. You can then get rid of all that horrible code and just do this:
    Code:
    Form3.StartupCheckBox.Checked = My.Settings.AddToStartup
    Form3.TrayIconBox.Checked = My.Settings.ShowIconInTray 
    Form3.AlwaysOnTopCheckBox.Checked = My.Settings.AlwaysOnTop
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: Code not Executing?

    Quote Originally Posted by jmcilhinney View Post
    You said in post #3 that no exception was being thrown but obviously one is. If the exception says that the file is open then I'm inclined to believe it. Maybe you've opened it elsewhere in the app and not closed it. I don't know but I believe that it's open.

    Having said all that, you appear to be using a rather horrible method to store application configuration. Separate text files containing Boolean text? Really not a good idea. The ability to store configuration data is built into .NET apps so you should use that functionality. You should open the Settings page of the project properties and add three settings of type Boolean named AddToStartup, ShowIconInTray and AlwaysOnTop. You can then get rid of all that horrible code and just do this:
    Code:
    Form3.StartupCheckBox.Checked = My.Settings.AddToStartup
    Form3.TrayIconBox.Checked = My.Settings.ShowIconInTray 
    Form3.AlwaysOnTopCheckBox.Checked = My.Settings.AlwaysOnTop
    Indeed, that method was stupid, but it was the only one I could think of, I didn't even know what you told me could be done, and it is so easy, I just store the settings, wow thank you so much, this will be so useful to me in a handful of other applications as well.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Code not Executing?

    Progress.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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