Murray Brown
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\Ele ments\Pivo t.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\Ele ments\Pivo t.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\Ele ments\Pivo t.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\Ele ments\Pivo t.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\Ele ments\Pivo t.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](Func tion(n) x.Field(Of Object)(n)).Aggregate(Func tion(a, b) a += Separator & b.ToString()) _
}).Distinct().OrderBy(Func tion(m) m.Name)
dt.Columns.Add(RowField)
For Each col As var In ColList
dt.Columns.Add(col.Name.To String())
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. ToCharArra y(), 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](Filt er)
Dim objList As Object() = FilteredRows.[Select](Func tion(x) x.Field(Of Object)(DataField)).ToArra y()
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
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\
Error 33 'RowList' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\
Error 49 'GetSum' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\
Error 47 'GetMin' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\
Error 45 'GetMax' is not declared. It may be inaccessible due to its protection level. C:\Users\murbro\Documents\
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(
Key .Name = x.Field(Of Object)(RowField) _
}).Distinct()
Dim ColList = (From x In _SourceTable.AsEnumerable(
Key .Name = ColumnFields.[Select](Func
}).Distinct().OrderBy(Func
dt.Columns.Add(RowField)
For Each col As var In ColList
dt.Columns.Add(col.Name.To
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(
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](Filt
Dim objList As Object() = FilteredRows.[Select](Func
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
after that, please post the new build error list, because I presume some errors will go away or change...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help