Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 30th, 2012, 09:31 AM
iamqwerty iamqwerty is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 18 iamqwerty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 13 m 57 sec
Reputation Power: 0
Help Needed with Randomising

Just wondering if anyone here will be able to help me with a problem im having on Visual Basic
I have to create a program which will randomise images within a picturebox
I have to import the images in using My Resources and then create an Array with them
my problem is im not sure if im doing this right as when i go to randomise the array of images the program fails and will not work

Anyone willing to help me if i post up my code? or give me any tips to do this

Reply With Quote
  #2  
Old March 30th, 2012, 11:58 AM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
Posts: 14,939 medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)  Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Months 2 Weeks 2 Days 1 h 38 m 6 sec
Reputation Power: 8490
Facebook
It's hard to help you debug code we can't see, or even speculate on a randomization method which is not even described.

Hypothetical way to do this with just a standard array (adapt to image as appropriate)

Code:
Sub RandomArray()
    ' assumes arrays start at 0 (option base 0)
    ' create three undimensioned arrays
    Dim SourceList() As String ' the original list
    Dim RandomList() As String ' the randomized list
    Dim SelectedList() As Long ' to keep track of random selections
    Dim NumberSelected As Long ' keep track of the number of picks
    Dim NumToSelect As Long    ' how many we are picking (ubound + 1)
    Dim ThisSelection As Long  ' for the random pick
    ' populate the source list
    SourceList = Split("ANT,BAT,CAT,DOG,ELEPHANT,FROG,GERBIL,HAMSTER,IGUANA", ",")
    ' redimension our other two
    NumToSelect = UBound(SourceList) + 1 ' the number of elements in our source array
    ReDim RandomList(0 To UBound(SourceList))
    ReDim SelectedList(0 To UBound(SourceList))
    Randomize ' if you don't do this your random sequence will be the same every time
    Do
        Do
            ThisSelection = Int(Rnd * NumToSelect) ' select a random number in the range
        Loop Until SelectedList(ThisSelection) = 0 ' loop until we find a number we haven't picked yet
        SelectedList(ThisSelection) = 1            ' mark this as picked now
        RandomList(NumberSelected) = SourceList(ThisSelection) ' copy the data from the random pick to output list
        NumberSelected = NumberSelected + 1 ' increment the pick counter
    Loop Until NumberSelected = NumToSelect        ' loop until all have been picked
  ' Just output the results to immediate pane/debug window
    For ThisSelection = 0 To UBound(SelectedList)
        Debug.Print RandomList(ThisSelection) & " ";
    Next
    Debug.Print
End Sub


That's a VB6/VBA you can run in Excel, Access, etc. Should be about the same for .Net

The output will be like
Code:
CAT GERBIL DOG ELEPHANT HAMSTER IGUANA BAT FROG ANT 
FROG ANT HAMSTER IGUANA CAT GERBIL DOG BAT ELEPHANT 
ELEPHANT HAMSTER IGUANA FROG ANT GERBIL DOG BAT CAT 
__________________
medialint.com

“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

Reply With Quote
  #3  
Old March 30th, 2012, 12:19 PM
iamqwerty iamqwerty is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 18 iamqwerty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 13 m 57 sec
Reputation Power: 0
Quote:
Originally Posted by medialint
It's hard to help you debug code we can't see, or even speculate on a randomization method which is not even described. ]


Your Method seems really complicated to me im a bit confused but will have another, this is what i have got


Method for doing Random
Dim random As New Random



Image Array
Dim imgPictures(3) As Image
imgPictures(0) = My.Resources.Red
imgPictures(1) = My.Resources.Blue
imgPictures(2) = My.Resources.Black
imgPictures(3) = My.Resources.Yellow




Trying to randomise the images within the Picturebox - THE PROBLEM
Dim imgReel1 As Integer = random.Next(0, imgPictures.Images.Count)
PicBox1.Image = imgPictures.Images(imgReel1)

Dim imgReel2 As Integer = random.Next(0, imgPictures.Images.Count)
Picbox2.Image = imgPictures.Images(imgReel2)

I cant seem to get this part above working, Can you take a look and see if you can spot why?
Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Help Needed with Randomising

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap