HOW DO I KEEP AN ARRAYLIST IN RANDOM ORDER AFTER EXITING THE SUB ROUTINE CONTAINING IT

PLEASE HELP!I am trying to go from VB4 which I loved to VB2010 which I find somewhat more challenging. I’ve searched the web for help and have adapted the following to my project. This code does
rotate randomly through every card in the deck and displays unique cards until all have been drawn. BUT I want to draw one card
only from the first “hat” of Boy’s names; then draw the second card from the second “hat” of Girl’s names and repeat this process until all cards in both decks have been drawn. How do I get the TextBox (OR any
MsgBox) to display JUST ONE unique random card at a time so I can exit that deck and go to the next deck?
On my form, I have two TextBoxes (to display the names (as drawn), two buttons (to re-load each deck once exhausted) and one command (&End)control (to end the process). I created two ArraysLists
(to hold the Boys names and Girls names separately) and two ArrayLists to hold the cards for the random decks when created in code.
I can
NOT get this code to draw random UNIQUE names once I exit the deck. I have tried to ReDim the deck; randomly pull a card from the second (temp) deck, etc
NOTHING seems to work.
WHY does my deck lose randomness once I exit it?
How can I fix it? I don’t understand this. Below is the code for the "hat" with the 10 girl's names.
Also, when I don't loop through all the cards, I usually get "An Out of Index exception was not handled" error. Hope someone can help me with this problem. It seems like this should
be easy BUT I'm baffled. Thank you for any help.
Imports System.Collections.Generic
Public Class Form1
Dim Count As Integer
Dim Rcard As New ArrayList
Dim Dcard As New ArrayList
Dim NewRDeck As New ArrayList
Dim NewDDeck As New ArrayList
Dim temp_Rnum As Integer
Dim temp_Dnum As Integer
Dim MyRand As New Random()
Public Sub Rcards_Click(sender As Object, e As System.EventArgs) Handles Rcards.Click
While Rcard.Count > 0
Dim temp_Rnum As Integer = Int(MyRand.Next(Rcard.Count))
NewRDeck(temp_Rnum) = Rcard(temp_Rnum)
Rem Check that the ArrayLists work correctly and display properly
MsgBox(Rcard(temp_Rnum), , "New random card selected is: ")
Console.WriteLine(Rcard(temp_Rnum))
Rcard.Text = (Rcard(temp_Rnum))
REM Now remove the Rcard with the random number generated so it can't be drawn again
Rcard.RemoveAt(temp_Rnum)
End While
REM When all 10 cards have been picked, alert player to re-load deck if desired.
MsgBox("No new cards left in deck; please Re-Load the cards. Thank you.")
EndSub
End Class

Hi Acamar,
Thank you for such a fast response. Sorry if my text wasn't clear. I'm really struggling with creating unique random elements in Collections in VB2010 and feel I understand ArrayLists better than some of the other Collection types.The code works perfectly
and generates unique random cards until the original deck is exhausted. Then it prompts the user to re-load the original deck so it can be reused if needed. But I need to draw one card only and exit the deck. Then when I click on the TextBox again, I want
that deck to be in the same random order - just minus any cards I have already drawn and thrown away.  Thanks again for your help.
Here's the rest of the code for just the girl's "hats" of names, if it helps:
Private Sub btnShuffleRCards_Click(sender
As System.Object, e
As System.EventArgs)
Handles btnShuffleRCards.Click
Dim j As
Integer
For j = 1 To 10
NewRDeck.Add(j)
Next j
Randomize()
REM Create original Deck with names for the girls.
Rcard.Add("1 HELEN”)
Rcard.Add("2 OLIVIA")
Rcard.Add("3 <st1:city w:st="on"><st1:place w:st="on">ALICE</st1:place></st1:city>")
Rcard.Add("4 VALERIE")
Rcard.Add("5 DONNA")
Rcard.Add("6 ZELDA")
Rcard.Add("7 MARGARIE")
Rcard.Add("8 <st1:city w:st="on"><st1:place w:st="on">NANCY</st1:place></st1:city>")
Rcard.Add("9 WANDA")
Rcard.Add("10 IRENE")
End Sub

Similar Messages

  • HT4061 How do I keep photos in alpha-numerical order when syncing them from my laptop?

    How do I keep photos in alpha-numerical order when syncing them from my laptop?

    Read this: http://support.apple.com/kb/HT4221

  • HOW DO I KEEP MY VOLUME BUTTON FROM LOCKING UP ALL THE TIME?

    HOW DO I KEEP MY VOLUME BUTTON FROM LOCKING UP ALL THE TIME? I UNDID IT ONCE BEFORE BUT CAN'T KEEP IT FROM HAPPENING.

    Cajuntwin2
    *Tip: ALL CAPS = SHOUTING*
    You don't tell us what year model MBP you have. Also, there is no such thing as iOS 10.9.5, but there is Mac OS X 10.9.5 Mavericks. In addition to that, tell what you mean exactly by "... locking up all the time..." and What you Did exactly when you "... undid it once before..."
    ÇÇÇ

  • In downloading my Events from iPhoto on my Mac to my iPad Air, the Events arrive in the proper order but not showing the Key Photo.  At the same time, the Events arrive in iPhoto on the iPad in totally random order but showing the Key Photo.Why?

    In downloading my Events from iPhoto on my Mac to my Ipad Air, the Events arrive in Photos in the correct order but not showing the Key photo. At the same time, the Events arrive in iPhoto in a totally random order but with the Key phto showing. Why? of course and is there a way to shift the order in Iphoto and get a Key photo in Photos?

    HHi, thank you for the reply. I have checked my iPad and iPhone and neither has iCloud Photo Library (Beta) enabled. Turned off in both. Photostream is turned on.
    i tried to sort it out  by dragging all the photos to Events on the Mac and then deleting them from iCloud - (left hand side of iPhoto under the section 'Shared'). the photos now show up in Events. I did force quit but the issue remains. The message reads ' photos are bing imported to the library. Please wait for import to complete.'
    i can't empty iPhoto trash either. The message read "Delete error. Please wait for import to complete.'
    WHen I was moving the photos to the Events I always had a message about duplicates - to the effect that the photos already existed, did I want to import them? I clicked on Yes, import all duplicates. But when it showed the images - duplicates side by side - one showed the photo and the other was blank.
    I really don't know what to do! And I don't know how to handle my iOS devices. Is it to do with the large number of photos? Any help, advice appreciated.

  • I want to transfer an audiobook and a movie from my MacBook Pro to my iPhone 4S, and can't figure out how.  I went to "Help" and it said after connecting the two devices I should "Click Apps," but I can't find anything labeled "Apps" to click.  Help?!!

    I want to transfer an audiobook and a movie from my MacBook Pro to my iPhone 4S, and can't figure out how.  I went to "Help" and it said after connecting the two devices I should "Click Apps," but I can't find anything labeled "Apps" to click.  Help?!!

    If you have iTunes 11 on your Mac then you can enable the left-hand sidebar via option-command-S, that might make it easier to navigate.
    Connect the phone to your Mac and select it on that left-hand sidebar, and on the right-hand side of the screen there should be a series of tabs which you can use to select what to sync to the phone. If it's an audiobook then it should appear on the Books tab for selecting/syncing, and films will be on the Movies tab. When you've got the audiobook on your phone you should get an Audiobooks option in the Music app (you might need to tap the '...' tab at the bottom of the Music app to see it).

  • How do I sync my 3rd gen ipod touch after installing the latest version of itunes?

    How do I sync my 3rd gen ipod touch after installing the latest version of itunes?

    Correction: Thank you FoxFifth for the good information. I did find this information earlier before landing here in the support community. I have come to the end and I am uncertain about trying to reset my I-pod touch to the factory settings. I was satisfied with the older version of i-tunes. Can someone direct me how to downgrade i-tunes perhaps?

  • How will be outbound data structure in sap xi after executing the stored pr

    Hi All
    can any one please tell me how will be outbound data structure in sap xi after executing the stored procedure by sender JDBC adapter?
    Thanks in advance
    regards
    Rams

    Hi..
    My stored procedure is select and it will be OUTBOUND in PI.
    is it will be same as following
    <resultset>
    <row>
    <column-name1>column-value</ column-name1>
    <column-name2></column-name2>
    <column-name3>column-value</ column-name3>
    <column-name4></column-name4>
    </row>
    <row>
    <column-name1>column-value</ column-name1>
    <column-name2></ column-name2>
    </row>
    </resultset>
    Regards
    Rams
    Edited by: Rameshkumar Varanganti on Oct 15, 2008 12:04 PM

  • How do I unlock macintoch HD hardrive in order to reset the mac to factory settings?

    How do I unlock macintoch HD hardrive in order to reset the mac to factory settings?

    Try this thread >  https://discussions.apple.com/message/23874937#23874937

  • How do we write the sub routines in smart forms?

    1) How do we write the sub routines in smart forms?
    2) What is the’ form interface’ in smart forms?
    3) Write down the path for writing for select queries in smart forms?
    4) How do we put dynamic page break in smart forms?
    5) in which system field contain the total page number of all forms in the currently processed print request in smart forms?
    6) What is the name of function module used to calling smart forms?
    1)     What is the functionality of function module ‘controal_form’?
    2)     How do we print the system date in this format ’15th Jan 2008’ on scripts?
    3)     What r the various print modes available in scripts?
    4)     What is the tcode for text element?
    5)     How do we draw horizontal line in scripts?
    6)     How can we suppress the leading zeros for a field in scripts?
    7)     In which system field is used to print current no page in scripts?
    Which f.m is used to reads text in sap scripts

    1) How do we write the sub routines in smart forms?
    after opening form see global definitions
    click on that there one tab called form routines inthat you can write subroutines logic.
    You can call in program lines .
    2) What is the’ form interface’ in smart forms?
    It is an interface between program and form .
    like function module we provide import,export,tables,exceptions
    Based on import and export parameters form will display for us.
    3) Write down the path for writing for select queries in smart forms?
    On window give right click in that command->programlines
    you can write all select  statements.
    4) How do we put dynamic page break in smart forms?
    you can define break point using break-point<>. syntax.
    5) in which system field contain the total page number of all forms in the currently processed print request in smart forms?
    SFSY-PAGE
    SFSY-JOBPAGES
    6) What is the name of function module used to calling smart forms?
    SSF_FUNCTION_MODULE_NAME
    =================
    1) What is the functionality of function module ‘control_form’?
    This function module is used to insert SAPScript control commands like NEW-PAGE etc from whithin the ABAP program.
    CALL FUNCTION 'CONTROL_FORM'
    EXPORTING
      COMMAND    =
    EXCEPTIONS
      UNOPENED   = 1
      OTHERS        = 3
    IF SY-SUBRC NE 0.
    MESSAGE ...
    ENDIF.
    2) How do we print the system date in this format ’15th Jan 2008’ on scripts?
    Use SET DATE MASK to change format of date display.
    3) What r the various print modes available in scripts?
    4) What is the tcode for text element?
    se91
    5) How do we draw horizontal line in scripts?
    &ULINE&
    6) How can we suppress the leading zeros for a field in scripts?
    &it_vbak-vbeln(Z)&
    7) In which system field is used to print current no page in scripts?
    &SYST-PAGE& of &SYST-FORMPAGES&
    Which f.m is used to reads text in sap scripts
    READ_TEXT functiomodule.
    Reward points

  • Firefox saves my cookies, but it keeps logging me out every time I exit the window. What do I do?

    Firefox saves my cookies, but it keeps logging me out every time I exit the window. I have "Remember Me" checked off, so I don't understand why it's doing this. Just started all of a sudden. What do I do?

    tried the above still having the same problem

  • My IPad4 cannot load the ios. it keeps trying but always crashes out after displaying the apple logo for a few seconds. it keeps cycling in the effort to start but without success.

    my IPad4 cannot load the
    os. it keeps trying but always crashes out after displaying the apple logo for a few seconds. it keeps cycling in the effort to start but without success.

    my IPad4 cannot load the
    os. it keeps trying but always crashes out after displaying the apple logo for a few seconds. it keeps cycling in the effort to start but without success.

  • How do I keep my contacts separate from other users under the same Apple ID?

    First, we have a single Apple ID that we use to log into iTunes and App Store.  We also have separate iPads.  Recently, my wife purchased an iPhone 4S.  During setup, she entered the Apple ID we use.  What happened next was that all of my contacts were added to her phone.  Then she followed the instructions to import her contacts from her old cell phone.  When that was done, all of my contacts were deleted from her phone.  Worse, they were deleted from my Address Book on the iMac (my account) and my iPad.  How do I keep my contacts safe from being deleted?  Do we need to have seperate Apple IDs?

    Go to settings>iclod>then mark "no" in  "contacts" .

  • How can I keep contact list separate on 2 phones on the same iTunes account

    I have 2 iPhones and 2 iPads on the same ITunes account. How can I keep my contact list separate on each device?

    You need to go to
    Setting
    Mail,contacts,calendars
    Go to each email and unselect contacts.
    Once this is complete all the contacts you add on the devices will stay local. Downfall of this is when you get a new phone you will not be able to transfer data to new phone unless you use computer to back it up

  • How do I keep photos in a particular order when burning to disc?

    I made an Album in iPhoto5 of 200 photos from a recent trip. The photos in the Album don't follow the sequence I shot them. I want the photos to stay in the new order I've given them, and I'd like to include titles to help explain many of the pictures. When I put the photos into a folder in Finder to burn them, they go out of order. Can I asign sequential numbers to this Album and still retain the titles? How do I keep them in order??? Thanks
    PowerBook G4   Mac OS X (10.4.7)  

    Hi Tom,
    You should be able to make a slidshow almost as easy as what you're trying to do right now... it'll take some pratice
    Personally, I have both exported a slideshow from iPhoto to iDVD and also created a slideshow directly in iDVD, the latter is a better fit for what you're doing.
    Open iDVD, create new project, name as you like and save, will auto open to work window, click on 'customize', pick a theme you like. Now click on 'Map' and in the customize pane click on 'Media'. In the media pane you have itunes, photos and movie, select photos... you're iPhoto library will appear along with all the albums you might have created and organized. Here's what makes it sweet, you can drag each album into the 'Map' Theme icon and it will automatically import and turn into a slideshow and take on the name of the album... to see your progess hit the Preview button... you'll have to do a little learning and tweaking, you can add music etc., but that's it, you made a slide show ready to burn to a dvd...
    My suggestions would be to organize albums as you like, named appropriately and just have fun with it. You can save and go back and edit at a later date. Use the highlight and delete or cut options to remove etc etc etc...
    You can burn project using the File > Burn DVD option or you can save the FINAL production use the File > Save As Disk Image option, and you can burn the DVD through disk utility which will give you more options on burn speed and buring at 1x speed may yield the best results...
    Rick
    iMac G5 iSight 20" - 30G iPOD in Slimming Black - Mac OS X (10.4.7) - HP Pav 15" WS and Toshiba Sat 17" WS LP's - Canon 20D & A620

  • How do i keep my photos from getting dark after the load on aperture?

    My photos look great as they load but the moment I click on them and they fully load they get completely dark? How do I keep this from happening? Please help me

    Littleton actually. If you drew a clock face around Denver, I'd be at about 7 o'clock. Pretty sure the Ogden is still here, but I have never been.

Maybe you are looking for