troubleshooting Question

Programming a VB6 dll (trying to understand class variables)

Avatar of HKComputer
HKComputerFlag for United States of America asked on
Visual Basic Classic
9 Comments1 Solution360 ViewsLast Modified:
I'm trying to program some of my own message box functions and put them in a dll to be used by my other VBScript and VB .exe projects. The first one I am trying to make is a Message Box that can take up to five arguments. The first one will be the message box title. The other 4 will be the caption for each button. The dll function will pass back the caption of the button that was clicked by the user.

So what kind of variables do I need and how do I pass them to the form when I open the form? And how do I pass the value of the clicked button back to the user?

Here's the code I have but it doesn't compile. My class module is named cMsgBoxes. I don't know where to go from here:

Option Explicit

Public strTitle As Variant
Public strcmd1 As Variant
Public strcmd2 As Variant
Public strcmd3 As Variant
Public strcmd4 As Variant
Public strMsgBox As Variant

Public Property Let Title(strTitle As String)
    Title = strTitle
End Property

Public Property Let Command1(strcmd1 As String)
    Command1 = strcmd1
End Property

Public Property Let Command2(strcmd2 As String)
    Command2 = strcmd2
End Property
Public Property Let Command3(strcmd3 As String)
    Command3 = strcmd3
End Property
Public Property Let Command4(strcmd4 As String)
    Command4 = strcmd4
End Property

Function MsgBox4Button(strTitle As String, strcmd1 As String, Optional strcmd2 As String, Optional strcmd3 As String, Optional strcmd4 As String)
    Load frmMsgBox4Button
    MsgBox4Button = strMsgBox
End Property

My Form Code:

Option Explicit

Private Sub cmd1_Click()
    cMsgBoxes.strMsgBox = Me.cmd1.Caption
    Unload Me.Name
End Sub

Private Sub cmd2_Click()
    cMsgBoxes.strMsgBox = Me.cmd2.Caption
    Unload Me.Name
End Sub

Private Sub cmd3_Click()
    cMsgBoxes.strMsgBox = Me.cmd3.Caption
    Unload Me.Name
End Sub

Private Sub cmd4_Click()
    cMsgBoxes.strMsgBox = Me.cmd4.Caption
    Unload Me.Name
End Sub

Private Sub Form_Load()
    Me.Caption = strTitle
    Me.cmd1.Caption = Trim(strcmd1)
    Me.cmd2.Caption = Trim(strcmd2)
    Me.cmd3.Caption = Trim(strcmd3)
    Me.cmd4.Caption = Trim(strcmd4)
    If Nz(Me.cmd1.Caption, "") = "" Then
        Me.cmd1.Visible = False
        Unload Me.Name
    End If
    If Nz(Me.cmd2.Caption, "") = "" Then Me.cmd2.Visible = False
    If Nz(Me.cmd3.Caption, "") = "" Then Me.cmd3.Visible = False
    If Nz(Me.cmd4.Caption, "") = "" Then Me.cmd4.Visible = False
End Sub

Private Function Nz(strValue As Variant, strChangeTo As String) As String
    If Not IsNull(strChangeTo) Then
        If strValue = Null Then strValue = strChangeTo
    End If
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros