Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Is it possible to dynamically create Collections in VB6?

Is it possible to dynamically create Collections in VB6?

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    suguimoto
    wrote on last edited by
    #1

    Hello! Does anyone know if it's possible to dynamically create Collections in VB6? I wanted to dynamically create as many Collections as the user needs/wants. Just like TextBox1(0), TextBox1(1), and so on. Is it possible? Regards

    T P 2 Replies Last reply
    0
    • S suguimoto

      Hello! Does anyone know if it's possible to dynamically create Collections in VB6? I wanted to dynamically create as many Collections as the user needs/wants. Just like TextBox1(0), TextBox1(1), and so on. Is it possible? Regards

      T Offline
      T Offline
      Thomas Krojer
      wrote on last edited by
      #2

      yes. Dim x(13) As New Collection x(1).Add "1,1" x(1).Add "1,2" x(2).Add "2,1" x(3).Add "3,1" Debug.Print x(1).Item(1) Debug.Print x(3).Item(1) it´s also possible to do this dynamically: Dim x() As New Collection ReDim x(13) x(1).Add "1,1" x(1).Add "1,2" x(2).Add "2,1" x(3).Add "3,1" ReDim Preserve x(17) x(17).Add "17,1" Debug.Print x(1).Item(1) Debug.Print x(17).Item(1)

      S 1 Reply Last reply
      0
      • S suguimoto

        Hello! Does anyone know if it's possible to dynamically create Collections in VB6? I wanted to dynamically create as many Collections as the user needs/wants. Just like TextBox1(0), TextBox1(1), and so on. Is it possible? Regards

        P Offline
        P Offline
        parth p
        wrote on last edited by
        #3

        Or simple way of doing it is, Changing Index to 0 for the component in Properties Window. For Example, Add & Select Text1, and goto Properties and in Index type 0. Now when you want to create new one's just use following code, it's much simple. Private Sub LoadTextBox() 'Get the number of Textbox User wants or needs Dim itext As Integer itext = InputBox("Enter how many text box you want") 'Now let's create and show them on form Dim i As Integer For i = 1 To itext Load Text1(i) Text1(i).Visible = True 'the lines below show new created textbox rightBelow eachother, like Table Text1(i).Left = Text1(0).Left Text1(i).Top = Text1(i - 1).Top + Text1(i - 1).Height Next i End Sub Hope it helps...

        S 1 Reply Last reply
        0
        • P parth p

          Or simple way of doing it is, Changing Index to 0 for the component in Properties Window. For Example, Add & Select Text1, and goto Properties and in Index type 0. Now when you want to create new one's just use following code, it's much simple. Private Sub LoadTextBox() 'Get the number of Textbox User wants or needs Dim itext As Integer itext = InputBox("Enter how many text box you want") 'Now let's create and show them on form Dim i As Integer For i = 1 To itext Load Text1(i) Text1(i).Visible = True 'the lines below show new created textbox rightBelow eachother, like Table Text1(i).Left = Text1(0).Left Text1(i).Top = Text1(i - 1).Top + Text1(i - 1).Height Next i End Sub Hope it helps...

          S Offline
          S Offline
          suguimoto
          wrote on last edited by
          #4

          Hi! Thank you very much for replying! Best Regards

          1 Reply Last reply
          0
          • T Thomas Krojer

            yes. Dim x(13) As New Collection x(1).Add "1,1" x(1).Add "1,2" x(2).Add "2,1" x(3).Add "3,1" Debug.Print x(1).Item(1) Debug.Print x(3).Item(1) it´s also possible to do this dynamically: Dim x() As New Collection ReDim x(13) x(1).Add "1,1" x(1).Add "1,2" x(2).Add "2,1" x(3).Add "3,1" ReDim Preserve x(17) x(17).Add "17,1" Debug.Print x(1).Item(1) Debug.Print x(17).Item(1)

            S Offline
            S Offline
            suguimoto
            wrote on last edited by
            #5

            Hi Thomas, Thank you very much! I declared in a module Public m_Collection() As Collection And in my form: (i needed to "Set" in order to work) Private Sub Command1_Click() For i = 0 To 13 Set m_Collection(i) = New Collection m_Collection(i).Add "1234" Next i End Sub It work perfectly :) Thanks! Best Regards!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups