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. comparing values on fields in arraylists

comparing values on fields in arraylists

Scheduled Pinned Locked Moved Visual Basic
question
21 Posts 3 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.
  • S ssbelfast

    thanks but these are arraylists, not arrays so yes the data rows look like this +-----------+ +-----------+ | StrList1 | | StrList2 | +-----------+ +-----------+ | 0 | Jenny | | 0 | Jenny | | 1 | Fred | | 1 | Fred | | 2 | Sony | | 2 | Rudy | | 3 | Marti | | 3 | Marti | | 4 | Rudy | | 4 | Sony | +-----------+ +-----------+ And yes, I want to count the number of times the second value in each row matches, i;e Jenny = Jenny 1, Fred = Fred 2, Sony not = Rudy etc But arraylists are one dimensional Okay, no problem I think because 0 Jenny is still = 0 Jenny; i;e; if I have 0 Jenny and 1 Jenny, it's not a match, its only a match when every thing in the datarow is the same So I tried this with the arraylist, assuming a one dimensional arraylist Dim RowIdx() As Integer = {} For r As Integer = 0 To 9 If arraylist1(r) = arraylist2(r) Then Dim x As Integer = RowIdx.GetUpperBound(0) ReDim RowIdx(x + 1) Dim y As Integer = RowIdx.GetUpperBound(0) RowIdx(y) = i End If Next but I get the same error message I've been getting all lone Operator is not valid for type ( field name) I've had the logic working for arrays, but the program uses arraylists I've tried copying the arraylist to an array, but it doesn't work

    N Offline
    N Offline
    Nouvand
    wrote on last edited by
    #21

    Or... Here we have 2 array list ArrList1 -------- arrayA1 * arrayA2 * arrayA3 * arrayA4 * -------- ArrList2 -------- ArrayB1 * arrayB2 * arrayB3 * arrayB4 * -------- *= 1 dimensional array. Lets say you want to compare arrayA2(n).Length with arrayB2(n).Length. But before we compare the values, we need to compare the bounds of arrays. ----------------------- Dim x as integer = ArrList1.GetUpperBound(0), _ y as integer = ArrList2.GetUpperBound(0) if x = y then For i as integer = 0 to x If ArrList1(i).Length = ArrList2(i).Length Then 'put your code here End If Next End If You can't compare "arraylist1(r) = arraylist2(r)" because the value on both side is an array, not property of array. Every array has properties(Length, UpperBound, LowerBound, i;e) I mean you can't compare your gf with your friend's gf, except they properties such as skin color, cute face, height, etc. ;P Here sample code to copy an array from array list to a new array: Dim newarr As Object() = ArrList1(1).Clone Good Luck -- modified at 4:59 Friday 4th August, 2006

    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