Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Populate form 2 with form 1 results


Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2006, 11:04 AM
teamdad teamdad is offline
Newcomer
 
Join Date: Jan 2004
Posts: 9
Default Populate form 2 with form 1 results


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.


Code:
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
Reply With Quote
  #2  
Old 04-07-2006, 11:07 AM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->