简体   繁体   中英

VB Error : “'mAuto1' is not declared. It may be inaccessible due to its protection level”. Need solution

I am new to programming in c# and visual basic. I am using visual studio 2010 and I am trying to retrieve some data from a mysql database. Installed using wamp.

I have already set connection to the database by going to 'Project', 'Application Properties', 'Settings'.

I have this error "'mAuto1' is not declared. It may be inaccessible due to its protection level" and I cant seem to solve it.

The code below is for a simple retrieve:

Public Class Form1

    Private procAuto As CALCOM.Auto

    Private Function Connect_To_Database() As Boolean
        Dim mErrorNumQuery As Long
        Dim mReturn As Boolean
        procAuto = New CALCOM.Auto
        procAuto.Connect(mErrorNumQuery)
        If mErrorNumQuery = 0 Then
            mReturn = True
        Else
            mReturn = False
        End If
        Connect_To_Database = mReturn
    End Function

    Private Function Get_Weight_By_TicketNumber(ByVal mTicketNumber As String, ByRef mAuto1 As Long, ByRef mAuto2 As Long, ByRef mTotalWeight As Long) As Boolean
        Dim mErrorNumQuery As Long
        Dim mXtr As New CALCOM.xTr
        Dim mRec As ADODB.Recordset
        Dim mReturn As Boolean
        mRec = mXtr.GetList("Select Auto1,Auto2,TotalWeight From txticket Where TicketCode = '" & mTicketNumber & "'", , , mErrorNumQuery)
        If mErrorNumQuery = 0 Then
            mReturn = True
            If mRec.RecordCount <> 0 Then
                mRec.MoveFirst()
                mRec.MoveFirst()
                mAuto1 = mRec.Fields("Auto1").Value
                mAuto2 = mRec.Fields("Auto2").Value
                mTotalWeight = mRec.Fields("TotalWeight").Value
            End If
        Else
            mReturn = False
        End If
        Get_Weight_By_TicketNumber = mReturn
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = mAuto1 <--------------------problem here
    End Sub
End Class

This program was just a test to see if I can display results of a mysql query on a form label. I wanted to display results on the click of a button

How do I fix the error? Any help appreciated.

The mAuto1 variant is a local one at Get_Weight_By_TicketNumber function, you can't use it outside the function. If you want, declare a class-level variant and set it to the value of mAuto1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM