How do you initialize and check if image tags are equal to each other?
-
I'm a newbie, but stuck in a loop on this one... I'm trying to take 13 cards (Hearts 0 -12) which are already set up in design view and check to see if their tag number (also 0 - 12) is equal to the tag number of another 13 cards (Image 1 0 - 12) of another suit. How do I do this w/out the compiler seeing that both hearts and Image1 are already equal to each other.....I'll explain more... such as: For Index = 0 To 12 For NewIndex = 0 - 12 'I initialized this to go through the suits in a loop, but what I'm trying to do is see if the tags are equal, as in: If Image1(Index).Tag = Hearts(NewIndex).Tag Then.....yadahyadah Else, yadahyadah 'But if I do this, then it will always equal, because the integers index and newindex were set to 0.....does this question make any sense? I'm trying to loop through the cards and check to see if their tags are equal so I can do things with the cards... Thanks in advance.
-
I'm a newbie, but stuck in a loop on this one... I'm trying to take 13 cards (Hearts 0 -12) which are already set up in design view and check to see if their tag number (also 0 - 12) is equal to the tag number of another 13 cards (Image 1 0 - 12) of another suit. How do I do this w/out the compiler seeing that both hearts and Image1 are already equal to each other.....I'll explain more... such as: For Index = 0 To 12 For NewIndex = 0 - 12 'I initialized this to go through the suits in a loop, but what I'm trying to do is see if the tags are equal, as in: If Image1(Index).Tag = Hearts(NewIndex).Tag Then.....yadahyadah Else, yadahyadah 'But if I do this, then it will always equal, because the integers index and newindex were set to 0.....does this question make any sense? I'm trying to loop through the cards and check to see if their tags are equal so I can do things with the cards... Thanks in advance.
nested for loops work like this: for x = 0 to 9 for y = 0 to 9 do something here next y next x The code at "do something here" will be executed 100 times, like so: x = 0, y = 0 x = 0, y = 1 ... x = 0, y = 9 x = 1, y = 0 ... See? If you set your loops up this way, you will definitely compare every item in X with every item in Y, but it's not particularly efficient. You probably want to stop processing once you find a matching tag?
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010
-
nested for loops work like this: for x = 0 to 9 for y = 0 to 9 do something here next y next x The code at "do something here" will be executed 100 times, like so: x = 0, y = 0 x = 0, y = 1 ... x = 0, y = 9 x = 1, y = 0 ... See? If you set your loops up this way, you will definitely compare every item in X with every item in Y, but it's not particularly efficient. You probably want to stop processing once you find a matching tag?
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010
Thanks for the advice. I tried something like the following, but when I tried placing the Next, Next lines just below the 'Hearts(Index).Tag = Source.Tag, the compiler gave me an error 340, array element 13 does not exist. It doesn't when I place the Next's at the end. However, what happens at run time is the You're right always happens, and then the card I choose from the left (can be any card), would always appear on the right hand side in hearts(0) slot. I'm confused but think that since Index and NewIndex are set to 0, they will always match and always do vbenddrag, not vbcancel. Any ideas would be much appreciated. Thank you. 'For Index = 0 To 12 'For NewIndex = 0 To 12 'Hearts(Index).Picture = Source.Picture 'Hearts(Index).Tag = Source.Tag 'If Hearts(Index).Tag = Image1(NewIndex).Tag Then 'Image1(NewIndex).Drag vbEndDrag 'MsgBox ("You're right!") 'Exit Sub 'Else 'Image1(NewIndex).Drag vbCancel 'Exit Sub 'End If 'Next 'Next 'End Sub
-
Thanks for the advice. I tried something like the following, but when I tried placing the Next, Next lines just below the 'Hearts(Index).Tag = Source.Tag, the compiler gave me an error 340, array element 13 does not exist. It doesn't when I place the Next's at the end. However, what happens at run time is the You're right always happens, and then the card I choose from the left (can be any card), would always appear on the right hand side in hearts(0) slot. I'm confused but think that since Index and NewIndex are set to 0, they will always match and always do vbenddrag, not vbcancel. Any ideas would be much appreciated. Thank you. 'For Index = 0 To 12 'For NewIndex = 0 To 12 'Hearts(Index).Picture = Source.Picture 'Hearts(Index).Tag = Source.Tag 'If Hearts(Index).Tag = Image1(NewIndex).Tag Then 'Image1(NewIndex).Drag vbEndDrag 'MsgBox ("You're right!") 'Exit Sub 'Else 'Image1(NewIndex).Drag vbCancel 'Exit Sub 'End If 'Next 'Next 'End Sub
You are never getting further than once through, as your code exits the sub regardless of whether heart(index).tab = image1(newindex).tag or not - you have exit sub in both the if and the else!!
ymilan wrote:
'If Hearts(Index).Tag = Image1(NewIndex).Tag Then 'Image1(NewIndex).Drag vbEndDrag 'MsgBox ("You're right!") 'Exit Sub <<<<<<<<<<<<<<<<<< HERE 'Else 'Image1(NewIndex).Drag vbCancel 'Exit Sub <<<<<<<<<<<<<<<<<<< HERE ALSO 'End If
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010
-
You are never getting further than once through, as your code exits the sub regardless of whether heart(index).tab = image1(newindex).tag or not - you have exit sub in both the if and the else!!
ymilan wrote:
'If Hearts(Index).Tag = Image1(NewIndex).Tag Then 'Image1(NewIndex).Drag vbEndDrag 'MsgBox ("You're right!") 'Exit Sub <<<<<<<<<<<<<<<<<< HERE 'Else 'Image1(NewIndex).Drag vbCancel 'Exit Sub <<<<<<<<<<<<<<<<<<< HERE ALSO 'End If
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010
Hello, I tried to take them out and then the Msgbox messages would run in an incessant loop at runtime. I took the message boxes out and tried this; but no card from the image1 side shows up over the card in the hearts side. It is just blank. Code? Sorry, I'm such a newbie... If X <= 12 And Y <= 12 Then Hearts(X).Picture = Source.Picture Image1(Y).Picture = Hearts(X).Picture X = X + 1 Y = Y + 1 End If 'should initialize those deck positions right in the array? For X = 0 To 12 <<<<should I use these For's? For Y = 0 To 12 Image1(X).Tag = Hearts(Y).Tag <or should I just start with this? But then X and Y will always = each other and it won't go to next lines....it will stop at here. If Hearts(Y).Tag = Image1(X).Tag Then Image1(X).Drag vbEndDrag <<<<<is this where I'm messing up? 'MsgBox ("You're right!") Else Image1(X).Drag vbCancel 'MsgBox ("You're wrong.") End If Next Next End Sub
-
Hello, I tried to take them out and then the Msgbox messages would run in an incessant loop at runtime. I took the message boxes out and tried this; but no card from the image1 side shows up over the card in the hearts side. It is just blank. Code? Sorry, I'm such a newbie... If X <= 12 And Y <= 12 Then Hearts(X).Picture = Source.Picture Image1(Y).Picture = Hearts(X).Picture X = X + 1 Y = Y + 1 End If 'should initialize those deck positions right in the array? For X = 0 To 12 <<<<should I use these For's? For Y = 0 To 12 Image1(X).Tag = Hearts(Y).Tag <or should I just start with this? But then X and Y will always = each other and it won't go to next lines....it will stop at here. If Hearts(Y).Tag = Image1(X).Tag Then Image1(X).Drag vbEndDrag <<<<<is this where I'm messing up? 'MsgBox ("You're right!") Else Image1(X).Drag vbCancel 'MsgBox ("You're wrong.") End If Next Next End Sub
Where are you actually setting the tags? Try getting rid of the "you're wrong" message box and the drag cancel etc, and just get it to say "you're right" when you find the right tag. This will help you work out that your checking routine is working correctly.
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010
-
Where are you actually setting the tags? Try getting rid of the "you're wrong" message box and the drag cancel etc, and just get it to say "you're right" when you find the right tag. This will help you work out that your checking routine is working correctly.
Knowledge is knowing that the tomato is a fruit. Wisdom is not putting it in fruit salad!! Booger Mobile - Camp Quality esCarpade 2010
This what I'm trying to do, but what happens is "it is always right" and with "any" card I put into any hearts slot on the right, will put that card right up at hearts(0) and say, you're right. How do I initialize the cards pictures to equal each other, then use next and next for the "for's in the beginning, then question whether the tags = each other. The tag numbers are set in design view. Here's my code: Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single) Dim NewIndex As Integer For Index = 0 To 12 For NewIndex = 0 To 12 Hearts(Index).Picture = Source.Picture Source.Picture = Image1(NewIndex).Picture If Hearts(Index).Tag = Image1(NewIndex).Tag Then Image1(NewIndex).Drag vbEndDrag MsgBox ("You're right!") Exit Sub Else Image1(NewIndex).Drag vbCancel MsgBox ("This card does not belong here") Exit Sub End If Next Next End Sub