Hi I’m fairly new to programming and I am having trouble trying to get a simple application to run which I consist of a windows form app and a class. I was hoping someone would be good enough to help me.
The windows form app consist of two controls:
A listbox And a button
The idea is that when I click on the button it calls a class and populates the listbox
Here is the code for the class definition.
Public Class Class1
Sub main()
Dim arr As Integer() = {1, 5, 7, 2, 11, 13, 16, 21, 36, 29}
Dim r = 7
Dim n = arr.Length
printcombination(arr, n, r)
End Sub
Private Shared Sub printcombination(ByVal arr As Integer(), ByVal n As Integer, ByVal r As Integer)
Dim data = New Integer(r - 1) {}
combinationUtil(arr, data, 0, n - 1, 0, r)
End Sub
Private Shared Sub combinationUtil(ByVal arr As Integer(), ByVal data As Integer(), ByVal start As Integer, ByVal [end] As Integer, ByVal index As Integer, ByVal r As Integer)
If index = r Then
For j = 0 To r - 1
'Console.Write(data(j) & " ")
Form1.ListBox1.Items.Add(data(j) & " ")
Next
'Console.WriteLine()
Form1.ListBox1.Items.Add(" ")
Return
End If
Dim i = start
While i <= [end] AndAlso [end] - i + 1 >= r - index
data(index) = arr(i)
combinationUtil(arr, data, i + 1, [end], index = 1, r)
i += 1
End While
End Sub
End Class
I’v converted this from a C# console application, hence the commenting out or the Console.Write(data(j) & " ") and Console.WriteLine()
The code for the Form button1_click event is:
Dim x As Class1
x = New Class1
x.main()