Solved

Can't figure out cause of warning

Posted on 2011-03-15
2
334 Views
Last Modified: 2012-08-13
Hi, there.  I am getting this warning on the code that follows:

Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.

Private Sub LoadData()
    Dim ds As New DataSet
    Try
        ds = objEngine.SelectRecords("frmDataAssociates")

The underlined code is where the warning is.

Here's the objEngine.SelectRecords() code:

Public Shared Function SelectRecords(ByVal formName As String, Optional ByVal mTab As Integer = 0) As DataSet
        Dim mConnection As OleDbConnection = GetConnection()
        Dim mConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\CLRS\CLRS.mdb"
        Dim mDataSet As New DataSet
        Dim mAdapter As OleDbDataAdapter

        Dim str As String = ""
        Dim tableName As String = ""
        Dim b As New HeaderDB
        Dim objHeader As New Header
        Try
            objHeader = b.Load()
            Select Case formName
                Case "frmSetup"
                    Select Case mTab
                        Case 0, 4 ' Current Month and System
                            str = "SELECT CurrentMonthName,CurrentYear,LegacyCO,Region,RegionPresident,GeneralManager,Manager "
                            str &= "FROM Header;"
                            tableName = "Header"
                        Case 1 ' Stores
                            str = "SELECT StoreID,StoreAbbreviation,StoreState,StoreName "
                            str &= "FROM Stores "
                            str &= "ORDER BY StoreState,StoreName;"
                            tableName = "Stores"
                        Case 2 ' Associates
                            str = "SELECT AssociateID,StoreName,AssociateName "
                            str &= "FROM Associates "
                            str &= "ORDER BY StoreName,AssociateName;"
                            tableName = "Associates"
                        Case 3 ' Products
                            str = "SELECT ProductID,ProductName,ProductType "
                            str &= "FROM Products "
                            str &= "ORDER BY ProductType,ProductName;"
                            tableName = "Products"
                    End Select

                Case "frmDataStores"
                    str = "SELECT  RecordID, CurrMonthName, CurrYear, StoreName, ProductName, Target, Actual, PercentValue "
                    str &= "FROM DataStores "
                    str &= "WHERE (CurrMonthName = '" & objHeader.CurrentMonthName & "') "
                    str &= "AND (CurrYear = " & objHeader.CurrentYear & ") "
                    str &= "ORDER BY StoreName,ProductName;"
                    tableName = "DataStores"

                Case "frmDataAssociates"
                    str = "SELECT RecordID,CurrMonthName,CurrYear,StoreName,AssociateName,ProductName,Target,Actual,PercentValue "
                    str &= "FROM DataAssociates "
                    str &= "WHERE (CurrMonthName = '" & objHeader.CurrentMonthName & "') "
                    str &= "AND (CurrYear = " & objHeader.CurrentYear & ") "
                    str &= "ORDER BY StoreName,AssociateName,ProductName;"
                    tableName = "DataAssociates"

                Case "frmDataTraffic"
                    str = "SELECT TrafficID,CurrMonthName,CurrYear,StoreName,Traffic "
                    str &= "FROM DataTraffic "
                    str &= "WHERE (CurrMonthName = '" & objHeader.CurrentMonthName & "') "
                    str &= "AND (CurrYear = " & objHeader.CurrentYear & ") "
                    str &= "ORDER BY StoreName;"
                    tableName = "DataTraffic"

            End Select
            mConnection.Open()
            mDataSet = New DataSet
            mAdapter = New OleDbDataAdapter(str, mConnectionString)
            mAdapter.Fill(mDataSet, tableName)
        Catch ex As Exception
            ShowError(ex, "DBEngine.SelectRecords", Err.Number, str)
        Finally
            mConnection.Close()
        End Try
        Return mDataSet
    End Function

Open in new window


The code works without error, but I get the warning everytime objEngine.SelectRecords is called.  I hope this is enough information to help you figure out the problem.  Thanks so much.
0
Comment
Question by:Agent909
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35144267
Hi,

A shared method is not accessed via an object instance like a regular method, but rather is accessed directly from the class

Probably objEngine is an instance of a class, so, to avoid the warning, use the class to call your shared function.

Lets say that your class name is MyClass, then instead of instance the class you call the method directly like this

ds = MyClass.SelectRecords("frmDataAssociates")
0
 
LVL 1

Author Closing Comment

by:Agent909
ID: 35144294
That worked!  Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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