Results 1 to 5 of 5

Thread: New Text Object Class

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Hi,

    A problem with the textbox class. Add a class to a vb project called CText and enter this code.

    Public Sub Add()
    Dim newText As TextBox
    Set newText = Controls.Add("VB.Textbox", "newText")
    With newText
    .Visible = True
    .Text = "&Dynamically Added Button"
    .Top = 0
    .Left = 0
    .Width = 2400
    .Height = 500
    End With
    End Sub

    And then add a form. On the form add this.

    Dim nObj As New CText

    Public Sub Form_Load()
    nObj.Add
    End Sub


    When irun the project vb gives me an error 424, object required, why does this not work ?

    [Edited by PsyVision on 11-23-2000 at 01:58 PM]

  2. #2
    Addicted Member darrenl's Avatar
    Join Date
    Jul 2000
    Location
    Portsmouth, UK
    Posts
    148
    simply because "Controls" is out of context, it belongs to the form not the class module. Try passing a reference to the form in your class and use that to add controls.

    [code]
    Public Sub Add(Form As Object)
    Dim newText As TextBox
    Set newText = Form.Controls.Add("VB.Textbox", "newText")
    With newText
    .Visible = True
    .Text = "&Dynamically Added Button"
    .Top = 0
    .Left = 0
    .Width = 2400
    .Height = 500
    End With
    End Sub


    [\code]
    Dazzer

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Cheers, m8 that will help loads in my scripting language.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Is there any way to have an array of these. i tried Dim newText(10) as textbox but it says not a legal object name, then setting .index value gives me an error.

  5. #5
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can't create control arrays at runtime, although you can create an array of controls, but in that case you can't receive the event of each of them without using a trick with classes and classcollections.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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