Results 1 to 8 of 8

Thread: Random Dice

  1. #1

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Unhappy

    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 ?

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Wink

    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
    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  3. #3

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    another error

    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

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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")
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Wink

    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...

    rino_2
    Visual Basic, HTML
    Please Visit my Site: Richard's VB Site

  6. #6

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Exclamation thanks but....

    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

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Talking cheers

    cheers kedaman

    it works well now


    Merlin ?

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width