need help building a matrix please help

tronracer

Newcomer
Joined
Mar 11, 2003
Messages
4
i have a database in which I would like to retrieve data. I setup my oledb connection, oledb adapter, and generated a dataset. But, I would like to retrieve only 2 columns (last name and salary) from the dataset and place them into a matrix from which I could use the matrix to compute data such as second highest salary). I am having trouble genrating code. Would I use an array? And if so, what would the code look like?

thank you,

VB gurus
 
cut and past code

Visual Basic:
Public Class Form1
    Inherits System.Windows.Forms.Form

'#Region...etc.....
.................................
end region

    'enum statement

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

        Dim Data(2, 23) As String
        Dim i As Integer
        Dim dblTotalSalary As Double
        Dim dblAverageSalary As Double
        Dim dblJTotalSalary As Double
        Dim dblJAverageSalary As Double
        Dim intJCount As Integer

        Dim dblHighestSalary As Double
        Dim dblSecondHighestSalary As Double
        Dim dblLowestSalary As Double
        Dim dblSecondLowestSalary As Double


        Dim intSmallestPrime As Integer
        Dim intTempPrime As Integer
        Dim result As Integer
        Dim j As Integer
        Dim intHaddockSalary As Integer

        For i = 0 To 22
            Data(0, i) = DataSet11.Tables(0).Rows(i)(0)
            Data(1, i) = DataSet11.Tables(0).Rows(i)(1)
        Next i

        For i = 0 To 22
            dblTotalSalary += Val(DataSet11.Tables(0).Rows(i)(1))
        Next i

        dblAverageSalary = dblTotalSalary / 23


        For i = 0 To 22
            If (InStr(Data(0, i), "J") = 1) Then
                intJCount += 1
                dblJTotalSalary += Val(Data(1, i))
            End If
        Next i

        dblJAverageSalary = dblTotalSalary / intJCount

        dblHighestSalary = Val(Data(1, 0))
        dblSecondHighestSalary = Val(DataSet11.Tables(0).Rows(0)(1))
        dblLowestSalary = Val(DataSet11.Tables(0).Rows(0)(1))
        dblSecondLowestSalary = Val(DataSet11.Tables(0).Rows(0)(1))

        For i = 0 To 22

            If (dblHighestSalary < Val(DataSet11.Tables(0).Rows(i)(1))) Then
                dblSecondHighestSalary = dblHighestSalary
                dblHighestSalary = Val(DataSet11.Tables(0).Rows(i)(1))

            else if(dblSecondHighestSalary <
Val(DataSet11.Tables(0).Rows(i)(1))
                dblSecondHighestSalary = Val(DataSet11.Tables(0).Rows(i)(1))
            End If


            'Add code for lowest follow the above example switching variables
and < to >

        Next i


        'initialize dblHaddockSalary to Captain Haddock's salary
        For i = 0 To 22

            If (InStr(Data(0, i), "Haddock") <> 0) Then

                intHaddockSalary = Val(Data(1, i))

            End If
        Next i

        intSmallestPrime = dblHighestSalary

        For i = 0 To 22


            If (Data(0, i) >= intHaddockSalary) Then

                If (checkIfPrime(Val(Data(0,i)) = isPrime.yes) Then
                    If (Val(Data(0, i)) < intSmallestPrime) Then
                        intSmallestPrime = Data(0, 1)
                    End If
                End If
            End If
        Next i

        If (checkIfPrime(intSmallestPrime) = isPrime.yes) Then
            'output smallest prime
        Else
            'print out "No prime numbers greater than Haddock's salary"

        End If

    End Sub

    'checkisPrime function goes here
End Class
 
Last edited by a moderator:
Back
Top