Checkbox Loop + Editing Array
Hey guys
having a bit of trouble with a bit of code.
This is going to be a bit complicated to explain so i hope i can get the idea across.
The idea is that the following bit of code uses an array called "lines" which has been loaded from a text file in a previous subroutine.
I then want the status of each Checkbox to edit a set of lines in the array.
So Checkbox1 will edit lines(v)
Checkbox2 will edit lines(v+1)
Checkbox3 will edit lines (v+2)
etc... etc....
The below code should check if each check box is checked, if so then it should check the corresponding line in the array and if the first character is a slash it will remove it.
If it is unchecked then the code checks the corresponding line in the array and if there is no slash at the start of the line it adds one.
slashnum() is defined in an earlier subroutine and is either 1 or 0 depending if the first character is a slash.
Checkbox Code:
Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Savebutton.Click
Clicked = True
Dim v = start + 1
Dim chkBoxes() As CheckBox = {CheckBox1, CheckBox2, CheckBox3, CheckBox4,
CheckBox5, CheckBox6, CheckBox7, CheckBox8,
CheckBox9, CheckBox10, CheckBox11, CheckBox12,
CheckBox13, CheckBox14}
Do While v = UBound(Lines) + 1
For Each chk As CheckBox In chkBoxes
If chk.Checked = True And slashnum(v) = 0 Then
Lines(v) = Mid(Lines(v), 2)
End If
If CheckBox1.Checked = False And slashnum(v) = 1 Then
Lines(v) = "/" & Lines(v)
End If
v = v + 1
Next
Loop
If Savefile(Lines) Then
MsgBox("File Saved")
Else
MsgBox("File Could Not Be Saved")
End If
End Sub
The code runs through fine with no errors but it doesnt seem to actually change the array at all. I assume its something incorrect in the way I have set it to loop through all the checkboxes?
Hope I explained that well enough.
Any help would be really handy and much appreciated.
Cheers
Dave
Re: Checkbox Loop + Editing Array
Step through the code, that should give you a clue as to where the problem is.
Re: Checkbox Loop + Editing Array
How do you say if your array is changed or not? If you look in the saved file then perhaps you've got something wrong with the Save procedure. Anyway, use breakpoints to determine where your array 'reverts' to its original state.