Results 1 to 11 of 11

Thread: Using Arrays....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98

    Using Arrays....

    Alrighty...

    I want to say:

    Code:
    If <Variable> = Array1(<any item in the array>) then
    do something
    end if
    But i cant just use Array() or array

    Second,

    Can you alphabitize objects in an array?

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Dim ary() As String = {"one", "two", "three"}
    2.  
    3. If ary(1) = "two" Then
    4. MessageBox.Show("second element is : Two")
    5. End If

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Maybe you mean this one .
    VB Code:
    1. Dim ary() As String = {"one", "two", "three"}
    2.         Dim str As String = "two"
    3.  
    4.         If str = ary(1) Then
    5.             MessageBox.Show("second element is : Two")
    6.         End If

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Depending on what is contained in the array you can probably use:
    VB Code:
    1. Dim ary() As String = {"one", "two", "three"}
    2.         Dim idx As Integer=ary.IndexOf("one")
    3.         If idx > -1 Then
    4.             MessageBox.Show(String.Format("Found in element: {0}",idx))
    5.         End If

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98
    I think E is more twards what i want, but havent tested it, will that check the whole array for what im looking for?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98
    Dim idx As Integer=ary.IndexOf("one")


    that isnt working for me

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Yes and return the index of the first found match. Although if the array contains objects then it may try to match an instance which can be tricky. Although I'm not sure of this, I haven't actually tested it yet.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98
    Well, i want it to do something if there is NO match

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    It returns -1 if there is no match found.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98
    Ah cool, but...

    users.LastIndexOf(uid)

    Overload resolution failed because no accessible 'LastIndexOf' accepts this number of arguments.

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You are using the wrong method its not LASTIndexOf its just IndexOf.

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