Post: VB- Create an Array with Images HELP
03-30-2012, 02:16 PM #1
IamQwerty
You talkin to me?
(adsbygoogle = window.adsbygoogle || []).push({}); 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
03-30-2012, 03:45 PM #2
fill0botto95
You talkin to me?
Dim images() As Image
Dim rand As Random
picturebox1.Backgroundimage= image(rand.next(0, images.lenght-1))
03-30-2012, 05:26 PM #3
IamQwerty
You talkin to me?
Originally posted by fill0botto95 View Post
Dim images() As Image
Dim rand As Random
picturebox1.Backgroundimage= image(rand.next(0, images.lenght-1))


Thanks for the reply i copied this piece of code into mine to see if it would work but yet im still getting errors,
i get the error lenght is not a member of system array

This is the code which i created myself doesnt work either

' 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)
03-30-2012, 05:34 PM #4
fill0botto95
You talkin to me?
Originally posted by IamQwerty View Post
Thanks for the reply i copied this piece of code into mine to see if it would work but yet im still getting errors,
i get the error lenght is not a member of system array

This is the code which i created myself doesnt work either

' 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)


use imagelist control and then just do the following:

Imagelist1.Imges(your random)
03-30-2012, 05:38 PM #5
IamQwerty
You talkin to me?
Originally posted by fill0botto95 View Post
use imagelist control and then just do the following:

Imagelist1.Imges(your random)


see thats how i got my code above using that method, but im not allowed to use it, this is part of a project and the specification states i need to use an Array of Images
03-30-2012, 05:41 PM #6
fill0botto95
You talkin to me?
Originally posted by IamQwerty View Post
see thats how i got my code above using that method, but im not allowed to use it, this is part of a project and the specification states i need to use an Array of Images


If so give me time, I'm on mobile phone now...


Will write here later
03-30-2012, 05:44 PM #7
IamQwerty
You talkin to me?
Thanks no rush, i think my array is right i just cant get it to randomise the pictures within the picture box
03-30-2012, 06:57 PM #8
fill0botto95
You talkin to me?
Originally posted by IamQwerty View Post
Thanks no rush, i think my array is right i just cant get it to randomise the pictures within the picture box


I will fix right your code.

Dim imgPictures() As Image
imgPictures.Add(My.Resources.Red)
imgPictures.Add(My.Resources.Blue)
imgPictures.Add(My.Resources.Black)
imgPictures.Add(My.Resources.Yellow)


' Trying to randomise the images within the Picturebox - THE PROBLEM
Dim imgReel1 As Integer = random.Next(0, imgPictures.Images.Count - 1)
PicBox1.Image = imgPictures.Images(imgReel1)
03-30-2012, 10:02 PM #9
IamQwerty
You talkin to me?
Originally posted by fill0botto95 View Post
I will fix right your code.

Dim imgPictures() As Image
imgPictures.Add(My.Resources.Red)
imgPictures.Add(My.Resources.Blue)
imgPictures.Add(My.Resources.Black)
imgPictures.Add(My.Resources.Yellow)


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



I Managed to fix this thanks for all the help was something simple in the end
Last edited by IamQwerty ; 03-30-2012 at 10:30 PM.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo