VBnet从模块调用sub

时间:2018-06-02 01:00:08

标签: vb.net visual-studio

我有一个名为" clsCustomer.vb"我该如何使用sub" CustomerInputOk"来自我主要形式的那个模块" frmMain"?我试图通过以下方式致电:

如果不是CustomerInputOK()则退出Sub

我尝试过调用前缀" clsCustomer.CustomerInputOK()"但那不起作用。

2 个答案:

答案 0 :(得分:1)

如果CustomerInputOK是sub,则不能在If语句中使用它。你会想......

Public Class Customer
    Public Function CustomerInputOK(SomeInput As String) As Boolean
        'Your code here
        Return True 'or False
    End Function
End Class

然后在你的表格中......

Private Sub VerifyInput()
        Dim CustomerInput As String = "Some Input"
        Dim cust As New Customer
        If cust.CustomerInputOK(CustomerInput) Then

        End If
End Sub

答案 1 :(得分:0)

您可以创建CustomerInputOK方法shared

Public Shared Function CustomerInputOK() As Boolean

请注意,它是公开的。 CustomerInputOK需要access modifier允许您的frmMain访问它,例如Friend或Public。

或者,再次按照访问修饰符规则,您可以实例化clsCustomer的实例,然后调用该方法。

Dim objMyInstanceOfCustomerClass As New clsCustomer()

If Not objMyInstanceOfCustomerClass.CustomerInputOK() Then Exit Sub
相关问题