Results 1 to 9 of 9

Thread: [RESOLVED] Dynamically adding and removing RTB control

  1. #1

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Resolved [RESOLVED] Dynamically adding and removing RTB control

    Hello,

    I think the subject said it all. So, is it possible??

    Thank you.
    Show Appreciation. Rate Posts.

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

    Re: Dynamically adding and removing RTB control

    make sure that RichTextBox is in the components list.

    uncheck "Remove information about unused activeX controls" in the 'Make' tab of the project properties.

    then it's just a case of doing:
    VB Code:
    1. Private WithEvents rtb As RichTextLib.RichTextBox
    2.  
    3. Private Sub Form_Load()
    4.     Set rtb = Me.Controls.Add("RICHTEXT.RichTextCtrl.1", "RichTextBox1")
    5.     rtb.Visible = True
    6. End Sub

  3. #3

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Dynamically adding and removing RTB control

    Thank you so much!!

    BTW, what is the significance of .1 in the Add function??
    Show Appreciation. Rate Posts.

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

    Re: Dynamically adding and removing RTB control

    Quote Originally Posted by Harsh Gupta
    Thank you so much!!

    BTW, what is the significance of .1 in the Add function??
    no probs

    i don't think there's any significance, it's just the ProgId.

    do:
    VB Code:
    1. Set rtb = Me.Controls.Add("RichTextLib.RichTextBox", "rtb")
    and you'll see what I mean.

  5. #5

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Dynamically adding and removing RTB control

    Ok, did a bit of RnD on ProgID. Searched the Reg Editor and noticed that almost all controls we use, the Reg Edit. has 2 ProgIDs, one with .1 and another without .1 but both having same CLSID, and further digging into the CLSID revealed that the ID with .1 has a Key [VersionIndependentProgID], its value being the ProgID without .1.

    From ProgID on VBAccelerator
    When you request an instance of the cFlatControl class, COM looks up the ProgID "vbalFCtl.cFlatControl" which gives it the GUID of the object. COM can then locate the GUID and therefore the path to the object. This is where the problem arises with two objects with the same ProgID. If you create a new version of the Flat Control DLL, say it either has with different methods or it is compiled in VB6 instead of VB5, you will automatically generate a new GUID. However, if you don't change either the project name or the class name, you will overwrite the existing ProgID with your own version. Anyone else's code which expects to get an instance of the object suddenly gets routed to the new version, and their code may then fail depending on what you've done to the existing class.
    Talking about RichTextLib.RichTextBox, if I make my own version of RTB and name it RichTextLib.RichTextBox.2, then will it:

    1) Generate a new progID? or

    2) Overwrite the old progID (i.e. overwrite the RichTextLib.RichTextBox.1)? or

    3) Rest in harmony with the default two?

    Thank you.
    Show Appreciation. Rate Posts.

  6. #6

  7. #7

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Dynamically adding and removing RTB control

    Quote Originally Posted by MartinLiss
    This FAQ will also help.
    Sorry, but the link said nothing about the ProgID concept!!

    I have the answer to my original question. There is something related to it that I haven't understood.
    Show Appreciation. Rate Posts.

  8. #8
    New Member
    Join Date
    Oct 2006
    Posts
    3

    Re: Dynamically adding and removing RTB control

    Most times the easiest way to dyanamically create and get rid of controls at run time is to create a control array. You can do this by simple copying as pasting a copy of the control on the form. then you can delete the extra one. This sets up an array of controls that can be created with the load statement. Then you assign properties to the new control.

    load some_control(index number)
    With some_control(index number)
    .Top = 300
    .Left = 500
    .Text = "Some Text"
    End With

    Hope this helped

  9. #9

    Thread Starter
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Dynamically adding and removing RTB control

    hmmf....I shall mark this thread resolved and ask the second question in GD section.
    Show Appreciation. Rate Posts.

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