Results 1 to 12 of 12

Thread: [RESOLVED] Loading a new control onto form

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Resolved [RESOLVED] Loading a new control onto form

    Now I *know* how to load a new control if I already have an instance of that control on the form...question is can I load a control onto a form if there isn't already one. For instance, I made that tab thing that shows tabs like in FireFox and places them equally at the top of the screen. I am now working on unloading the tabs, but I can't unload the first tab as it was added at design time thus the error is "can't unload controls created at design time"

    My question basically is HOW do I create the first object in a control array at runtime, and is it possible? If not, I know I can just hide array object (0) and work from that :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Loading a new control onto form

    You may use Controls collection:
    VB Code:
    1. Dim txt As Textbox 'or declare it as Control
    2.  
    3. Set txt = Me.Controls.Add("VB.Textbox", "txtTemp")
    4. With txt
    5.     .Text = "Hi. I am new here"
    6.     .Move 300, 500 'or whatever plus you may set Height/Width as well
    7.     .Visible = True
    8. End With
    9.  
    10. 'to delete control that was added using controls collection use Remove method:
    11. Me.Controls.Remove "txtTemp"
    NOTE: technic from the above sample will require lisense for any non intrinsic control (Intrinsic controls are those that are built into VB and always appear as default controls set: command button, textbox, etc, etc, etc...).

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Loading a new control onto form

    You can also declare the object WithEvents and then access all the events associated with an object of that type:
    VB Code:
    1. Private WithEvents txt As Textbox
    2.  
    3. Private Sub txt_Change()
    4.  
    5. End Sub

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Loading a new control onto form

    In VB6 adding control through controls collection and also declaring it using WithEvents keyword isn't as flexible as it may look and that is the reason I've decided not to use it in my sample.
    But it is important to know that this feature exist.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Loading a new control onto form

    Rhino's code seems to work okay...I'm having problems trying to convert the OptionButton to graphical though, and I get the feeling I might have to rewrite whole blocks of code to get this to work with the other stuff I did. I might just hide (0) and use 1+ :-)

    Also, using the WithEvents, I am assuming I can't use a control array like I need to, or if I can it won't be as flexible as I'd like it to be
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Loading a new control onto form

    Quote Originally Posted by RhinoBull
    In VB6 adding control through controls collection and also declaring it using WithEvents keyword isn't as flexible as it may look and that is the reason I've decided not to use it in my sample.
    But it is important to know that this feature exist.
    I mentioned it only for completeness and the fact that some dynamic controls would be pointless without it.

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Loading a new control onto form

    Quote Originally Posted by smUX
    ...Also, using the WithEvents, I am assuming I can't use a control array like I need to, or if I can it won't be as flexible as I'd like it to be
    No, you cannot create control array using the Add method - only Load allows this and at least one element MUST be created at design time.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Loading a new control onto form

    Quote Originally Posted by RhinoBull
    No, you cannot create control array using the Add method - only Load allows this and at least one element MUST be created at design time.
    Too bad...Guess I'll stick with the original jerry-rigging I am so good at :-)

    I'm chucking (0) away where it can't be seen and writing it so the program loads 1-2 on runtime and works from there :-)

    Currently I have it adding array items and deleting them dynamically (so it can delete one in the middle and when you add a new one it takes up a free space that was made by deleting one)

    I think my next project for this is multi-row tabs :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Loading a new control onto form

    Well bugger me sideways, it works :-)

    I've attached the most recent version...clicking tabs now deletes them (just to show that they can be deleted) and as I said above, they are dynamically reassigned new index numbers so there shouldn't be any problems with clashing indexes or anything :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: [RESOLVED] Loading a new control onto form

    Rhino, you mention non-intrinsic controls requiring something extra if I wanted to load new instances of them...exactly what do I do?
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  11. #11
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] Loading a new control onto form

    For each non-intrinsic control you will have to add a license.
    Look up MSDN for Licenses Collection but in a nutshell it's painfull and not a good idea.
    Better approach (by far) is to add control to your form in design and use control array if you need more than one instance.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: [RESOLVED] Loading a new control onto form

    Yeah, I'm doing that...I thought that was what I would need for this too...I have a webbrowser (yeah, trying to copy firefox :-)) and I am using load wb(x) (wb is the name I am using, and x is 1 in this case...there's a wb(0) already available)

    However, the error is "Property let procedure not defined and property get procedure did not return an object"

    Edit: Ignore...showing my noobishness...forgot to make the original index 0 :-)
    Last edited by smUX; Jun 11th, 2006 at 08:06 PM.
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

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