Discussion Locked

Please explain this code!

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

For I = 0 To 15
'replace with card back
imgHidden(I).Picture = imgBack.Picture
imgHidden(I).Visible = True
Next I
'Randomly sort 16 integers using Shuffle routine
'Behind contains indexes (0-7) for hidden pictures
Call Shuffle(16, Behind)
For I = 0 To 15
If Behind(I) > 8 Then
Behind(I) = Behind(I) - 8
End If
'Shift value back one since picture indices are from 0 to 7 (not 1 to 8)
Behind(I) = Behind(I) - 1
Next I
Choice = 1
cmdNew.Enabled = False
cmdExit.Caption = "&Stop"
End Sub

For LoopCounter = 1 To numberofitems
NumberList(LoopCounter) = LoopCounter
Next LoopCounter
'Work through Remaining values
'Start at NumberOfItems and swap one value
'at each For/Next loop step
'After each step, Remaining is decreased by 1
For Remaining = numberofitems To 2 Step -1
'Pick item at random
ItemPicked = Int(Rnd * Remaining) + 1
'Swap picked item with bottom item
TempValue = NumberList(Remaining)
NumberList(Remaining) = NumberList(ItemPicked)
NumberList(ItemPicked) = TempValue
Next Remaining
'End Sub

'Call cmdNew_Click
End Sub

Private Sub imgHidden_Click(Index As Integer)
'If trying to pick same box, picking already selected box
'or trying pick when not playing, exit
If (Choice = 2 And Index = Picked(1)) Or Behind(Index) = -1 Or cmdNew.Enabled Then
Exit Sub
End If
'Display selected picture
imgHidden(Index).Picture = imgChoice(Behind(Index)).Picture
imgHidden(Index).Refresh
If Choice = 1 Then
Picked(1) = Index
Choice = 2
Exit Sub
End If
Guesses = Guesses + 1
lblGuesses.Caption = Format(Guesses, "0")
Picked(2) = Index
If Behind(Picked(1)) = Behind(Picked(2)) Then

Behind(Picked(1)) = -1
Behind(Picked(2)) = -1
Remaining =Remaining - 1
Else
'If no match, blank picture, restore backs

imgHidden(Picked(1)).Picture = imgBack.Picture
imgHidden(Picked(2)).Picture = imgBack.Picture
End If
Cho

3 replies

by mjervis

Basically it is a card game program. If you are trying to learn programming and want this code explained line by line I doubt your going to get any takers.

Although without seeing all the code nobody will be able to explain this.

See you have I=0 - 15 well I understand why they have 0-15 but what I don't understand and can't without all of the code is what = what. 0-15 mean the cards A 2 3 4 5 6 etc. and they also stand for cards that are not turned up yet and cards that are not visibleto be turned up yet.

Some direction to help you learn. This is a VB program if your looking to learn VB and cannot find the books your reading helpful try this one Learn VB in 14 days. IDG books puts it out. It is very easy to follow and will allow you to learn what this program and others are doing so you can write your own programs.

This discussion is closed to new replies.