Solved

Recognising variables in an ActiveX DLL

Posted on 1998-06-20
3
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:trimtrom
ID: 1463859
Edited text of question
0
 
LVL 2

Accepted Solution

by:
Llandr earned 100 total points
ID: 1463860
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
ID: 1463861
OK Thanks: really well expressed answer!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

728 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