Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net Code Errors

Hi

I get the following code errors amongst othersin the code further on.
I already have the following references:
Imports System.Data
Imports System.Linq


Error      34      Type 'AggregateFunction' is not defined.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Elements\Elements\Pivot.vb      41      82      Elements
Error      33      'RowList' is not declared. It may be inaccessible due to its protection level.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Elements\Elements\Pivot.vb      24      36      Elements
Error      49      'GetSum' is not declared. It may be inaccessible due to its protection level.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Elements\Elements\Pivot.vb      62      28      Elements
Error      47      'GetMin' is not declared. It may be inaccessible due to its protection level.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Elements\Elements\Pivot.vb      60      28      Elements
Error      45      'GetMax' is not declared. It may be inaccessible due to its protection level.      C:\Users\murbro\Documents\Visual Studio 2010\Projects\Elements\Elements\Pivot.vb      58      28      Elements


Imports System.Data
Imports System.Linq

Public Class Pivot


    Public Function PivotData(RowField As String, DataField As String, Aggregate As AggregateFunction, ParamArray ColumnFields As String()) As DataTable
        Dim dt As New DataTable()
        Dim Separator As String = "."
      Dim RowList = (From x In _SourceTable.AsEnumerable()New With { _
            Key .Name = x.Field(Of Object)(RowField) _
      }).Distinct()
      Dim ColList = (From x In _SourceTable.AsEnumerable()New With { _
            Key .Name = ColumnFields.[Select](Function(n) x.Field(Of Object)(n)).Aggregate(Function(a, b) a += Separator & b.ToString()) _
      }).Distinct().OrderBy(Function(m) m.Name)

        dt.Columns.Add(RowField)
        For Each col As var In ColList
            dt.Columns.Add(col.Name.ToString())
        Next

        For Each RowName As var In RowList
            Dim row As DataRow = dt.NewRow()
            row(RowField) = RowName.Name.ToString()
            For Each col As var In ColList
                Dim strFilter As String = (RowField & Convert.ToString(" = '")) + RowName.Name + "'"
                Dim strColValues As String() = col.Name.ToString().Split(Separator.ToCharArray(), StringSplitOptions.None)
                For i As Integer = 0 To ColumnFields.Length - 1
                    strFilter += " and " + ColumnFields(i) + " = '" + strColValues(i) + "'"
                Next
                row(col.Name.ToString()) = GetData(strFilter, DataField, Aggregate)
            Next
            dt.Rows.Add(row)
        Next
        Return dt
    End Function


    Private Function GetData(Filter As String, DataField As String, Aggregate As AggregateFunction) As Object
        Try
            Dim FilteredRows As DataRow() = _SourceTable.[Select](Filter)
            Dim objList As Object() = FilteredRows.[Select](Function(x) x.Field(Of Object)(DataField)).ToArray()

            Select Case Aggregate
                Case AggregateFunction.Average
                    Return GetAverage(objList)
                Case AggregateFunction.Count
                    Return objList.Count()
                Case AggregateFunction.Exists
                    Return If((objList.Count() = 0), "False", "True")
                Case AggregateFunction.First
                    Return GetFirst(objList)
                Case AggregateFunction.Last
                    Return GetLast(objList)
                Case AggregateFunction.Max
                    Return GetMax(objList)
                Case AggregateFunction.Min
                    Return GetMin(objList)
                Case AggregateFunction.Sum
                    Return GetSum(objList)
                Case Else
                    Return Nothing
            End Select
        Catch ex As Exception
            Return "#Error"
        End Try
        Return Nothing
    End Function

End Class
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
after that, please post the new build error list, because I presume some errors will go away or change...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks for the help