Adding two different object arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cmdolcet69
    New Member
    • Sep 2007
    • 25

    Adding two different object arrays

    I have created two different object arraylist of n size. Once my first arraylist is full and no number are unique i will test again this time putting the second test values in arraylist 2. how can i then take the results in my arraylist1 and arraylist2 add each of the indexs and average them out.

    arraylist1 (0) 400
    (1) 401
    (2) 402

    arraylist2 (0) 399
    (1) 400
    (2) 401

    then add arraylist1 + arraylist2 / number of arraylist = avgarraylist


    can anyone help me out. I thought about a for each loop however that not working.
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    This may work:

    [code=vb]
    Dim i As Long
    For i = LBound(ArrList1 ) To UBound(ArrList1 )
    ArrList3(i) = (Arrlist1(i) + ArrList2(i)) / 2
    Next
    [/code]

    Just Check both of the Arrays, Should Have Same Higher and Lower Bound..
    If not, then you can put a "If" Condition in the Loop...

    Regards
    Veena

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Originally posted by cmdolcet69
      I have created two different object arraylist of n size. Once my first arraylist is full and no number are unique i will test again this time putting the second test values in arraylist 2. how can i then take the results in my arraylist1 and arraylist2 add each of the indexs and average them out.

      arraylist1 (0) 400
      (1) 401
      (2) 402

      arraylist2 (0) 399
      (1) 400
      (2) 401

      then add arraylist1 + arraylist2 / number of arraylist = avgarraylist


      can anyone help me out. I thought about a for each loop however that not working.
      i think a FOR or a LOOP actualy will do, try something like

      [CODE=vb]dim i as integer
      for i = 0 to ubound(arraylis t1)
      avgarraylist(i) = (arraylist1(i)+ arraylist2(i)) / 2
      next[/CODE]

      HTH

      **Sorry Veena, i didnt see you've already answered.
      Last edited by kadghar; Oct 26 '07, 03:13 PM. Reason: Adding a comment

      Comment

      • cmdolcet69
        New Member
        • Sep 2007
        • 25

        #4
        Originally posted by kadghar
        i think a FOR or a LOOP actualy will do, try something like

        [CODE=vb]dim i as integer
        for i = 0 to ubound(arraylis t1)
        avgarraylist(i) = (arraylist1(i)+ arraylist2(i)) / 2
        next[/CODE]

        HTH

        **Sorry Veena, i didnt see you've already answered.
        [CODE]
        Dim AVGarraylist As New ArrayList
        Dim intloop1 As Long
        For intloop1 = LBound(_ArrayLi st1) To UBound(_Arrayli st2)
        AVGarraylist(in tloop1) = (_ArrayList1(in tloop1) + _Arraylist2(int loop1)) / 2
        Next

        /[CODE]

        it give me an error message system.collecti on.arraylist can not be converted to system.array

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          Originally posted by cmdolcet69
          it give me an error message system.collecti on.arraylist can not be converted to system.array
          try defining it with:
          dim AVGarraylist() as double
          redim AVGarraylist(ub ound(arraylist1 ))

          HTH

          Comment

          Working...