I have 2 arrays. One is an array of images other an array of numbers. The images are card faces, (Card(i)), the integers are the corresponding values of the cards (Value(i)). I want to associate the card face with a corresponding value. However, everytime I do what I think is correct, I get an error stating that I cant convert an image to an integer and visa versa.

Thanks,

-J

"Associating" is a vague term that can mean many things. If you have an array of 52 images and an array of 52 strings (such as "AH 2H 3H..." then the two arrays are "associated" by their indices assuming that the two arrays were defined and loaded such that the "Ace of hearts" image has the same index as the "AH" string. How, exactly, are you trying to associate the two arrays? Without seeing the code or the error that it produces we can't really say what the problem might be.

If the arrays are the same size and sorted the same way, you can just associate them by their position 0-51 or 1-52.

If they are always to be "together", you might as well create a class that contains the value and the image.

Thanks for the replies! We meet yet again, Jim...LOL.

Heres what I have so far. I'm guessing that the association should take place in a loop under the draw_button push but thats where I'm stuck. I considered making both arrays strings but just thought about that about 10 minutes ago and havent tried at. At any rate...here it is:

Public Class frmWar
    'Created By: Jason Wilbarger
    Dim value(51), intgame_score1, intgame_score2, inthand_value1, inthand_value2 As Integer
    Dim card(51) As Image
    Dim switch, tempval As Integer
    Dim tempcard As Image
    Dim number_of_cards As Integer
    

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        card(0) = My.Resources.twoc
        card(1) = My.Resources.threec
        card(2) = My.Resources.fourc
        card(3) = My.Resources.fivec
        card(4) = My.Resources.sixc
        card(5) = My.Resources.sevenc
        card(6) = My.Resources.eightc
        card(7) = My.Resources.ninec
        card(8) = My.Resources.tenc
        card(9) = My.Resources.jackc
        card(10) = My.Resources.queenc
        card(11) = My.Resources.kingc
        card(12) = My.Resources.acec
        card(13) = My.Resources.twos
        card(14) = My.Resources.threes
        card(15) = My.Resources.fours
        card(16) = My.Resources.fives
        card(17) = My.Resources.sixs
        card(18) = My.Resources.sevens
        card(20) = My.Resources.eights
        card(21) = My.Resources.nines
        card(22) = My.Resources.tens
        card(23) = My.Resources.jacks
        card(24) = My.Resources.queens
        card(25) = My.Resources.kings
        card(26) = My.Resources.aces
        card(27) = My.Resources.twoh
        card(28) = My.Resources.threeh
        card(29) = My.Resources.fourh
        card(30) = My.Resources.fiveh
        card(31) = My.Resources.sixh
        card(32) = My.Resources.sevenh
        card(33) = My.Resources.eighth
        card(34) = My.Resources.nineh
        card(35) = My.Resources.tenh
        card(36) = My.Resources.jackh
        card(37) = My.Resources.queenh
        card(38) = My.Resources.kingh
        card(39) = My.Resources.aceh
        card(40) = My.Resources.twod
        card(41) = My.Resources.threed
        card(42) = My.Resources.fourd
        card(43) = My.Resources.fived
        card(44) = My.Resources.sixd
        card(45) = My.Resources.sevend
        card(46) = My.Resources.eightd
        card(47) = My.Resources.nined
        card(48) = My.Resources.tend
        card(49) = My.Resources.jackd
        card(50) = My.Resources.queend
        card(51) = My.Resources.kingd
        card(52) = My.Resources.aced


        value(0) = 1
        value(1) = 2
        value(2) = 3
        value(3) = 4
        value(4) = 5
        value(5) = 6
        value(6) = 7
        value(7) = 8
        value(8) = 9
        value(9) = 10
        value(10) = 11
        value(11) = 12
        value(12) = 13
        value(13) = 1
        value(14) = 2
        value(15) = 3
        value(16) = 4
        value(17) = 5
        value(18) = 6
        value(19) = 7
        value(20) = 8
        value(21) = 9
        value(22) = 10
        value(23) = 11
        value(24) = 12
        value(25) = 13
        value(26) = 1
        value(27) = 2
        value(28) = 3
        value(29) = 4
        value(30) = 5
        value(31) = 6
        value(32) = 7
        value(33) = 8
        value(34) = 9
        value(35) = 10
        value(36) = 11
        value(37) = 12
        value(38) = 13
        value(39) = 1
        value(40) = 2
        value(41) = 3
        value(42) = 4
        value(43) = 5
        value(44) = 6
        value(45) = 7
        value(46) = 8
        value(47) = 9
        value(48) = 10
        value(49) = 11
        value(50) = 12
        value(51) = 13

        Randomize()

    End Sub

    Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click

        txtOne.Text = Nothing
        txtTwo.Text = Nothing
        intgame_score1 = 0
        intgame_score2 = 0
        shuffle()

    End Sub

    Private Sub btnDraw_Click(sender As System.Object, e As System.EventArgs) Handles btnDraw.Click

        txtOne.Text = intgame_score1
        txtTwo.Text = intgame_score2
        pbPlayer2.Image = tempcard
        pbPlayer1.Image = tempcard
        
        shuffle()

        If inthand_value1 < inthand_value2 Then
            intgame_score2 = intgame_score2 + 1
            pbWinner.Image = My.Resources.winright
        ElseIf inthand_value2 < inthand_value1 Then
            intgame_score1 = intgame_score1 + 1
            pbWinner.Image = My.Resources.winleft
        ElseIf inthand_value1 = inthand_value2 Then
            pbWinner.Image = My.Resources.tie
        ElseIf intgame_score1 = 26 Then
            MessageBox.Show("Congratulations Player1! You are victorious")
        ElseIf intgame_score2 = 26 Then
            MessageBox.Show("Congratulations, Player2! You are victorious")
        End If









    End Sub

    Private Sub btnShuffle_Click(sender As System.Object, e As System.EventArgs) Handles btnShuffle.Click

        pbPlayer1.Image = My.Resources.back
        pbPlayer2.Image = My.Resources.back
        pbWinner.Image = My.Resources.back
        shuffle()

    End Sub

    Public Sub shuffle()

        Try
            number_of_cards = 52

            For i = 0 To number_of_cards
                switch = Int(Rnd() * number_of_cards)

                tempval = value(i)
                value(i) = value(switch)
                value(switch) = tempval

                tempcard = card(i)
                card(i) = card(switch)
                card(switch) = tempcard

            Next
        Catch ex As Exception

        End Try
    End Sub


End Class

Thanks for your input!!

-J

BTW, Jim this defines me to a T....

By doing just a little every day, I can gradually let the task completely overwhelm me. (©Ashleigh Brilliant)

Atleast I know I'm not the only one that feels that way...LOL.

-J

I woud suggest to try a structure like

Public Struct Card
    Public [Image] as Image
    Public Value as Integer
End Struct

Then You define an array of Card

Dim Cards(51) as Card

After that, to initialize you can

Cards(0).Image = My.Resources.twoc
Cards(0).Value = 1
.
.
.
Cards(51).Image = My.Resources.aced
Cards(51).Value = 13

To switch the cards you need a

Dim tempCard as Card

And

tempCard = Card(i)
Card(i) = Card(switch)
Card(switch) = tempCard

Hope this helps

This is exactly what I was looking for

Cards(0).Image = My.Resources.twocCards(0).Value = 1...Cards(51).Image = My.Resources.acedCards(51).Value = 13Cards(0).Image = My.Resources.twoc
Cards(0).Value = 1
.
.
.
Cards(51).Image = My.Resources.aced
Cards(51).Value = 13

Yes, that helps a lot. I will prolly not close this out because I could be back...LOL. Thanks again!!

-J

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.