Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Object VHow do you reference a user control? (VB6)

    This may be where i'm going wrong with my handles question, but how do you reference a User Control?

    I'm trying to convert an Exe project into an OCX so my user control is called FrmMain and it opens forms within it. If I try and reference frmMain from one of these forms I get either get Variable not defined on frmMain or Object Variable or With Block Variable not set. if I dim a variable as frmMain i.e.

    Dim A As frmMain
    A.text1.enabled = false

    Any ideas where i'm going wrong? Any help would be much appreciated.
    Regards,

    i.e. frmmain.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Object VHow do you reference a user control? (VB6)

    Try dimming the variable as New frmMain. Otherwise, you dim the variable but you haven't instantiated it, so the reference to it's control won't work.
    Charlotte

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object VHow do you reference a user control? (VB6)

    If I add the new Keyword in I get Invalid use of New Keyword.

    I'm also having a load of other problems with it as the original app uses CommandBars which don't seem to be part of a user control (makes sense as they should be in the main app), but i've currently only just started looking at that - however, it's making me think I may need to approach the whole thing from a different angle!

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Object VHow do you reference a user control? (VB6)

    Then try the long way

    Dim A as frmMain
    Set A = New frmMain

    I use VB.Net now and the syntax is different, so I may have forgotten the exact syntax, but the idea is that just declaring the variable doesn't create an instance of it. You have to assign an instance to the variable. The exact syntax will depend on how your class was built. It may have an Initialize method you have to use to create an instance of it, and I can't remember if the Set keyword is needed in VB6 or not. It is history in VB.Net, so I'm out of the habit of using it. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>
    Charlotte

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Object VHow do you reference a user control? (VB6)

    <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15> I just reread your original post. What do you mean about frmMain containing other forms? The declaration and what you can do with it depends on the interface of the class. Usually a usercontrol has an object interface with methods and properties, not a bunch of other forms. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    Charlotte

  6. #6
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object VHow do you reference a user control? (VB6)

    It might help if I explained the control a bit better. We have a couple of products, 1 access based, 1 VB based. Until we can phase out the access one we are trying to program the various chunks of our program in user controls that we can just drop in the main app whatever the version.

    The main app contains various areas such as Account records, Reports, Sales, and in the case of the one i'm creating, Data. The Data area is where the user can select specific establishments from the full list, mailsort the data (a UK postal thingy), export the data etc.

    I am currently trying out the CodeJock frames component and as I'm not a fan of putting controls on top of each other at design time anyway (I find it easier to change the handle to make things appear where I want them) the result is that I have my user control with all of the CodeJock frame stuff on it, then a load of forms containing all of the other screens that need to be displayed. There will probably also be some popup forms and things like that.

    Based on some of the add in components i've seen that are available I didn't realise this was improper use of making an ocx. Any tips you can give me for creating such a large chunk of a program as a component would be much appreciated.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Object VHow do you reference a user control? (VB6)

    Sorry, I'm out of my depth here. I do this in VB.Net, so I'm just likely to mislead you in VB. I didn't say it was an improper use, but what you're describing sounds more like an add-in than a user control. Semantics, really, but I think of a user control as an object that contains a unified set of operations with a single interface. A form, for instance, that you can drop into an application. That isn't a restriction, just the way I develop.
    Charlotte

  8. #8
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object VHow do you reference a user control? (VB6)

    I've only ever built stand alone apps so this is my first "add in" or whatever you may want to term it. I haven't yet had the time to delve into the world of .Net but i'm planning on this being my last big VB project before I take the plunge. I would attempt this one in .Net as I've read you can put .Net components into a VB6 app, but I have time constraints to consider so I don't think it'll be possible.

    Not to worry. Due to some other application constraints I think i'm going to have to split it up into smaller components anyway.

  9. #9
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object VHow do you reference a user control? (VB6)

    Unfortunately i'm back to struggling with this.

    I have attached a demo app. If you run the ocx from VB i'd like to press the button, open form1, edit text1, press the button and have the contents of text1 write back to the text box on the usercontrol object.

    Any help would be much appreciated or is it really the case that an OCX should not use forms?

  10. #10
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object VHow do you reference a user control? (VB6)

    Found it!

    You have to:
    declare an object as a variable on the sub form i.e. public T1 as textbox
    set the object on the sub form as the object on the user control i.e. set form1.textbox = textbox
    then open the sub form
    changing T1 then changes textbox on the user control as its referenced ByRef.

    Obvious now I know, but it took me ages to work it out.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Object VHow do you reference a user control? (VB6)

    Thanks for posting the solution, it may be useful to others.

    (I apologize for the lack of replies - VB6 help is thin on the ground in Woody's Lounge, most people here do Office VBA or have moved on to .Net)

  12. #12
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Object VHow do you reference a user control? (VB6)

    Unfortunately, from a job role point of view at least, upgrading to .Net will involve me getting a new job. Bummer.

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Object VHow do you reference a user control? (VB6)

    I don't want to turn you away from Woody's Lounge, but you might have better luck in discussion forums geared towards VB6 development. If you search Google for vb6 discussion forum you'll find lots of them.

Posting Permissions

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