|
-
Oct 16th, 2010, 06:31 PM
#1
Thread Starter
Fanatic Member
[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
-
Oct 16th, 2010, 06:43 PM
#2
Thread Starter
Fanatic Member
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
-
Oct 16th, 2010, 06:49 PM
#3
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.
-
Oct 17th, 2010, 08:41 AM
#4
Thread Starter
Fanatic Member
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.
-
Oct 17th, 2010, 09:37 AM
#5
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.
-
Oct 17th, 2010, 04:48 PM
#6
Thread Starter
Fanatic Member
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
-
Oct 17th, 2010, 05:02 PM
#7
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
-
Oct 18th, 2010, 11:12 AM
#8
Thread Starter
Fanatic Member
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
-
Oct 18th, 2010, 12:05 PM
#9
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|