0

I recently have convert my project from VB6 to VB.NET2008, after the convert here is a sub that control form from a module that i create, the error was something like

"cmdAdd is not a member of System.Windows.Forms.Form"

Public Sub ButtonSet(ByRef frmObj As System.Windows.Forms.Form)
    frmObj.cmdAdd.Visible = True
    frmObj.cmdCopy.Visible = True
    frmObj.cmdEdit.Visible = True
    frmObj.cmdCorrection.Visible = True
End Sub

how its call:

Private Sub frmAPNote_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
ButtonSet(Me)
End Sub

1 Answer 1

1

Change the parameter type to YourFormName.

Public Sub ButtonSet(ByRef frmObj As frmAPNote)
    frmObj.cmdAdd.Visible = True
    frmObj.cmdCopy.Visible = True
    frmObj.cmdEdit.Visible = True
    frmObj.cmdCorrection.Visible = True
End Sub

PS: No need to specify ByRef parameter type for objects.

The problem is the sub in the module not only just called by "frmAPNote" but also other form such as "frmARNote" and "frmRTNote"

You may get the reference of a specific control from Form.Controls collection.

Public Sub ButtonSet(ByVal frmObj As Form)
    Dim btnAdd = frmObj.Controls("btnAdd")

    If Not IsNothing(btnAdd) Then
        btnAdd.Visible = False
    End If

    ....
End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

The problem is the sub in the module not only just called by "frmAPNote" but also other form such as "frmARNote" and "frmRTNote".
@monaz g: Then make a base class or interface that they all use, then use that as the type.
Hi jmoreno, that is what i'm trying to do with this sub, can you give example how to do it by using "base class or interface"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.