borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Diff. between ActiveX exe and ActiveX DLL)Next Topic (ActiveX  DLL) New Topic New Poll Post Reply
AndreaVB Forum : ActiveX : Communicate between ActiveX forms & usercontrol????
Poster Message
orgdoctor
Level: Guest


icon Communicate between ActiveX forms & usercontrol????

After 3 days of trying every permutation, I give up. I need help. I have an ActiveX control consisting of a usercontrol interface and several forms, created using VB6. The usercontrol has a number of command buttons which, when clicked, load and display the respective forms they are linked to. After working with the form, the user clicks a "Done" button to get back to the "command center" at the usercontrol interface (which has been residing underneath the form that was being used).

Here's the problem: I want to invoke a procedure in the usercontrol that changes its display fields according to the data entered on whatever form was being used. I have a "Startup" procedure in the usercontrol to do this. However, no matter what I've tried in order to invoke the Startup procedure from the form, it doesn't recognize any object name I use to refer to the usercontrol. I always get an "error 424, object required", or "object variable ... not set".

Here are the references I've tried unsuccessfully:
       (the name of the usercontrol within the
        activex object is ACC; the name given to
        the whole control when it is instantiated
        within its container program is ACC1; the
        name of the procedure in the usercontrol
        I want to access is "Startup")

        ACC.Startup
        ACC1.Startup
        ContainerName.ACC.Startup
        ContainerName.ACC1.Startup
        usercontrol.Startup
        ActiveXControlName.ACC.Startup
        ActiveXControlName.ACC1.Startup
     And all remotely plausible combinations of the above.

I've tried to declare ACC and ACC1 as public instances of usercontrol and of each other (in a separate module I included in the control for all public declarations.)

You should also know that when I invoke the usercontrol from the container vb6 program, using "Call ACC1.Startup", it invariably starts up with no problem. The problem arises in trying to call back to the usercontrol once you're in one of the forms.

I'm out of things to try. I would be most grateful for any help you all can provide.

17-02-2004 at 03:45 AM
| Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Communicate between ActiveX forms & usercontrol????

Hi orgDoctor, welcome to Andreavb/forum. I'm not sure if I fully understand your problem so please post back if I am wrong.

From what I understand, you want your Usercontrol to update itself with the values entered in any of the forms it displays upon return. Here is one way of doing it. You will have to use the forms like classes. Here goes:

In this example, I will assume we have a form called frmOrgDoctor which has 3 fields "LoginName", "PassWord" and a boolean "IsAdmin". Here is the code to invoke the form.

Dim frm As frmOrgDoctor
Set frm = New frmOrgDoctor
frm.Show vbModal
Me.lblLoginName = frm.LoginName
Me.lblPassword = "Go away, I will not tell you the password is " & frm.Password
Me.lblIsAdmin = IIf(frm.IsAdmin = True, "True", "False")
Set frm = Nothing


Inside the form you set the different fields as follows.

Private strLoginName as String, strPassword as String
Private bIsAdmin as Boolean
'...whatever code and upon closing this:
Private Sub Form_Unload(Cancel As Integer)
  'whatever other code
  strLoginName = txtLoginName.Text
  strPassword = txtPassword.Text
  bIsAdmin = (chkAdmin.Checked = True)
End Sub

'and to return the values use property procedures
Public Property Get LoginName() As String
  LoginName = strLoginName
End Property

Public Property Get Password() As String
  Password = strPassword
End Property

Public Property Get IsAdmin() As Boolean
  IsAdmin = bIsAdmin
End Property


I hope this answers your question. Happy coding.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

17-02-2004 at 04:56 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
orgdoctor
Level: Guest

icon Re: Communicate between ActiveX forms & usercontrol????

Fabulous,

Thanks so much for your reply. That's a clever way of getting variable values into the usercontrol. I'll make use of it, but unfortunately it doesn't solve my problem.

What I need to happen is for the form to either raise an event in the container or in the usercontrol, or directly call a procedure in the container or in the usercontrol. Whatever procedure is invoked will use the new property values to make changes in the information displayed and update a number of other variables in the usercontrol. If the form raises an event or calls a procedure in the container, that event/procedure will set a flag and call the "Startup" procedure in the usercontrol. This is what is stumping me: I can't seem to invoke any event/procedure outside a form from within the form (referring here to forms WITHIN the ActiveX control).

I didn't mention in my first post that I tried setting a public event in the form and then doing a RaiseEvent. I tried putting the event (i.e., a sub procedure) in both the container and in the usercontrol, and neither worked.

It sounds like you might be one of the few people around who can help me figure this out. It seems like a critical capability for ActiveX forms to have. If I can get a solution to this, I'll be able to transform an entire desktop technical application to an .OCX and implement it on the web. If you want to email me directly on this, you can use jkane@alliant.edu.

Thanks again for your suggestion. I hope you'll take another stab at this.

Jeff

17-02-2004 at 05:30 AM
| Quote Reply
fabulous
Level: VB Guru


Registered: 03-08-2002
Posts: 439
icon Re: Communicate between ActiveX forms & usercontrol????

Try it this way.

'inside the form
Public Event LoginNameChanged(Byval NewName As String)
'...somewhere else
RaiseEvent LoginNameChanged(strNewName)


To get events from the form you will have to do this in an instance module, i.e a UserControl, Form or class module:

Private WithEvents frm As frmLogin
'...somewhere
Private Sub frm_LoginNameChanged(Byval NewName As String)
'dosomething
End Sub


To get events, the form will have to be declared at module level in an instance module type and will need to have the WithEvents keyword spedified. I hope this helps.

P.S, there are a lot of us that can help. Happy coding.

____________________________
My boss is a Jewish Carpenter (Jesus Christ)


Brain Bench Certified VB.NET Developer

17-02-2004 at 06:01 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : ActiveX : Communicate between ActiveX forms & usercontrol????
Previous Topic (Diff. between ActiveX exe and ActiveX DLL)Next Topic (ActiveX  DLL) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder