?
Solved

VB.net Code Errors

Posted on 2014-01-24
4
Medium Priority
?
528 Views
Last Modified: 2014-01-27
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
0
Comment
Question by:Murray Brown
  • 2
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 39806026
Aggregate As AggregateFunction  must be  AggregateFunction as Aggregate
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39806028
after that, please post the new build error list, because I presume some errors will go away or change...
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 39806186
It sounds like you AggregateFunction enum isn't in the same project, or at least the same namespace, as your method (or maybe just not scoped correctly).
0
 

Author Closing Comment

by:Murray Brown
ID: 39811435
Thanks for the help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question