1

我正在构建一个从对象中提取脚本的小应用程序。我已经到了我的代码从具有脚本的对象中拉回字段的部分,我收到了这个错误。

“对非共享成员的引用需要对象引用”

我不确定要改变什么或如何解决这个问题。有没有人有任何建议?

这是我到目前为止的代码。这是一个简单的应用程序,它有一个组合框,您可以从中选择公司,然后单击按钮,它将获取脚本并将其显示在文本框中。

这是我的代码:

Imports System.IO
Public Class Form1
    Public M3System As MILLSYSTEMLib.System
    Public M3Script As MILLCOMPANYLib.CScripting

    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'On Error Resume Next
        Try
            Dim Approved As Integer

            ' Create a Millennium system obects
            M3System = CreateObject("MillSystem.System")
            M3System.Load("Millennium")

            'run login script
            Dim User As Object = M3System.Login()

            ' See if login worked
            If User Is Nothing Then
                'MsgBox("Login failed!")
                Approved = 0
            Else
                'MsgBox("Login successful")
                'if approved=1 then the user is able to access M3
                Approved = 1
            End If

            'populate combo box
            For Each Company In M3System.Companies
                cb_COID.Items.Add(Company.Field("co").ToString)
            Next

        Catch ex As Exception
            Me.Close()
        End Try


    End Sub

    Public Sub btn_LoadScript_Click(sender As Object, e As EventArgs) Handles btn_LoadScript.Click

        Dim CoCode As String = cb_COID.SelectedItem
        Dim script As String = M3Script.vbscript

        If IsNothing(cb_COID) Then
            MessageBox.Show("Select a Company Code")
        End If
        For Each CoCode In M3Script.co
            tb_Script.Text = script
        Next

    End Sub
4

1 回答 1

2

我猜你失败的那条线是Dim script As String = M3Script.vbscript

如果是这种情况,那是因为您声明了M3Script,但没有创建它的实例。

尝试通过添加M3Script = new MILLCOMPANYLib.CScripting到代码中来设置对象,或者你会加载它(也许M3Script = CreateObject("MillSystem.Script")?)

于 2013-08-30T17:54:36.640 回答