Results 1 to 7 of 7

Thread: [RESOLVED] Creating Control Arrays During Runtime

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Resolved [RESOLVED] Creating Control Arrays During Runtime

    I am creating a program where there is not necessarily a specific number of items in the menu...I was wondering if there is a specific way of creating a control during runtime... I'll have a minimum of one label... but I just want to make copies of it... but still be able to access them individually...

    I remember seeing something like that... but I couldn't find it in the search... or maybe I am just not typing the correct keyword

    If anyone could help or give me a link to that thread... I'd really appreciate it...

    Khanjan
    Hey... If you found this post helpful please rate it.

  2. #2
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Creating Control Arrays During Runtime

    Create the array in design time, and say the user calls something that needs a new label:
    VB Code:
    1. Load (lblMyLabel(UBound(lblMyLabel + 1)), Label)

    Please note that has not been tested, but it should be close.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Creating Control Arrays During Runtime

    Put one on your form and set it's Index to 0. You can hide it if you want and make it visible if you need just one. After that you Load new ones, making sure you make them visible and moving them where you want them.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: Creating Control Arrays During Runtime

    Well... timeshifter you are close enough... you gave me that hint of the keyword "Load"

    However the prompt I get for the format is ....
    Code:
    Load(Object As Object)
    I enter:
    VB Code:
    1. Private Sub Command1_Click()
    2.        Static intCount As Integer
    3.        intCount = intCount + 1
    4.        Load  (Label1(intUCount) As Label)
    5. End Sub

    I get an error with "As"
    The error is:
    Code:
    Expected: list seperator or )
    I get an error with your code too... at "+"
    For the "+" the error is:

    Code:
    Expected: List Seperator
    Hey... If you found this post helpful please rate it.

  5. #5
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Creating Control Arrays During Runtime

    Have fun making Opbects
    VB Code:
    1. '
    2. ' SESSI4ML  10/10/2006
    3. ' Create Objects...or, create new Objects as the user needs them
    4. '
    5. 'Option Explicit
    6. '
    7. ' VBforums.com ....
    8. '
    9. Private Sub Form_Load()
    10.     Command3.Caption = "Make Objects"
    11.     Command1.Caption = "Single Step"
    12.     Text1.Text = 10
    13. End Sub
    14. Private Sub Command3_Click()
    15.     For a = 1 To Val(Text1.Text)
    16.         Call Command1_Click
    17.     Next
    18. End Sub
    19.  
    20. Private Sub Command1_Click()
    21. ' what is the  object count
    22. ' text1= number of objects to create
    23. '
    24.     intobj = Command2.Count   ' Points to the next Object
    25.        
    26.     Load Command2(intobj)   ' command2 will always default to index 0 for the load
    27.                             ' ready to create new object
    28.                             ' Create new object
    29.     ' Create a new Row
    30.     '
    31.     If intobj / 5 = Int(intobj / 5) Then
    32.         ' Create a new Top for object
    33.         Command2(intobj).Top = Command2(intobj - 1).Top + Command2(intobj).Height + 10
    34.         Command2(intobj).Left = 120     ' Start on Left column
    35.         Command2(intobj).Visible = True
    36.         Command2(intobj).Caption = Command2(intobj).Index
    37.         Exit Sub
    38.     End If
    39.               '
    40.     Command2(intobj).Top = Command2(intobj - 1).Top
    41.     Command2(intobj).Left = Command2(intobj - 1).Left + Command2(intobj - 1).Width + 5
    42.     Command2(intobj).Caption = Command2(intobj).Index
    43.     Command2(intobj).Visible = True
    44.    
    45. End Sub
    46. '

  6. #6
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Creating Control Arrays During Runtime

    Complete Code. The same could be used for Text boxes, Labels, etc...
    Attached Files Attached Files

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    Re: Creating Control Arrays During Runtime

    Sessi4ml
    YOU ARE THE BEST!!!

    I FEEL LIKE JUMPING WITH JOY... THANX A LOT...
    I SHALL RATE YOUR POST FOR SURE...
    Hey... If you found this post helpful please rate it.

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