Results 1 to 3 of 3

Thread: Checkbox Loop + Editing Array

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    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:
    1. Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Savebutton.Click
    2.         Clicked = True
    3.  
    4.         Dim v = start + 1
    5.         Dim chkBoxes() As CheckBox = {CheckBox1, CheckBox2, CheckBox3, CheckBox4,
    6.                                     CheckBox5, CheckBox6, CheckBox7, CheckBox8,
    7.                                     CheckBox9, CheckBox10, CheckBox11, CheckBox12,
    8.                                     CheckBox13, CheckBox14}
    9.  
    10.         Do While v = UBound(Lines) + 1
    11.  
    12.             For Each chk As CheckBox In chkBoxes
    13.  
    14.                 If chk.Checked = True And slashnum(v) = 0 Then
    15.                     Lines(v) = Mid(Lines(v), 2)
    16.                 End If
    17.                 If CheckBox1.Checked = False And slashnum(v) = 1 Then
    18.                     Lines(v) = "/" & Lines(v)
    19.                 End If
    20.                 v = v + 1
    21.             Next
    22.         Loop
    23.  
    24.         If Savefile(Lines) Then
    25.             MsgBox("File Saved")
    26.         Else
    27.             MsgBox("File Could Not Be Saved")
    28.         End If
    29.     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

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Checkbox Loop + Editing Array

    Step through the code, that should give you a clue as to where the problem is.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  3. #3
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    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.

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