473,836 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do I randomise images from an imagelist without repeats?

15 New Member
I am trying to design a quiz where the user will be presented randomised images to grade. I am at the stage of writing code to randomise image without repeating. Images are stored in imagelist and are being randomised in picturebox. At the moment my code loops around continuously with repeats. However I would like it to present images randomly without repeating. Here's the randomise snippet of my code. Hellllppp!

Expand|Select|Wrap|Line Numbers
  1. ...Button Click
  2. Dim intPic As Integer
  3. Dim rand as New Random
  4. IntPic=rand.Next(0, Imagelist1.Images.Count
  5. PictureBox1.Image= Imagelist1.Images(intPic)
Dec 27 '11
17 5578
15 New Member
@ Guido ...:( I can open the application but not any files....
Jan 1 '12 #11
15 New Member
This is what i have so far...
'Random Class included in .NET
Private RND As New Random

'Create an array that can be used to hold the Index of Images to select from
Dim ImageIndexes As New List(Of Integer)

Private Sub Form6_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'Populate the array with the Index of each Image in the ImageList
For i As Integer = 0 To ImageList1.Imag es.Count - 1
ImageIndexes.Ad d(i)
Next i
End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
'// To get a Random Image:
'Get a random Index within the array
Dim ArrayIndex As Integer = RND.Next(0, ImageIndexes.Co unt)

'Get the associated Image from the ImageList
PictureBox1.Ima ge = ImageList1.Imag es(ImageIndexes (ArrayIndex))

'Remove the reference to the current Image's Index from the ImageIndexes array (so it cannot be picked again)
'nb: We are not removing the Image, just a reference to it from within another array
ImageIndexes.Re move(ArrayIndex )
End Sub
Jan 1 '12 #12
15 New Member
Expand|Select|Wrap|Line Numbers
  2. 'Random Class included in .NET
  3.     Private RND As New Random
  5.     'Create an array that can be used to hold the Index of Images to select from
  6.     Dim ImageIndexes As New List(Of Integer)
  8.     Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.         'Populate the array with the Index of each Image in the ImageList
  10.         For i As Integer = 0 To ImageList1.Images.Count - 1
  11.             ImageIndexes.Add(i)
  12.         Next i
  13.     End Sub
  17.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  18.         '// To get a Random Image:
  19.         'Get a random Index within the array
  20.         Dim ArrayIndex As Integer = RND.Next(0, ImageIndexes.Count)
  22.         'Get the associated Image from the ImageList
  23.         PictureBox1.Image = ImageList1.Images(ImageIndexes(ArrayIndex))
  25.         'Remove the reference to the current Image's Index from the ImageIndexes array (so it cannot be picked again)
  26.         'nb: We are not removing the Image, just a reference to it from within another array
  27.         ImageIndexes.Remove(ArrayIndex)
  28.     End Sub
Jan 1 '12 #13
Guido Geurs
767 Recognized Expert Contributor
This is the code for VB6 !!!:
form with:

ListBox List2
ListBox List1
CommandButton ComEvaluation (1)
CommandButton ComEvaluation (2)
CommandButton ComEvaluation (3)
CommandButton ComEvaluation (4)
CommandButton ComEvaluation (5)
Timer Timer1
TextBox TextNmbrPicture s
TextBox TextInterval
CommandButton ComStart
PictureBox PictureBox

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim ARR_SELECT() As Integer
  3. Dim ARR_SELECTidx As Integer
  4. Dim ARR_EVALUATION() As Integer
  5. Dim ARR_EVALUATIONidx As Integer
  6. Dim EVALUATIONvalue As Integer
  7. Dim PICTUREnmbr As Integer
  9. Private Sub ComEvaluation_Click(Index As Integer)
  10.    EVALUATIONvalue = Index
  11. End Sub
  13. Private Sub ComStart_Click()
  14. Dim PICTUREScount As Integer
  15. '§ ===BEGIN Just for development check================================
  16.       List1.Clear
  17.       List2.Clear
  18. '§ ===END Just for development check================================
  19.    EVALUATIONvalue = 0
  20.    PICTUREScount = Val(TextNmbrPictures.Text)
  21. '§ fill Array Evaluation
  22.    ReDim ARR_EVALUATION(1 To PICTUREScount, 1 To 2)
  23.    For ARR_EVALUATIONidx = 1 To PICTUREScount
  25.    Next
  26. '§ fill Array Select
  27.    ReDim ARR_SELECT(0 To PICTUREScount)
  28.    For ARR_SELECTidx = 1 To PICTUREScount
  30.    Next
  31. '§ Start evaluation
  32.    Randomize ' Initialize random-number generator.
  33.    With Timer1
  34.       .Interval = 1 '§ load immediately first picture
  35.       .Enabled = True '§ start timer
  36.    End With
  37. End Sub
  39. Private Sub Form_Load()
  40. Me.ZOrder
  41. End Sub
  43. Private Sub Timer1_Timer()
  44.    Timer1.Interval = Val(TextInterval.Text) * 1000
  45.    '§ save evaluation previous picture
  46.    If PICTUREnmbr <> 0 Then
  47.       ARR_EVALUATION(PICTUREnmbr, 2) = EVALUATIONvalue
  48. '§ ===BEGIN Just for development check================================
  49.       List2.AddItem "Pic " & ARR_EVALUATION(PICTUREnmbr, 1) & " - Eval= " & ARR_EVALUATION(PICTUREnmbr, 2)
  50. '§ ===END Just for development check================================
  51.    End If
  52.    EVALUATIONvalue = 0
  53.    If UBound(ARR_SELECT) > 0 Then
  54.       '§ Generate random value between 1 and UBound(ARR_SELECT).
  55.       ARR_SELECTidx = Int((UBound(ARR_SELECT) * Rnd) + 1)
  56.       '§ load picture
  57.       PICTUREnmbr = ARR_SELECT(ARR_SELECTidx)
  58.       PictureBox.Picture = LoadPicture(App.Path & "\Pictures\" & PICTUREnmbr & ".GIF")
  59.       '§ delete picture-number from ARR_SELECT
  61.       ReDim Preserve ARR_SELECT(0 To (UBound(ARR_SELECT) - 1))
  62. '§ ===BEGIN Just for development check================================
  63.       List1.AddItem PICTUREnmbr
  64. '§ ===END Just for development check================================
  65.    Else
  66.       Timer1.Enabled = False
  67.       PictureBox.Picture = LoadPicture(App.Path & "\Pictures\END.GIF")
  68.    End If
  69. End Sub
How it works:
"ARR_SELECT () As Integer" has the indexes for the filenames.
"ARR_EVALUATION () As Integer" has 2 columns:
1= file indexes
2= has the evaluations.
In the textboxes are the numbers for
TextBox TextNmbrPicture s = the number pictures to show
TextBox TextInterval = the durations between two pictures

the pictures are loaded from the HD with the index as name.

PS: List1 and List2 can be deleted= just for checking the program evolution!
Jan 1 '12 #14
15 New Member
Hi Guido ...well after several days sick in bed I'm finally visiting your reply. Thank you for taking the time to reply to my query.

Hmm I'm using the Visual Studio 2008. So I'm getting lots of errors I've used the MSDN to identify a solution ...but am not getting very far. Hellllp...
Option Explicit default is On in VB 2008.
Not sure about how to set the evaluation index
List1.Clear().. .the Clear command is being underlined aswell as the .addItem
Redim has an error
ARR_EVALUATION is underlined - I'm unsure how to write this for my version of VB.
I'm getting a list of 18 errors :(. Am trying to work through them...
Jan 6 '12 #15
15 New Member
I've whittled it down to 5 error...probabl y more comprensive to paste the errors...forgiv e my being dozey!

Error 1 'ReDim' cannot change the number of dimensions of an array.
Error 2 Number of indices exceeds the number of dimensions of the indexed array.
Error 3 Number of indices exceeds the number of dimensions of the indexed array.
Error 4 Number of indices exceeds the number of dimensions of the indexed array.
Error 5 Number of indices exceeds the number of dimensions of the indexed array.
Jan 6 '12 #16
15 New Member
I tried looking this up Killer...but I feel like I don't know to adapt this for my needs...newbie :(
Jan 6 '12 #17
15 New Member
@ Guido I think I've sorted out all the errors...but how do I save the responses in excel instead of in lISTS? I want the user to email me their responses back to me in an excel file. They will do this experiment twice...so they will send responses back twice. Many thanks
Jan 6 '12 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

by: brunchto | last post by:
Hi, I've this code: Dim ImageList1 As New ImageList ImageList1.Images.Add(Image.FromFile("..\images\statusOK.bmp")) ImageList1.Images.Add(Image.FromFile("..\images\statusKO.bmp")) TV.ImageList = ImageList1 Dim rootNode As New TreeNode("Test", 0, 1) rootNode.Text = "TEST"
by: Mamatha | last post by:
Hi I am developing a small application to capture a record a video file through webcam in C#.NET. In this application i created a JPEG images for every slide,means every JPEG image was treated as a slide then i want to display these images as a slide show. How can i alot time teo each frame? How can i display images one by one without my interaction? Please give me the solution or any releated source code.
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error like "gcnew is undeclared error",how to deeclare 'gcnew" and when i am using in runtime to change the size of images in imagelist in listview control in .net(forms application) by chnging one trckbar(like tb1->Value),
by: Just Me | last post by:
If I add an image to an imagelist using imageList.Images.Add... And use it with a tree node tn.ImageIndex = imageList.Images.Count-1 This is the actual code: Win32.Shell.SHGetFileInfo(NodePath, 256, fileinfo, cbFileInfo, flags) tvFolders.ImageList.Images.Add(Icon.FromHandle(fileinfo.hIcon)) tn.ImageIndex = tvFolders.ImageList.Images.Count - 1
by: Mitchell Vincent | last post by:
I've been trying to get a standard toolbar to play nice with some nice icons that I have. When I put them on a button or anything they look perfect, but through an imagelist and on a toolbar they all have this blue aura around them. I assume that is from the transparency, but I don't understand why almost any other control displays them properly.. There really is no replacement for the toolbar (without paying!), so I hope someone can tell...
by: mrmagoo | last post by:
I'm trying to fill a listview with data. I'm using the example from the help file, but how do I modify this to avoid using images? I want the exact same layout but without images. This procedure seems so dependent on the image being the "anchor" of each row that I don't understand how to modify it. Thanks. Dim lv As ListView lv = Me.ListView1
by: Roger Miller | last post by:
I have a WxPython app that displays images that are typically around 600x600 pixels. I use a wxStaticBitmap, which appears to work fine on Windows XP. However the documentation states that a StaticBitmap "... is meant for display of the small icons in the dialog boxes and is not meant to be a general purpose image display control. In particular, under Windows 9x the size of bitmap is limited to 64*64 pixels and thus you should use your own...
by: tpgames | last post by:
I'm trying to make the code work with images, and work without using dates. I'm trying to alter someone elses script. The board doesn't show up with images. Thanks! <script type="text/javascript"> var sUnsolvedSudoku var sSolvedSudoku var sStyle var sHeader var sTodaysDate var d_names = new Array("Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"); var d = new Date();
by: wolffy | last post by:
okay heres my problem; i want to add image K to a imagelist, thats easy. The hard part is that the imagelist was made in Application Settings. **I made the imagelist in application settings so i could eventually add in code which would make its value saved when the form closes** But every time i use something like this image k = toolstrip1.backgroundimage; Settings.Default.kill.Images.Add(k); **kill is the name of the imagelist** i get...
by: Paul E Collins | last post by:
I want to fill an ImageList with bitmaps for a ListView from another thread, because it's a time-consuming process. I expect the ListViewItems' images to "load" one by one, as in a Web browser. I wrote the following code, but the form freezes up while CreateTileBitmaps is running, just as if I'd done it on the main thread. How can I add items to the ImageList without this problem? (Note: I do *not* want to use an owner-draw ListView and...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.