|
-
Oct 28th, 2012, 06:46 PM
#1
Thread Starter
Addicted Member
[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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ProgramFiles As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
Dim LegLabs As String = ProgramFiles & "\Leg Labs"
Dim FileRenamer As String = LegLabs & "\File Renamer"
If Directory.Exists(FileRenamer) Then
MsgBox("Add to Startup Check")
Using FileRead As StreamReader = New StreamReader(FileRenamer & "\Add to Startup.txt")
If FileRead.ReadToEnd.ToString.Contains("True") Then
Form3.StartupCheckBox.Checked = True
Else
Form3.StartupCheckBox.Checked = False
End If
FileRead.Close()
End Using
End If
If Directory.Exists(FileRenamer) Then
MsgBox("Show Icon Tray Check") ' IT SEEMS LIKE THIS IS THE POINT WHERE THE CODE STOPS EXECUTING.
Using Fileread As StreamReader = New StreamReader(FileRenamer & "\Show Icon in Tray.txt")
If Fileread.ReadToEnd.ToString.Contains("True") Then
' MsgBox("aaaaaaaa") THIS MSGBOX DOESN'T POPUP
Form3.TrayIconBox.Checked = True
' NotifyIcon1.Visible = True
Else
Form3.TrayIconBox.Checked = False
' NotifyIcon1.Visible = False
End If
Fileread.Close()
End Using
MsgBox("zbzbz") ' THIS MSGBOX DOESN'T POPUP EITHER AND THE CODE BELOW DOESN'T EXECUTE
End If
MsgBox(FileRenamer)
If Directory.Exists(FileRenamer) Then
MsgBox("Always on Top Check")
Using FileRead As StreamReader = New StreamReader(FileRenamer & "\Always on Top.txt")
If FileRead.ReadToEnd.ToString.Contains("True") Then
Form3.AlwaysOnTopCheckBox.Checked = True
' MsgBox("Supposedly Done")
Me.TopMost = True
Else
' MsgBox("WHAT THE ****?")
Form3.AlwaysOnTopCheckBox.Checked = False
Me.TopMost = False
End If
FileRead.Close()
End Using
End If
MsgBox("File Renamer")
NotifyIcon1.Text = "File Renamer"
Timer1.Start()
-
Oct 28th, 2012, 07:16 PM
#2
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.
-
Oct 28th, 2012, 07:26 PM
#3
Thread Starter
Addicted Member
Re: Code not Executing?
 Originally Posted by jmcilhinney
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.
-
Oct 28th, 2012, 07:51 PM
#4
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.
-
Oct 28th, 2012, 08:05 PM
#5
Thread Starter
Addicted Member
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.
-
Oct 28th, 2012, 08:50 PM
#6
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
-
Oct 28th, 2012, 09:25 PM
#7
Thread Starter
Addicted Member
Re: Code not Executing?
 Originally Posted by jmcilhinney
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.
-
Oct 28th, 2012, 09:32 PM
#8
Re: Code not Executing?
Progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|