?
Solved

Recognising variables in an ActiveX DLL

Posted on 1998-06-20
3
Medium Priority
?
153 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 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