Results 1 to 5 of 5

Thread: [RESOLVED] Control Arrays, Anyone?

  1. #1

    Thread Starter
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Resolved [RESOLVED] Control Arrays, Anyone?

    I need to know how to make a control array in the Form_Load() sub routine. I am trying to make a platform game that is totally random in fact, that nothing is similar in each execution of the program.

    So far I have this as my source code:
    Code:
    Dim i as Integer
    
    Public Sub Form_Load()
    For i = 0 to 99
    
    End Sub
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Control Arrays, Anyone?

    Try looking at this FAQ, post #3. Also, searching the forums for control arrays will return so many examples.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Control Arrays, Anyone?

    The easiest way would be to just add a control (example, a PictureBox) to the form and set its Index property to 0. Then you could have something like:

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.    
    5.     Dim i As Integer
    6.    
    7.     For i = 1 To 99
    8.         Load Picture1(i)
    9.         Picture1(i).Move i * Picture1(i).Width, 100
    10.         Picture1(i).Visible = True
    11.     Next i
    12.    
    13. End Sub
    14.  
    15. Private Sub Form_Unload(Cancel As Integer)
    16.    
    17.     Dim i As Integer
    18.    
    19.     For i = 1 To Picture1.UBound
    20.         Unload Picture1(i)
    21.     Next i
    22.    
    23. End Sub

  4. #4

    Thread Starter
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,948

    Re: Control Arrays, Anyone?

    How can I get the PictureBox control array to only move a random control in the array, into another position without disrupting all the rest.

    eg:
    Picture1(1).Top = "100"
    Picture1(2).Top = "0"
    Picture1(3).Top = "100"
    And so on.

    Also I don't wish this to only be one of them. But a randomly determined number of them, in fact.
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Love Shack | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University | Ambra Cheese |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

  5. #5
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Control Arrays, Anyone?

    Generate a random number to determine which control to move. Here is some code that doesn't quite do that, but should show you enough to get you there (I think). Start a project and put a picture box on the form. Call it "pb," and give it an index of 0 as mentioned earlier.

    After the form loads, double click it to re-gen.

    Code:
    Option Explicit
    
    Private Sub Form_DblClick()
        Call randGen
    End Sub
    
    Private Sub randGen()
        Dim myRand As Integer
        Dim randLeft As Integer
        Dim randTop As Integer
        Dim i As Integer
        Randomize
        myRand = Int((99 - 1 + 1) * Rnd + 1)    'generates random number between 1 and 99
        For i = 1 To myRand
            randLeft = Int((Me.ScaleWidth - pb(0).Width - 1 + 1) * Rnd + 1)
            randTop = Int((Me.ScaleHeight - pb(0).Height - 1 + 1) * Rnd + 1)
            On Error Resume Next
            Load pb(i)
            pb(i).Left = randLeft
            pb(i).Top = randTop
            pb(i).Visible = True
        Next i
        Me.Caption = myRand
    End Sub
    
    Private Sub Form_Load()
        Call randGen
    End Sub

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