Connecting Tech Pros Worldwide Forums | Help | Site Map

Finding the Next (Duplicate) Record

Newbie
 
Join Date: Aug 2008
Posts: 6
#1: Nov 7 '08
Hi all,
I am currently involved in a project where I am working with some label arrays. My Problem is that I am using a button that is supposed to find a duplicate label in the array, but I am not sure how to do this....The code that I have right now is actually going to the next label in the array, but not the next duplicate array. Can anybody please help me with this problem??? I will highly appreciate the help. Thank you so much!!!

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,131
#2: Nov 7 '08

re: Finding the Next (Duplicate) Record


Could you please post the code that is currently checking the labels and explain in more detail what it's supposed to be doing.(Please remember to use code tags when posting code snippets).

-Frinny
Newbie
 
Join Date: Aug 2008
Posts: 6
#3: Nov 13 '08

re: Finding the Next (Duplicate) Record


I sure can explain it in more detail by giving an example. Lets say there is an array of Labels with texts like "H1", "H2", "H3", "H4", "H1", "H4", so on and so forth. I want a code that actually, finds the labels with same text....It is easy to find if there are different labels. But I am having difficulty as it is a label array. Also, the label array is spread out on different pages, which makes it even more difficult. Any help is appreciated!!!
vanc's Avatar
Expert
 
Join Date: Mar 2007
Posts: 202
#4: Nov 13 '08

re: Finding the Next (Duplicate) Record


Quote:

Originally Posted by pray2me

I sure can explain it in more detail by giving an example. Lets say there is an array of Labels with texts like "H1", "H2", "H3", "H4", "H1", "H4", so on and so forth. I want a code that actually, finds the labels with same text....It is easy to find if there are different labels. But I am having difficulty as it is a label array. Also, the label array is spread out on different pages, which makes it even more difficult. Any help is appreciated!!!

If you store labels in an array then just go into the array and compare the Text value. I don't see any difficulties here or I miss something?
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Nov 14 '08

re: Finding the Next (Duplicate) Record


You said your code is not doing the right thing. Post it and maybe we can see if there is more to all this.
Newbie
 
Join Date: Aug 2008
Posts: 6
#6: Nov 14 '08

re: Finding the Next (Duplicate) Record


Expand|Select|Wrap|Line Numbers
  1. Public Sub SelectItem(ByVal intSelectedItem As Integer)
  2.  
  3.         Dim i As Integer = 0
  4.         Dim intFound As Integer = 0
  5.  
  6.  
  7.         For i = intItemXrefSize To 1 Step -1
  8.             If intSelectedItem >= intItemXrefArray(i) Then
  9.                 intFound = i
  10.                 Exit For
  11.             End If
  12.         Next
  13.  
  14.  
  15.         If intFoundPos <> Me.intItemXrefIndex Then
  16.  
  17.             intItemXrefIndex = intFound
  18.  
  19.             FillListPage(intItemXrefIndex)
  20.         End If
  21.  
  22.  
  23.  
  24.         For i = 1 To Me.intItemMax
  25.             If intLabelXref(i) = intSelectedItem Then
  26.                 intFoundPos = i
  27.                 Exit For
  28.             End If
  29.         Next                                  
  30.  
  31.         ItemScreenList(intFound)
  32.  
  33.     End Sub
  34.  
  35.  
  36.     Private Sub ItemScreenList(ByVal intScreenList As Integer)
  37.  
  38.         gintSelectedItem = intLabelXref(intScreenList)
  39.  
  40.         If gintSelectedItem = 0 Then
  41.  
  42.             intScreenList += 1
  43.             If intScreenList <= intItemMax Then
  44.                 gintSelectedItem = intLabelXref(intScreenList)
  45.  
  46.                 If gintSelectedItem = 0 Then
  47.                     Exit Sub
  48.                 End If
  49.             Else
  50.                 Exit Sub
  51.             End If
  52.         End If
  53.  
  54.         intCurrentScreenList = intScreenList
  55.         Me.picCurrentItem.Top = mlblItemArray(intCurrentScreenList).Top + 3
  56.  
  57.  
  58.                gintSelectedItem = intLabelXref(intScreenList)
  59.  
  60.              gobjSelectedItem = gobjXMLItem.Item(gintSelectedItem)
  61.  
  62.  
  63.  
  64.     End Sub
  65.  
  66.  
  67. Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
  68.  
  69.         If gintSelectedItem < gobjXMLCalendar.ItemCount Then
  70.             gintSelectedItem = gintSelectedItem + 1
  71.         End If
  72.  
  73.         SelectItem(gintSelectedItem)
  74.  
  75.     End Sub
  76.  
This is what I have done so far...but it goes to a next record instead of next duplcate record!!! Can anyone please help me!!! I appreciate it!!!
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,131
#7: Nov 15 '08

re: Finding the Next (Duplicate) Record


Your code isn't checking whether or not the label's text is the same as another.

You should be doing something like:

For everyLabel in myArrayOfLabels
DoesTheLabel.Text = theTextYoureLookingFor
If so: add the label to an array of "MatchingLabels"
Othererwise: don't do anything.

-Frinny
Newbie
 
Join Date: Aug 2008
Posts: 6
#8: Nov 17 '08

re: Finding the Next (Duplicate) Record


Hi Frinny,
Thank you so much for all your time!!! But can you explain a little more by giving a code example. Actually, i tried it but it doesn't work. I want to make sure that I am doing it correctly!!! Thank you
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,131
#9: Nov 17 '08

re: Finding the Next (Duplicate) Record


Somehow I find it really hard to believe that you cannot translate the pseudo code I mentioned above into VB syntax......

Here is an example of the pseudo code that mentioned above.
It is not guaranteed to work because I haven't tested it.

Expand|Select|Wrap|Line Numbers
  1. Dim theTextToLookFor As String = theLabelToCheck.Text 
  2. Dim theLabelsFound As List(Of Integer) 'Will contain all of the indexes of the labels whose text matches the one you're checking
  3.  
  4. For index As Integer = 0 to myArrayOfLabels.Length
  5.     Dim lbl As Label = myArrayOfLabels(index)
  6.     If String.Compare(theTextToLookFor,lbl.Text,True)=0 Then
  7.         theLabelsFound.Add(index)
  8.     End If
  9. Next
  10.  
  11. 'Now you need to process the Labels that you've found.
  12. 'I *Think* you're going to have to put this whole section of code within another loop so to loop through each label in the array and check for duplicates...I think...
  13.  
  14.  
Try implementing this solution.
If it doesn't do exactly what you want it to do (which I'm guessing that it wont) think about how you can modify the code to do what you want it to do...give that a try...and then if you are still having difficulties post the code that you have tried so that we can see what you are doing. We can't help you if you simply say "I tried something but it doesn't work"...you need to provide details on why it doesn't work and, to make it even more clear, you should post the snippet of code that you are having difficulties with.

Please do not post all of your code because this makes it hard for us to find exactly what you're talking about. Just post the code that you are having difficulties with.

Also please remember to use code tags when posting code snippets.

-Frinny
Newbie
 
Join Date: Aug 2008
Posts: 6
#10: Nov 20 '08

re: Finding the Next (Duplicate) Record


Thanks Frinny. I appreciate your help and your time. I will use the code tag next time...Thanks once again
Reply


Similar .NET Framework bytes