Link to home
Start Free TrialLog in
Avatar of DanielAttard
DanielAttardFlag for Canada

asked on

Problem with duplicate values in an array

I am having some diffuculty working with an array that contains duplicate values.  My array consists of the following:

CompArray(1) 11182
CompArray(2) 14490
CompArray(3) 14490
CompArray(4) 15800
CompArray(5) 34000
CompArray(6) 35842
CompArray(7) 35842
CompArray(8) 39976

What I am trying to do after this point is loop through the array and then assign a value if a certain condition is met.  The problem is that the values being assigned are not correct.  Here is the incorrect result which should be self-explanatory:

CompArray(1) 11182 is assigned Symbol = 208
CompArray(2) 14490 is assigned Symbol = 210  ' should be 209
CompArray(3) 14490 is assigned Symbol = 210
CompArray(4) 15800 is assigned Symbol = 211
CompArray(5) 34000 is assigned Symbol = 212
CompArray(6) 35842 is assigned Symbol = 214  ' should be 213
CompArray(7) 35842 is assigned Symbol = 214
CompArray(8) 39976 is assigned Symbol = 215

Could someone please help me to modify this code to account for the possibility of duplicate values in the array?  I'm having one heluva time teaching myself all this stuff in the last few days, but I'm stuck on this point.  Thanks for the help I know I will inevitably receive in minutes . . .

Here is the problem code:

    objRS.MoveFirst
    Dim x As Integer
    Do Until objRS.EOF
        For x = 1 To UBound(CompArray)
          If CompArray(x) = objRS.Fields(24).Value Then
             objRS.Pushpin.Symbol = intSymbol + x - 1
          End If
        Next
      objRS.MoveNext
    Loop
Avatar of DanielAttard
DanielAttard
Flag of Canada image

ASKER

ok, maybe not minutes . . .
ASKER CERTIFIED SOLUTION
Avatar of flavo
flavo
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Dave, but I am getting a "subscript out of range" error on the first pass through when x=1 in comparray(x).  it cannot evaluate comparray(x-1) if x=1.  Did i mention that this module is declared as option base 1?
Got it figured out.  I had to create a multi-dimensional array, and then check both elements to eliminate the possibility of a duplicate, rather than try to handle it.  This seems to work fine.

    objRS.MoveFirst
    Dim x As Integer
    Do Until objRS.EOF
        For x = 1 To UBound(CompArray)
          If (CompArray(x, 1) = objRS.Fields(1).Value) And (CompArray(x, 2) = objRS.Fields(24).Value) Then
             objRS.Pushpin.Symbol = 207 + x
          End If
        Next
      objRS.MoveNext
    Loop
Avatar of jadedata
DanielAttard:

  First,...thank you for the prior question!
  Second and more important...
    I am really freekin' impressed that you have gone from only minimal knowledge on arrays to this in just a couple days and only two questions!!!!  ( and more !!!!) and applying it to a process that would have most newer programmers yanking their hair out.  The concept of arrays has most new programmers scratching their head for a while.

  It's going to be no time at all before you are answering questions out here, and I'm looking forward to working with you in the MSAccess Forum!!

my kindest regards
Jack
Thanks for the kind words Jack, I appreciate it.

Since discovering EE, my interest in computing has shifted from "using" software to "developing" it for my own purposes.  I would not have been able to get to where I am without the patience and altruism shown by the dedicated experts at EE.  It really is an amazing concept - knowledge out of thin air~!  Within the last week I have begun to appreciate the power of the Object Browser and the Locals window.  No doubt the learning curve will speed up even more now!

Thank you for all the help you have given me since I became a member.  I appreciate it more than I can begin to explain.  

p.s.  I see from your profile that you are a former Navy officer.  My father spent 25 years in the Canadian Navy on board HMCS Haidi.  Perhaps one of these days I will consider hiring you to handle some of the more complex programming tasks I might want to consider implementing into my database.  We should discuss this some time via email.

See you around!
I was actually a Naval Petty Officer with posting with the U S Marines (my favorites!).
I see it didn't take EE_AI very long to get informed.  The membership agreement precludes going into negotiations in the technical areas.  But I very much appreciate the kind words!  (and might would take you up on it under the *proper* circumstances!)
-j-