开发者

Variable Protection Level in Script

开发者 https://www.devze.com 2023-03-19 11:08 出处:网络
I am creating a script programatically. However I cannot access the dataset from the modeule. See \"Sample\" below. (\'ds\' is not declared. It may be inaccessible due to its protection level.)

I am creating a script programatically. However I cannot access the dataset from the modeule. See "Sample" below. ('ds' is not declared. It may be inaccessible due to its protection level.)

In the Sub main() I can access ds without a probl开发者_开发问答em In the Sub test() in Cacl_Module I cannot access ds.

Namespace Evaluator

Public Class Evaluator
    Public ds As New DataSet
    Public ComboBox1 As New ComboBox
    Public CheckBox1 As New CheckBox
    Public TextBox1 As New TextBox

    Sub main()
        Debug.Print(ds.Tables("Table1").Rows.Count)
        Debug.Print(CheckBox1.Checked)
    End Sub

End Class

Public Module Calc_module
    Sub test()
        Debug.Print(ds.Tables("Table1").Rows.Count)
        Debug.Print(CheckBox1.Checked)
    End Sub
End Module

End Namespace


That's because ds is a member of the Evaluator class. In the Main method of the Evaluator class, you can access its members. But in the test method of the Calc_Module, you don't have an instance of Evaluator. You should create one, like that:

Public Module Calc_module
    Sub test()
        Dim MyEvaluator as new Evaluator()
        Debug.Print(MyEvaluator.ds.Tables("Table1").Rows.Count)
        Debug.Print(MyEvaluator.CheckBox1.Checked)
    End Sub
End Module

Or even better (no need to duplicate code)

Public Module Calc_module
    Sub test()
        Dim MyEvaluator as new Evaluator()
        MyEvaluator.main()
    End Sub
End Module
0

精彩评论

暂无评论...
验证码 换一张
取 消