我有一个名为"clsCustomer.vb“的模块,如何在我的主窗体"frmMain”中使用子模块"CustomerInputOk“?我正在尝试通过以下方式进行呼叫:
如果不是CustomerInputOK(),则退出Sub
我尝试为调用添加前缀"clsCustomer.CustomerInputOK()“,但这不起作用。
发布于 2018-06-02 09:26:06
您可以将CustomerInputOK方法设置为shared
Public Shared Function CustomerInputOK() As Boolean请注意,它是公共的。CustomerInputOK需要有一个允许您的frmMain访问它的access modifier,比如Friend或Public。
或者,再次遵循访问修饰符规则,您可以实例化一个clsCustomer实例,然后调用该方法。
Dim objMyInstanceOfCustomerClass As New clsCustomer()
If Not objMyInstanceOfCustomerClass.CustomerInputOK() Then Exit Sub发布于 2018-06-02 13:45:58
如果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 Subhttps://stackoverflow.com/questions/50652621
复制相似问题