We will continue modifying the program from example 08.

So far the program only has one checkbox that removes the folder path from filenames.
One thing that appears on my filename list are files with a "~" tilde sign inside. They are usually found at the bottom of the loaded lists. They appear to be backup files that are not really visible inside a folder. We'll add a checkbox to remove those files from the list.

Current code:


    Imports System.IO

    Public Class Form1

    Private bb As String()
    Private c1 As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim d As String
    If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
    c1 = 1
    Label1.Text = FolderBrowserDialog1.SelectedPath

    bb = Directory.GetFiles(FolderBrowserDialog1.SelectedPath, "*.*")
    TextBox1.Clear()
    For Each d In bb
    TextBox1.AppendText(d & vbNewLine)
    Next
    End If

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    TextBox1.Clear()
    If c1 = 0 Then
    CheckBox1.Checked = False
    Exit Sub


    End If

    If CheckBox1.Checked = True Then
    For Each d In bb
    d = Replace(d, FolderBrowserDialog1.SelectedPath, "")
    TextBox1.text += Replace(d, "\", "") & vbNewLine
    Next
    Else
    For Each d In bb
    TextBox1.Text = TextBox1.Text & d & vbNewLine
    Next

    End If

    End Sub
   
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    TextBox1.Clear()
    Label1.Text = "No Folder Selected"
    c1 = 0
    CheckBox1.Checked = False

    End Sub
   
    End Class


Add another checkbox. Change the text of the checkbox to: Remove ~ files
We can change all the:   CheckBox1.Checked = True  code lines into:
CheckBox1.Checked
Same thing if the checkbox value is true.

At the beginning of the program under: Private bb As String()  we will add:
Private bb2() As String

We will use this inside the checkboxes.
If the next checkbox is already checked, AND we check the current one, we then use bb2.

At the beginning of checkbox1 let's add this:
If c1 = 0 Then
Exit Sub
End If
ReDim bb2(0 To TextBox1.Lines.Count - 1)
For d = 0 To TextBox1.Lines.Count - 1
bb2(d) = TextBox1.Lines(d)
Next
TextBox1.Clear()

TextBox1.Lines.Count  - counts the number of lines that are currently present in the textbox. It gives an accurate value. In our case, we will use this function inside of an array. The last array cannot be:
bb2(TextBox1.Lines.Count)   because arrays start at zero for the first line. The last array must, therefore, be:
bb2(TextBox1.Lines.Count - 1) to have the exact number of lines present in the textbox.

ReDim bb2 - this function will give a new size to our bb2 array. It is usually used as:
ReDim Variable_Name(Number1 to Number2)   - "Number1" - starting value of the array, "Number2" - ending value of the array.  example:  Redim a1(0 to 20)

bb2 didn't have a determined size prior to this.

For d = 0 To TextBox1.Lines.Count - 1   -  this is a "for" loop, it's closed by "next".  "d" starts at zero inside the loop and the it all stops when we reach the last number determined by: TextBox1.Lines.Count - 1
With this loop we will take all the current text from the textbox and store it inside bb2.

We will remove all the remaining previous code from the checkboxes and a new one.

Add this into checkbox1 just below the previous code:
If CheckBox1.Checked Then
If CheckBox2.Checked Then
ElseIf CheckBox2.Checked = False Then
End If
End If

If CheckBox1.Checked = False Then
If CheckBox2.Checked Then
ElseIf CheckBox2.Checked = False Then
End If
End If

Add this into checkbox2:
If CheckBox2.Checked Then
If CheckBox1.Checked Then
ElseIf CheckBox1.Checked = False Then
End If
End If

If CheckBox2.Checked = False Then
If CheckBox1.Checked Then
ElseIf CheckBox1.Checked = False Then
End If
End If

The code looks similar, only the checkbox numbers are changed. This code covers all the conceivable possibilities we might have with two checkboxes.

Inside checkbox1:
If checkbox1 is true -> then checkbox2 can be true or false   (2 possibilities)
if checkbox1 is false -> then checkbox2 can be true or false  (2 possibilities)

Same thing for checkbox2.
We will fill those possibilities with operations in the next post.

Current code:

    Imports System.IO

    Public Class Form1

    Private bb As String()
    Private bb2() As String
    Private c1 As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim d As String
    If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
    c1 = 1
    Label1.Text = FolderBrowserDialog1.SelectedPath

    bb = Directory.GetFiles(FolderBrowserDialog1.SelectedPath, "*.*")
    TextBox1.Clear()
    For Each d In bb
    TextBox1.AppendText(d & vbNewLine)
    Next
    End If

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If c1 = 0 Then
    Exit Sub
    End If

    ReDim bb2(0 To TextBox1.Lines.Count - 1)
    For d = 0 To TextBox1.Lines.Count - 1
    bb2(d) = TextBox1.Lines(d)
    Next

    TextBox1.Clear()


    If CheckBox1.Checked Then
    If CheckBox2.Checked Then
    ElseIf CheckBox2.Checked = False Then
    End If
    End If

    If CheckBox1.Checked = False Then
    If CheckBox2.Checked Then
    ElseIf CheckBox2.Checked = False Then
    End If
    End If


    End Sub
    

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
    If c1 = 0 Then
    Exit Sub
    End If

    ReDim bb2(0 To TextBox1.Lines.Count - 1)
    For d = 0 To TextBox1.Lines.Count - 1
    bb2(d) = TextBox1.Lines(d)
    Next

    TextBox1.Clear()


    If CheckBox2.Checked Then
    If CheckBox1.Checked Then
    ElseIf CheckBox1.Checked = False Then
    End If
    End If

    If CheckBox2.Checked = False Then
    If CheckBox1.Checked Then
    ElseIf CheckBox1.Checked = False Then
    End If
    End If


    End Sub

 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    TextBox1.Clear()
    Label1.Text = "No Folder Selected"
    c1 = 0

    CheckBox1.Checked = False
    CheckBox2.Checked = False
    End Class


The rest of the program in the next post. Next Post