• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Need help with VB! (1 Viewer)

Fluorescent

Banned
Joined
Apr 5, 2009
Messages
266
Location
Sydney
Gender
Female
HSC
2009
I am pretty damn close to abandoning this ridiculously difficult game, but while I still have some thread of hope....

I need help with my VB major project, a Solitaire game.

Firstly, I randomised and assigned each card value/colour/picture to my card deck array, here's the code for the purpose of my question:

Code:
Private Sub Form_Load()
Randomize          'Makes it so the starting seed is different

Dim arrDeck(1 To 52) As Integer
Dim CardCount As Integer    'This will be my loop counter


Dim CardVal As Integer      'This will get assigned the random value
Dim Count As Integer






CardCount = 1           'Resets card count to 1





Do While CardCount < 53     'This sets every slot in arrDeck to -1


arrDeck(CardCount) = -1 'so that later I can tell if the slot is empty


CardCount = CardCount + 1   'or not


Loop





CardCount = 1           'Resets card count to 1





Do While CardCount < 53     'Loop until every slot is full


10  CardVal = Int((52 * Rnd) + 1)   'Set CardVal = to a random number


If arrDeck(CardVal) = -1 Then   'Take random slot and see if there is a card


                'in it yet. If there isn't it will be = to -1


                'if there is it will be equal to a different


                'value.


    arrDeck(CardVal) = CardCount 'There isn't so put current card in that slot


    CardCount = CardCount + 1   'Increment my card count





Else: GoTo 10          'There is so start again from the beginning


End If


Loop                'Do it all again if < 53

'Set the image, value and colour of each card.

For Count = 1 To 52
Select Case arrDeck(Count)
Case Is = 1
CardValue(1) = 1
CardColour(1) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-ace.bmp")
Case Is = 2
CardValue(2) = 2
CardColour(2) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-2.bmp")
Case Is = 3
CardValue(3) = 3
CardColour(3) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-3.bmp")
Case Is = 4
CardValue(4) = 4
CardColour(4) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-4.bmp")
Case Is = 5
CardValue(5) = 5
CardColour(5) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-5.bmp")
Case Is = 6
CardValue(6) = 6
CardColour(6) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-6.bmp")
Case Is = 7
CardValue(7) = 7
CardColour(7) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-7.bmp")
Case Is = 8
CardValue(8) = 8
CardColour(8) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-8.bmp")
Case Is = 9
CardValue(9) = 9
CardColour(9) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-9.bmp")
Case Is = 10
CardValue(10) = 10
CardColour(10) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-10.bmp")
Case Is = 11
CardValue(11) = 11
CardColour(11) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-jack.bmp")
Case Is = 12
CardValue(12) = 12
CardColour(12) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-queen.bmp")
Case Is = 13
CardValue(13) = 13
CardColour(13) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\clubs-king.bmp")
Case Is = 14
CardValue(14) = 1
CardColour(14) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-ace.bmp")
Case Is = 15
CardValue(15) = 2
CardColour(15) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-2.bmp")
Case Is = 16
CardValue(16) = 3
CardColour(16) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-3.bmp")
Case Is = 17
CardValue(17) = 4
CardColour(17) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-4.bmp")
Case Is = 18
CardValue(18) = 5
CardColour(18) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-5.bmp")
Case Is = 19
CardValue(19) = 6
CardColour(19) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-6.bmp")
Case Is = 20
CardValue(20) = 7
CardColour(20) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-7.bmp")
Case Is = 21
CardValue(21) = 8
CardColour(21) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\DIamond-8.bmp")
Case Is = 22
CardValue(22) = 9
CardColour(22) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\diamond-9.bmp")
Case Is = 23
CardValue(23) = 10
CardColour(23) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-10.bmp")
Case Is = 24
CardValue(24) = 11
CardColour(24) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\diamond-jack.bmp")
Case Is = 25
CardValue(25) = 12
CardColour(25) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\diamond-queen.bmp")
Case Is = 26
CardValue(26) = 13
CardColour(26) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Diamond-king.bmp")
Case Is = 27
CardValue(27) = 1
CardColour(27) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-ace.bmp")
Case Is = 28
CardValue(28) = 2
CardColour(28) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-2.bmp")
Case Is = 29
CardValue(29) = 3
CardColour(29) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\Heart-3.bmp")
Case Is = 30
CardValue(30) = 4
CardColour(30) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-4.bmp")
Case Is = 31
CardValue(31) = 5
CardColour(31) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-5.bmp")
Case Is = 32
CardValue(32) = 6
CardColour(32) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-6.bmp")
Case Is = 33
CardValue(33) = 7
CardColour(33) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-7.bmp")
Case Is = 34
CardValue(34) = 8
CardColour(34) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-8.bmp")
Case Is = 35
CardValue(35) = 9
CardColour(35) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-9.bmp")
Case Is = 36
CardValue(36) = 10
CardColour(36) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-10.bmp")
Case Is = 37
CardValue(37) = 11
CardColour(37) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-jack.bmp")
Case Is = 38
CardValue(38) = 12
CardColour(38) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-queen.bmp")
Case Is = 39
CardValue(39) = 13
CardColour(39) = "Red"
CardImage(Count).Picture = LoadPicture(App.Path & "\heart-king.bmp")
Case Is = 40
CardValue(40) = 1
CardColour(40) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-ace.bmp")
Case Is = 41
CardValue(41) = 2
CardColour(41) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-2.bmp")
Case Is = 42
CardValue(42) = 3
CardColour(42) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-3.bmp")
Case Is = 43
CardValue(43) = 4
CardColour(43) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-4.bmp")
Case Is = 44
CardValue(44) = 5
CardColour(44) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-5.bmp")
Case Is = 45
CardValue(45) = 6
CardColour(45) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-6.bmp")
Case Is = 46
CardValue(46) = 7
CardColour(46) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-7.bmp")
Case Is = 47
CardValue(47) = 8
CardColour(47) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-8.bmp")
Case Is = 48
CardValue(48) = 9
CardColour(48) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-9.bmp")
Case Is = 49
CardValue(49) = 10
CardColour(49) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-10.bmp")
Case Is = 50
CardValue(50) = 11
CardColour(50) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-jack.bmp")
Case Is = 51
CardValue(51) = 12
CardColour(51) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-queen.bmp")
Case Is = 52
CardValue(52) = 13
CardColour(52) = "Black"
CardImage(Count).Picture = LoadPicture(App.Path & "\spade-king.bmp")
End Select
Next Count

End Sub

My problem is that when I click a particular card, I need the program to be able to "read it" as such, so I can obtain the Value and the colour....

But how the hell do I do that!?

Also, if anyone can recommend a site or source that I could use I would greatly appreciate it because I'm seriously considering abandoning this project -.-
 

zvyx

Member
Joined
Aug 10, 2006
Messages
95
Location
NSW
Gender
Male
HSC
2008
not sure if you still need the help, but you can use the _click event for your cards to execute a command when the card is clicked.

e.g. If you have an array of images called "Card", then
Code:
Private Sub Card_Click(Index As Integer)
    MsgBox (Str(Index))
End Sub
Will give you a popup saying the index number of the card you selected when you click on one of them. Obviously, then you can extend that index result to finding Value and the colour, since you've already got the arrays for that set up.

Cheers,
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top