Solved

VB.net Code Errors

Posted on 2014-01-24
4
513 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:murbro
  • 2
4 Comments
 
LVL 142

Accepted Solution

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

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 250 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:murbro
ID: 39811435
Thanks for the help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now