Solved

Recognising variables in an ActiveX DLL

Posted on 1998-06-20
3
141 Views
Last Modified: 2010-05-03
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
Comment
Question by:trimtrom
  • 2
3 Comments
 

Author Comment

by:trimtrom
Comment Utility
Edited text of question
0
 
LVL 2

Accepted Solution

by:
Llandr earned 100 total points
Comment Utility
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
 

Author Comment

by:trimtrom
Comment Utility
OK Thanks: really well expressed answer!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now