hi,
i am trying to write a program that has six pictures of the six sides of a dice, and when i click on a button i want the program to randomally choose one of these pictures, and display it
can anyone help me
Merlin ?
Printable View
hi,
i am trying to write a program that has six pictures of the six sides of a dice, and when i click on a button i want the program to randomally choose one of these pictures, and display it
can anyone help me
Merlin ?
Try something like this:
dim intNumber as Integer
randomize
intNumber = int((6 * rnd) + 1)
select case intNumber
case 1
image1.picture = 'Put the picture
case 2
image2.picture = ' put the picture
etc....
Hope this helps
hi,
now i get the message
type miss match
it is on the line with the **
Private Sub Command1_Click()
Dim intNumber As Integer
Randomize
intNumber = Int((6 * Rnd) + 1)
Select Case intNumber
Case 1
**Image1.Picture = "C:\My Documents\vb\Total Domination\dice 1.jpg "
Case 2
Image2.Picture = "C:\My Documents\vb\Total Domination\dice 2.jpg"
MsgBox ("2")
Case 3
Image3.Picture = "C:\My Documents\vb\Total Domination\dice 3.jpg"
MsgBox ("3")
Case 4
Image4.Picture = "C:\My Documents\vb\Total Domination\dice 4.jpg"
MsgBox ("4")
Case 5
Image5.Picture = "C:\My Documents\vb\Total Domination\dice 5.jpg"
MsgBox ("5")
Case 6
Image6.Picture = "C:\My Documents\vb\Total Domination\dice 6.jpg"
MsgBox ("6")
End Sub
String is not a picture, that's why you get a type mismatch. Use image1.picture=Loadpicture(yourfilename) to get your picture
And also you don't need to have that select case. Put:
Image1.picture= Loadpicture ("C:\My Documents\vb\Total Domination\dice " & intnumber & "1.jpg")
Hi,
You need to use the LoadPicture method:
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 1.jpg")
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 2.jpg")
etc...
hi,
thanks that but now works
but when i try and make it for two dice they both come out with the same number
any way of them being different ?
code used so far...
Private Sub Command1_Click()
Dim intNumber As Integer
Randomize
intNumber = Int((6 * Rnd) + 1)
Select Case intNumber
Case 1
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 1.jpg")
Case 2
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 2.jpg")
Case 3
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 3.jpg")
Case 4
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 4.jpg")
Case 5
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 5.jpg")
Case 6
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 6.jpg")
End Select
Select Case intNumber
Case 1
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 1.jpg")
Case 2
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 2.jpg")
Case 3
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 3.jpg")
Case 4
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 4.jpg")
Case 5
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 5.jpg")
Case 6
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice 6.jpg")
End Select
End Sub
Code:Private Sub Command1_Click()
Dim Num1%,Num2%
Randomize timer
Num1 = Int((6 * Rnd) + 1)
Num2 = Int((6 * Rnd) + 1)
Image1.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice " & Num1 & ".jpg")
Image2.Picture = LoadPicture("C:\My Documents\vb\Total Domination\dice " & Num2 & ".jpg")
End Sub
cheers kedaman
it works well now
Merlin ?