Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:29:46+00:00 2026-05-25T23:29:46+00:00

I have a simple routine to find the next object based on a name

  • 0

I have a simple routine to find the next object based on a name property in an un-ordered collection of objects. I go through the collection and collect all the names in a List(of String) adding any names that are > my current name, which should give a list of everything that comes after the current key. I then sort the list using the default .Sort() method on the List(of String) and take the first item in the list, which should be my next item. I do the reverse to find the previous item, add all items < my current name, sort, and take the last item in the list.

However, this method skips over some items. For example I have items named 1210, 1210-ADA, and 1210_ADA_DB. Using this method, getting the next item skips the middle item 1210-ADA and finds 1210_ADA_DB, but finding the previous item seems to work.

If my process is correct, my only explanation is that the < and > operators compare differently than the .Sort() method. Is this true? What are the differences?

Code for finding next item:

        Dim Key As String = Name
        Dim NameList As New List(Of String)
        For Each obj As T In Collection
            Dim ObjKey As String = Obj.Key
            If  ObjKey > Key Then
                NameList.Add(ObjKey)
            End If
        Next
        If NameList.Count = 0 Then Return Nothing
        NameList.Sort()
        Dim NextKey As String = NameList.First
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:29:47+00:00Added an answer on May 25, 2026 at 11:29 pm

    I think you already found what the problem might be. But to annotate, you are getting bitten by some VB6 compat behavior. The default for Option Compare is Binary which uses String.CompareOrdinal(). Not what List.Sort() uses. Option Compare Text uses CultureInfo.CompareInfo.Compare() with the CompareOptions.IgnoreWidth, CompareOptions.IgnoreKanaType, CompareOptions.IgnoreCase options. Also not what List.Sort() uses.

    Avoid the operators and use String.Compare() instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do you have a simple debounce routine handy to deal with a single switch
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have simple routine to show tips in the textarea to the users. If
I have a simple ASP.NET 3.5 SP1 Web Forms app... I've added the System.Web.Routing
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have simple SSIS package which reads data from flat file and insert into
I have simple HTML code with some JavaScript. It looks like: <html> <head> <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.