Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How do you initialize and check if image tags are equal to each other?

How do you initialize and check if image tags are equal to each other?

Scheduled Pinned Locked Moved Visual Basic
questiondatabasedesignhelp
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ymilan
    wrote on last edited by
    #1

    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.

    _ 1 Reply Last reply
    0
    • Y ymilan

      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.

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      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

      Y 1 Reply Last reply
      0
      • _ _Damian S_

        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

        Y Offline
        Y Offline
        ymilan
        wrote on last edited by
        #3

        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

        _ 1 Reply Last reply
        0
        • Y ymilan

          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

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #4

          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

          Y 1 Reply Last reply
          0
          • _ _Damian S_

            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

            Y Offline
            Y Offline
            ymilan
            wrote on last edited by
            #5

            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

            _ 1 Reply Last reply
            0
            • Y ymilan

              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

              _ Offline
              _ Offline
              _Damian S_
              wrote on last edited by
              #6

              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

              Y 1 Reply Last reply
              0
              • _ _Damian S_

                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

                Y Offline
                Y Offline
                ymilan
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups