PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Getting list number from variable-VBForums
Results 1 to 5 of 5

Thread: Getting list number from variable

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Getting list number from variable

    Code:
    For j = 1 To 12
        For i = 1 To 31
            Randomize
            x = Int(Rnd * 13 + 1)
            winner(j, i) = x
            Listj.AddItem winner(j, i)
        Next i
    Next j
    How can i accomplish adding the numbers to different Listboxes? The number of list depends on the counter of the outer for cycle (So i want to put 31 random numbers to different ListBoxes, e.g. List1, List2, .. List12)

    Edit: Actually if there's a simple way to show these data in a table, that would do it too.

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Getting list number from variable

    Please explain the rules of the game.
    BTW, Randomize should only be called once
    at the beginning of program run, not in a loop.

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,647

    Re: Getting list number from variable

    Code:
    Me.Controls("List" & j).AddItem winner(j, i)

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Getting list number from variable

    Here is a loop that will add odd numbers to listbox1 and even numbers to listbox2:
    vb Code:
    1. For j = 1 To 12
    2.     For i = 1 To 31
    3.         Randomize
    4.         x = Int(Rnd * 13 + 1)
    5.         winner(j, i) = x
    6.         If j / 2 = int(j / 2) Then
    7.             ListjEven.AddItem winner(j, i)
    8.         Else
    9.             ListjOdd.AddItem winner(j, i)
    10.         EndIf
    11.     Next i
    12. Next j
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Re: Getting list number from variable

    Quote Originally Posted by akhileshbc View Post
    Code:
    Me.Controls("List" & j).AddItem winner(j, i)
    Thanks, this one has really worked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width