Results 1 to 5 of 5

Thread: Creating ... controls

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Hi PPL!


    i was so thrilled with the fact that i finally knew how to write code for the control being created in the future with the vb.controls.add, using the withEvents function, but my happyness dyed soon cause what i need to do is not only program for one or two controls, say labels, but for say 30 labels, i tryed to make an array with WithEvents, but it's not possible, any suggestion?

    Thanks guys!

  2. #2
    Guest
    If you start off with a Label, with an index of 0, you can create replicas.

    Code:
    Public ReplicaLabel(1 to 30) As New Label1
    
    Private Sub Form_Load()
    'Whenever you need one simply do this.
    
    Load ReplicaLabel(1) ' or whatever number.
    
    With ReplicaLabel
     .Top = 0
     .Left = 0
     .Visible = True
    End With
    
    End Sub
    That code also works for any object, like forms, except MDI forms I think.

    Just be careful though, if you try to load a replica twice the program will give the error 'Object already loaded.'

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Thankx DreamLax!

    But theres something i don't know either! I want the user to create the labels he or she wants, but i want to write code for each label that could be added, say label has one behaviour the second a different behaviour! The thing is since i have to this with many other different controls i would like to find now a way to write code without using WithEvents for each of the 80 possible controls to be added!

    Thanks for the help!

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If you want to write the code you could just write your 80 subs and then call whatever sub from the click on whatever control you wish to use.
    example:
    Code:
    Option Explicit
    
    Public Sub sub0()
        MsgBox "zero"
    End Sub
    
    Public Sub sub1()
       MsgBox "one"
    End Sub
     
    Public Sub sub2()
       MsgBox "Two"
    End Sub
    
    Public Sub sub3()
        MsgBox "Three"
    End Sub
      
    Private Sub Form_Load()
    
    'load an array of controls at runtime
    Dim intcre As Integer
    
    Do Until intcre = 3
        intcre = intcre + 1
        Load Label1(intcre)
        Label1(intcre).Left = Label1(0).Left
        Label1(intcre).Top = Label1(intcre - 1).Top + Label1(0).Height + 100
        Label1(intcre).Visible = True
        
    Loop
    
    End Sub
    
    Private Sub Label1_Click(Index As Integer)
        Select Case Index
        Case 0
          Call sub0
        Case 1
          Call sub1
        Case 2
          Call sub2
        Case 3
          Call sub3
        End Select
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Also, consider this. If you have a finite number of label styles, you can always hide the type of the label in the Tag property of the label. IE: Label1(0).Tag = "IPLABEL". Then, you can specify the events you need for each specific style. You can possibly even use CallByName to call specific functions based on that tag:
    Code:
        CallByName Me, Label1(X).Tag & "_MouseDown", _
                   VbMethod, Button, Shift, X, Y
    Keep in mind that methods/properties called by CallByName must be Public for them to be used.

    This way could kill off a select statement, but would give pause to the number of functions available outside of your control.

    Hope this gives you some ideas.
    -Excalibur

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