Populate form 2 from form 1 results

teamdad

Member
Joined
Jun 14, 2004
Messages
12
Programming Experience
Beginner
Below are the guts of my program, I need to somehow get the results of my calculations with the code below on frmMain to be displayed in frmDisplay in a listbox named ListBoxDisplay. I have commented my code so it's easier to understand. Any code help is appreciated.

VB.NET:
Public Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
        Dim i As Integer
        Dim j As Integer
        Dim results() As Integer
        Dim output As String
        ListBox3.Items.Clear()
        'Get known
        Dim known As ListBox
        known = knownValuesList
        'Array keeping the results
        ReDim PResults(numPlays.Value, numsPerLine.Value)
        For i = 1 To numPlays.Value
            results = getNumbers(known, numsPerLine.Value, minRange.Value, maxRange.Value)
            For j = 0 To results.GetUpperBound(0)
                PResults(i - 1, j) = results(j)
                'Can change the "0" to " " to use a space
                Dim temp As String = IIf(CheckBox1.Checked = True, String.Format("{0:00}", results(j)), CStr(results(j)))
                If output <> "" Then output += " - "
                output += temp
            Next
            ' This section used with ListBox3 on same frmMain and not using frmDisplay
            'ListBox3.Items.Add(output)
            'output = ""
        Next
        'open the form and populate ListBoxData's listbox to display the results.
        Dim frmDisplay As New frmDisplay
        frmDisplay.Show()
 
    End Sub
    Public Function getNumbers(ByVal known As ListBox, ByVal requiredNumber As Integer, ByVal minRange As Integer, ByVal maxRange As Integer) As Integer()
        Dim output() As Integer
        Dim i As Integer
        Dim tmp As Integer
        Dim rndIndex As Integer
        Dim tmpArray(requiredNumber - 1) As Integer
        Dim randomPool As New ArrayList
        ' build the random pool
        For i = minRange To maxRange
            ' don't include any of the known values
            If Not known.Items.Contains(i) Then
                randomPool.Add(i)
            End If
        Next
        ' shuffle the random values
        For i = 0 To (randomPool.Count - 1)
            rndIndex = R.Next(0, randomPool.Count)
            tmp = randomPool(i)
            randomPool(i) = randomPool(rndIndex)
            randomPool(rndIndex) = tmp
        Next
        ' populate tmpArray with the known values
        ' and fill in any remaining slots
        ' with values from the shuffled randomPool
        For i = 0 To (requiredNumber - 1)
            If i <= (known.Items.Count - 1) Then
                tmpArray(i) = known.Items(i)
            Else
                tmpArray(i) = randomPool.Item(0)
                randomPool.RemoveAt(0)
            End If
        Next
        ' shuffle the set by swapping
        ' each position with another
        For i = 0 To tmpArray.GetUpperBound(0)
            rndIndex = R.Next(0, tmpArray.GetUpperBound(0))
            tmp = tmpArray(i)
            tmpArray(i) = tmpArray(rndIndex)
            tmpArray(rndIndex) = tmp
        Next
        output = tmpArray
        Return output
    End Function
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        Dim i As Integer
        Dim j As Integer
        Dim output As String
        Try
            ListBox3.Items.Clear()
            For i = 0 To numPlays.Value - 1
                For j = 0 To numsPerLine.Value - 1
                    Dim temp As String = IIf(CheckBox1.Checked = True, String.Format("{0:00}", PResults(i, j)), CStr(PResults(i, j)))
                    If output <> "" Then output += " - "
                    output += temp
                Next
                ListBox3.Items.Add(output)
                output = ""
            Next
        Catch
        End Try
    End Sub
 
Back
Top