Some of you are already familiar with my attempts to write a GroceryList program. I wrote it a long time ago in VB6 using 40 Listboxes, 40 RadioButtons, and 40 Buttons. I got a lot of flack on this forum about using so many controls. Now I rewriting it in VB.net VS2019. I'm using 4 Listboxes, 40 RadioButtons, and 16 Buttons, and saving the items in general in List Arrays.
But here is the problem. I am not using automation because I don't know how. The program IS working, but it's getting really long because I have to make a subroutine for each list with each one just having a different number next to the word "List" and/or "Listbox". And I'm having to do this over and over!!! How do I make a subroutine that will handle each one with the important info sent as arguments?
Here is some examples of what I'm talking about.
Example 1Example 2Code:Dim list0 As New List(Of String)
Dim list1 As New List(Of String)
Dim list2 As New List(Of String)
Dim list3 As New List(Of String)
Dim list4 As New List(Of String)
Example 3Code:Dim objWriter As New StreamWriter("C:\Grocery List\GList2.TXT")
objWriter.WriteLine("00;*;" & RadioButton0.Text) '
For Each Item As String In list0
objWriter.WriteLine(Item) '
Next
objWriter.WriteLine("01;*;" & RadioButton1.Text) '
For Each Item As String In list1
objWriter.WriteLine(Item) '
Next
objWriter.WriteLine("02;*;" & RadioButton2.Text) '
For Each Item As String In list2
objWriter.WriteLine(Item) '
Next
ThanksCode:Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
ListBox0.Items.Clear()
ListBox0.Items.AddRange(list1.ToArray)
Else
list1.Clear()
For X As Integer = 0 To ListBox0.Items.Count - 1
If ListBox0.GetSelected(X) Then
list1.Add("+" & ";" & ListBox0.Items.Item(X).ToString)
Else
list1.Add("-" & ";" & ListBox0.Items.Item(X).ToString)
End If
Next
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
ListBox0.Items.Clear()
ListBox0.Items.AddRange(list2.ToArray)
Else
list2.Clear()
For X As Integer = 0 To ListBox0.Items.Count - 1
If ListBox0.GetSelected(X) Then
list2.Add("+" & ";" & ListBox0.Items.Item(X).ToString)
Else
list2.Add("-" & ";" & ListBox0.Items.Item(X).ToString)
End If
Next
End If
End Sub