Click to See Complete Forum and Search --> : this is interesting...


ariel_au
April 1st, 2001, 12:57 AM
well, the following code is interesting, all u need is a folder that contains pictures and named the pics as
pic1, pic2, pic3, etc.... and run the program.
also, u must have a imagebox named "imgControl" with index property 0.
now, my problem is dealing with the random function. i wanted pics of the same to be appeared only twice.
i do not allow pics of the same to be appeared once or more then twice. see code below: (especially the random function).
how can i solve that?


option Explicit

' Global variables hold the total number of columns and rows
private TotalCols as Integer
private TotalRows as Integer
'---------------------------------------------------------
private Sub Form_Load()
' You must have an image on the form with the following properties:
' .Name = imgControl
' .Index = 0
' .Visible = false
' .Strech = true
' set the picture property to something (a bitmap, icon, etc.)

TotalCols = InputBox("How many columns do you want?", "set Columns", "4")
TotalRows = InputBox("How many rows do you want?", "set Rows", "4")

Call LoadImagesOnForm
End Sub
'----------------------------------------------------------
private Sub LoadImagesOnForm()
Dim ImgCount as Integer
Dim RowCount as Integer
Dim ColCount as Integer
Dim FrmScalHghtDiff as Integer
Dim FrmScalWdthDiff as Integer

Dim i as Integer, num as Integer, k as Integer
Dim filepath as string

With me
' get the difference between (Form1.Height and Form1.ScaleHeight)
' and (Form1.Width and Form1.ScaleWidth) for use in resizing form
FrmScalHghtDiff = .Height - .ScaleHeight
FrmScalWdthDiff = .Width - .ScaleWidth

' set width and height of form so that it resizes to the
' number of images the user requested to display
.Height = (imgControl(0).Height * TotalRows) + FrmScalHghtDiff
.Width = (imgControl(0).Width * TotalCols) + FrmScalWdthDiff

' These loops load images by rows first, then columns, like this:
' 1 2 3
' 4 5 6
' 7 8 9
for RowCount = 1 to TotalRows
for ColCount = 1 to TotalCols
ImgCount = ImgCount + 1

Load imgControl(ImgCount)
'-----------------------------------------------------------
Randomize Timer 'here is the problem...
k = TotalRows * TotalCols
num = 1 + Int(Rnd * k)
filepath = "C:\Unzipped Files\memory2\Icons" & "\im" & num & ".ico"
imgControl(ImgCount).Picture = LoadPicture(filepath)
'------------------------------------------------------------
With imgControl(ImgCount)
.Move (ColCount - 1) * imgControl(0).Width, _
(RowCount - 1) * imgControl(0).Height

.Tag = RowCount & "," & ColCount
.Visible = true
End With ' imgControl(ImgCount)
next ' ColCount
next ' RowCount

End With

End Sub