Results 1 to 6 of 6

Thread: ocx control on VB form

  1. #1

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290

    Arrow ocx control on VB form

    I have made an OCX combo box control that saves file paths to the registry.

    The way it *should* work is that the SaveSetting uses the current app name as the registry key.

    Instead, the control only picks up its own app name. The control doesn't seem to have any awareness of the form it is called by etc.

    How do I make the control aware of the app in which it is operating?

    Within the OCX project, I want the code to be able to reference the name of the VB project in which it is being used as a component.

  2. #2
    Fanatic Member
    Join Date
    Aug 2001
    Location
    Connecticut
    Posts
    855
    Maybe there's another way, but can't you pass the app name from the parent form on Form_load into a user defined property of the ocx?
    VB 6.0, Access, Sql server, Asp

  3. #3

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    I would like the control to do the job automatically; it's one of those deals where I think there should be A way, but it takes a while to find THE way.

    Currently, I have a user defined property on the control in which I am manually entering the registry key; your way would automate that part, but it is quicker to type the key in than to code to automate it.

    I've been looking for a good book on ActiveX / OCX controls, but I can't find any. Do you have any recommendations?

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Check out Joacim Andersson's reply in this old thread:
    http://www.vbforums.com/showthread.p...hreadid=107707

    That should be what you are looking for.

  5. #5

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290

    Unhappy

    The thread deals with determining the calling program - and it works in that respect. But the value returned is for VB - not for the project in which I am using the control.

    Is there a way to get the project name of the project using the OCX control? Or does that violate the rules of COM?

    Thank you for your input.

  6. #6

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290
    Found this on Planet Source Code, and it works (almost) - it gives the name of the form on which the control is placed. Can you get from the ParentControls to the project name?


    http://www.planet-source-code.com/vb...d=644&lngWId=1

    Code:
    '**************************************
    ' Name: Getting a Reference to a VB 5.0 
    '     UserControl
    ' Description:Visual Basic 5.0 allows yo
    '     u to use UserControls to create ActiveX 
    '     controls in your projects. The following
    '     code snippet does two things: It gets a 
    '     reference to the form in which a UserCon
    '     trol is placed, and it gets a reference 
    '     to that control on the form. by David Me
    '     ndlen
    ' By: Found on the World Wide Web
    '
    '
    ' Inputs:None
    '
    ' Returns:None
    '
    'Assumes:None
    '
    'Side Effects:None
    '**************************************
    
    Dim PControl As Object
    Dim MyControl As Control
    Dim AControl As Object
    'Get my UserControl
    
    
    For Each AControl In ParentControls
          If AControl.Name = Ambient.DisplayName Then
            Set MyControl = AControl
            Exit For
          End If
    Next
    'Get the Form UserControl is on
    Set PControl = ParentControls.Item(1).Parent
    
    
    While Not (TypeOf PControl Is Form)   Set PControl = PControl.Parent
    Wend
    Last edited by billwagnon; Jan 22nd, 2002 at 09:04 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width