Results 1 to 9 of 9

Thread: [RESOLVED] im having a little trouble

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Resolved [RESOLVED] im having a little trouble

    Code:
    how do i see with domino it is and witch number is asigned to it?
    thanks
    
    Private Sub Shuffle()
        Dim X As Integer
        Dim IsUsed(28) As Byte, pipVal(28) As Integer
        Dim ThisCard As Integer
        Randomize
        'generate a number between 1 and 28 inclusive for each of 28 dominoes
        For X = 1 To 28
    Try2:
    
    
            ThisCard = Int((28 - 1 + 1) * Rnd + 1)
           
            
            If IsUsed(ThisCard) = 1 Then
                GoTo Try2
            Else
                'get and store
                pipVal(X) = ThisCard
                IsUsed(ThisCard) = 1
            
            Debug.Print pipVal(X)
            
           End If
        Next
        
        
    End Sub
    
    Private Sub Command1_Click()
    Shuffle
    End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: im having a little trouble

    is this the right way?
    and why does isused have to be a byte?


    Code:
    Debug.Print X & ThisCard

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: im having a little trouble

    Is it the right way to do what? IsUsed would be more appropriate to be a Boolean.

    Also, that GoTo looks very nasty.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: im having a little trouble

    thanks baja
    whats so weird about vb is no two people write the same code ,,while making the same program.

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: [RESOLVED] im having a little trouble

    That's true for any programming language. Programming is a skill and not an exact science. And that is exactly why there are some practices that should be avoided as they are potential pitfalls. Those include GoTo (other than error handling), On Error Resume Next, End and so on.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] im having a little trouble

    thanks again
    without using a goto ,how im i, to not use a allready used number?

    Code:
        For X = 1 To 28
    Try2:
    
    
            ThisCard = Int((28 - 1 + 1) * Rnd + 1)
           
            
            If IsUsed(ThisCard) = 1 Then
                GoTo Try2
            Else
                'get and store
                pipVal(X) = ThisCard
                IsUsed(ThisCard) = 1
            
                    
           End If
        Next

  7. #7
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: [RESOLVED] im having a little trouble

    Code:
    For X = 1 to 28
       Do
          ThisCard = Int((28 - 1 + 1) * Rnd + 1)
       Loop While IsUsed(ThisCard) = 1
    
       'get and store
       pipVal(X) = ThisCard
       IsUsed(ThisCard) = 1
    Next X

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] im having a little trouble

    i cant figure out why im getting the same 7 dominoes in all three places?
    it shuffles just fine other wize

    Code:
    Private Sub Shuffle()
        Dim x As Integer
        Dim IsUsed(28) As Byte, pipVal(28) As Integer
        Dim ThisCard As Integer
        Randomize
        'generate a number between 1 and 28 inclusive for each of 28 dominoes
      
        
        
       For x = 1 To 28
       Do
          ThisCard = Int((28 - 1 + 1) * Rnd + 1)
       Loop While IsUsed(ThisCard) = 1
    
       'get and store
       pipVal(x) = ThisCard
       IsUsed(ThisCard) = 1
         
         Next x
        
        ' computers hand
         For x = 1 To 7
            
           computerrack(x) = LoadPicture(App.Path & "\dom\" & pipVal(x) & "\up.ico")
           
         Next x
        '  humans hand
         For x = 1 To 7
            
           hrack(x) = LoadPicture(App.Path & "\dom\" & pipVal(x) & "\up.ico")
            
            
         Next x
         ' boneyard
         For x = 1 To 14
            
           boneyard(x) = LoadPicture(App.Path & "\dom\" & pipVal(x) & "\up.ico")
           
         Next x
        
       
    End Sub

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2009
    Posts
    573

    Re: [RESOLVED] im having a little trouble

    im sorry took a break then figured it out
    thanks all

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