Hi all,
My first post....I am a newbie at using vs2012 and vb.net code. I have created a simple form that uses radio buttons to change a text file between test1.txt and test1.txt.off and a checkbox to change a text file between test2.txt and test2.txt.off. I also want to set the radio button and checkbox when program starts to have the right radio button and checkbox selected to show the beginning status of the files.
I found I had to get into Overrides and Overridable subs so that when I programatically set the radio button and the checkbox onload, the code doesn't also try to excute file renames that fire when I manually choose a radio button or check or uncheck the checkbox.
I must be doing something wrong because in the OnLoad sub which initially sets the RadioButton and Checkbox, as soon as the code reaches a RadioButton1.Checked = True statement it does not execute the next If statement, and just pops the form up. The same is true if it were to reach a CheckBox1.Checked = True Statement.
Any help would be appreciated. Here is the code -- There is a Partial Class statement at the very beginning of the Form Designer code - I didn't show all of the form design info in the form designer:
Protected Overrides Sub OnLoad(e As EventArgs)
If File.Exists("test1.txt.off") Then
RadioButton1.Checked = True
Else
RadioButton2.Checked = True
End If
If System.IO.File.Exists("test2.txt") Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
End Sub
Protected Overridable Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
My.Computer.FileSystem.RenameFile("test1.txt", "test1.txt.off")
Else : RadioButton2.Checked = True
My.Computer.FileSystem.RenameFile("test1.txt.off", "test1.txt")
End If
End Sub
Protected Overridable Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
My.Computer.FileSystem.RenameFile("test2.txt.off", "test2.txt")
Else : CheckBox1.Checked = False
My.Computer.FileSystem.RenameFile("test2.txt", "test2.txt.off")
End If
End Sub
End Class
Any help would be appreciated....
Rod
My first post....I am a newbie at using vs2012 and vb.net code. I have created a simple form that uses radio buttons to change a text file between test1.txt and test1.txt.off and a checkbox to change a text file between test2.txt and test2.txt.off. I also want to set the radio button and checkbox when program starts to have the right radio button and checkbox selected to show the beginning status of the files.
I found I had to get into Overrides and Overridable subs so that when I programatically set the radio button and the checkbox onload, the code doesn't also try to excute file renames that fire when I manually choose a radio button or check or uncheck the checkbox.
I must be doing something wrong because in the OnLoad sub which initially sets the RadioButton and Checkbox, as soon as the code reaches a RadioButton1.Checked = True statement it does not execute the next If statement, and just pops the form up. The same is true if it were to reach a CheckBox1.Checked = True Statement.
Any help would be appreciated. Here is the code -- There is a Partial Class statement at the very beginning of the Form Designer code - I didn't show all of the form design info in the form designer:
Protected Overrides Sub OnLoad(e As EventArgs)
If File.Exists("test1.txt.off") Then
RadioButton1.Checked = True
Else
RadioButton2.Checked = True
End If
If System.IO.File.Exists("test2.txt") Then
CheckBox1.Checked = True
Else
CheckBox1.Checked = False
End If
End Sub
Protected Overridable Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
My.Computer.FileSystem.RenameFile("test1.txt", "test1.txt.off")
Else : RadioButton2.Checked = True
My.Computer.FileSystem.RenameFile("test1.txt.off", "test1.txt")
End If
End Sub
Protected Overridable Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
My.Computer.FileSystem.RenameFile("test2.txt.off", "test2.txt")
Else : CheckBox1.Checked = False
My.Computer.FileSystem.RenameFile("test2.txt", "test2.txt.off")
End If
End Sub
End Class
Any help would be appreciated....
Rod