Results 1 to 7 of 7

Thread: searching array values in another array

  1. #1

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    searching array values in another array

    hi, i have retreive my database values and stored in arrays ie i am retreiving worked dates ans stored the retreived dates in one array named as arr1.then i have some dates in another array named as arr2.so i want to
    check whether arr2 dates are present in arr1 array,if present means i need to show the dates, please tel me how to do and please give me sample coding

  2. #2
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: searching array values in another array

    Quote Originally Posted by karthikeyan
    hi, i have retreive my database values and stored in arrays ie i am retreiving worked dates ans stored the retreived dates in one array named as arr1.then i have some dates in another array named as arr2.so i want to
    check whether arr2 dates are present in arr1 array,if present means i need to show the dates, please tel me how to do and please give me sample coding
    I don't know why you want to store your database query result in an array rather than in a recordset but anyway try this:

    VB Code:
    1. Dim ForCounter as Integer
    2. Dim ForCounter2 as Integer
    3. For ForCounter = 0 to Ubound(arr1).Count - 1
    4.      For ForCounter2 = 0 Ubound(arr2).Count - 1
    5.           If arr1(ForCounter) = arr2(ForCounter2) Then
    6.                'Dates Matched wohoo
    7.           Else
    8.           End If
    9.      Next
    10. Next

    Hope this helps you
    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

  3. #3

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: searching array values in another array

    hi tommygrayson thanks a lot nice reply

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: searching array values in another array

    VB Code:
    1. For Each dt As Date In arr1
    2.     If arr2.IndexOf(dt) <> -1 Then
    3.         MessageBox.Show(dt.ToString() & " is contained in both arrays.")
    4.     End If
    5. Next dt
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: searching array values in another array

    hi jmcilhinney,

    if i use this it gives error:
    over load resolution failed becos no accssible 'IndexOf' accepts this no of arguments

    For Each dt As Date In arr1
    If arr2.IndexOf(dt) <> -1 Then
    MessageBox.Show(dt.ToString() & " is contained in both arrays.")
    End If
    Next dt

    give me sugestion to recover that error please

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: searching array values in another array

    Ah, sorry. That's what comes from typing straight into the forum rather than pasting from the IDE. This:
    VB Code:
    1. arr2.IndexOf(dt)
    should be this:
    VB Code:
    1. Array.IndexOf(arr2, dt)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: searching array values in another array

    hi jmcilhinney,nice very nice,i got it,cute reply,thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width