• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Recognising variables in an ActiveX DLL

Hello,
I am having a few problems with an ActiveX DLL that I have done (one of my first experiments) with VB5 Professional.

I have created a class (HaroldsClass) in the DLL, in which I instantiate a form, as follows:

Private haroldsform As Form1
Set haroldsform = New Form1

I have placed a commandbutton and a textbox on the form, and attached the following code:

Private Sub CommandOK_Click()
HaroldsClass.NewText = Text1.Text
Unload Me

End Sub

NewText is a public property (Get/Let) of HaroldsClass.

Now I would expect that the Haroldsclass property addressed in HaroldsForm above would be recognised by the form, as the form was itself created in Haroldsclass.  But no matter what I do, I cannot get any of my public Haroldsclass properties recognised within the bounds of the form Haroldsform.

HELP!!  What am I doing wrong??

Anwsers with code much appreciated, please.

TrimTrom
0
trimtrom
Asked:
trimtrom
  • 2
1 Solution
 
trimtromAuthor Commented:
Edited text of question
0
 
LlandrCommented:
It seems to me that what you are doing is confusing a Class and an Object. An object is an instance of a class. This means that you cannot reference methods in the Harrold-class without a specific object there to reference.

This is the way to make it work, note the use of then backreference (is there a better word?):
<-------- code starts --------->

<Module modStart>
Option Explicit

Public Sub Main()
  Dim cls As New CHarroldsClass
 
  cls.DoShow
End Sub

<Class CHarroldsClass>
Option Explicit

Private mText As String
Private mForm As frmHarrlodsForm

Public Property Let NewText(newT As String)
  mText = newT
End Property

Public Property Get NewText() As String
  NewText = mText
End Property

Public Sub DoShow()
  Set mForm = New frmHarrlodsForm
  Set mForm.BackReference = Me
  mForm.Show 1
  MsgBox "New text:" & NewText
End Sub

<Form frmHarrlodsForm>
Option Explicit

Public BackReference As CHarroldsClass


Private Sub cmdSetText_Click()
  BackReference.NewText = txtText
  Hide
End Sub
<------Code ends------------->
0
 
trimtromAuthor Commented:
OK Thanks: really well expressed answer!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now