随机图片但不重复

随机图片但不重复

本文介绍了随机图片但不重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在我的项目的一部分并且对VB很新。

i将我的图片切成6等于部分

但是需要随机显示它们,不再按照随机顺序重复相同部分的图片。

例如,pic1,pic2,pic3,pic4,pic5,pic6到==> pic3,pic2,pic6,pic1,pic5,pic4


以下是我的代码的一部分


Dim theImage(0 To 7)As Object

Dim myArray(0到7)As Object


theImage(0)= pic1.Image

theImage(1)= pic2.Image

theImage(2)= pic3.Image

theImage(3)= pic4.Image

theImage(4)= pic5。图片

theImage(5)= pic6.Image

theImage(6)= pic7.Image


For i = 0 To 6步骤1



随机= num.Next(0,7)

循环时(myArray(随机)<> 0 )

myArray(随机)= theImage(i)


接下来我是


while循环中的部分不会工作,因为他们无法解析图像。

我该怎么做呢?我的代码看起来很糟糕。

提前感谢

i am stuck on part of my project and very new to VB.
i had cut my picture into 6 equals part
but need to display them randomly, without repeating the same part of the pic again, in random sequence.
eg, pic1,pic2,pic3,pic4,pic5,pic6 to ==> pic3,pic2,pic6,pic1,pic5,pic4

below are part of my code

Dim theImage(0 To 7) As Object
Dim myArray(0 To 7) As Object

theImage(0) = pic1.Image
theImage(1) = pic2.Image
theImage(2) = pic3.Image
theImage(3) = pic4.Image
theImage(4) = pic5.Image
theImage(5) = pic6.Image
theImage(6) = pic7.Image

For i = 0 To 6 Step 1
Do
random = num.Next(0, 7)
Loop While (myArray(random) <> 0)
myArray(random) = theImage(i)

Next i

the part on the while loop wont work as they cant parse in image.
how do i go about doing it? and my code seems sucky.
thanks in advance

推荐答案





关键是你没有分配图片,你只需要分配图片的数字。换句话说,第二个数组将以随机顺序保持数字1-6。要显示图片,您只需浏览此数组并使用每个数字作为第一个数组(图像)的索引。

The point was that you don''t assign the pictures, you just assign the numbers of the pictures. In other words, the second array would just hold numbers 1-6, in a random sequence. To show the pictures, you just go through this array and use each number as an index for the first array (theImage).



就像我说的,一般的技巧就是简单地保持生成随机数,直到你得到一个在用过的数组中找不到的数字。例如,这里有一个小例子例程来生成一个包含六个非重复数字的数组。它可能不是很优雅,因为我只是在当场弥补它。 (哦,它也从中调用RandomNumBetween函数)。

Like I said, the general technique is to simply keep generating random numbers until you get one that you can''t find in the array of used ones. For instance, here''s a little sample routine to generate an array of six non-repeating numbers. It''s probably not very elegant, as I''m just making it up on the spot. (Oh, also it calls the RandomNumBetween function from this post).

展开 | 选择 | Wrap | 行号


这篇关于随机图片但不重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:41