Sorting help please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Terry

    Sorting help please

    I have a text file with an unknown number of entries in it. The data
    in the text file is in this format:

    22.9,"June",200 4
    6.7,"July",2003
    18.3,"June",200 4


    dblIndex, strMonth, intYear

    How do I sort these by date (from newest to oldest) and if the records
    have the same date, from lowest dblIndex to highest?

    Any help with this problem would be greatly appreciated.

  • James L Hill

    #2
    Re: Sorting help please

    I would approach this problem with a two fold solution. First convert the
    months to numeric for ease of sorting. I would use a Case Statment for that.
    Then store the data in a database which you can then retrieve in any order
    you like.

    Dim dblIndex As Double
    Dim strMonth As String
    Dim intYear As Integer
    Dim intMonth As Integer
    Dim filename As String


    Open filename For Input As #1
    Input #1, dblIndex, strMonth, intYear

    'Convert Month to numeric
    Select Case strMonth
    Case "Jan", "January", UCase("January" )
    intMonth = 1

    Case "Feb", "Febuary", UCase("Febuary" )
    intMonth = 2

    Case "Mar", "March", UCase("March")
    intMonth = 3

    Case "Apr", "April", UCase("April")
    intMonth = 4
    ....
    End Select

    Add record to database:
    Dim RS As Recordset
    ....
    RS.Fields("Inde x") = dblIndex
    RS.Fields("Mont h") = intMonth
    RS.Fields("Year ") = intYear
    RS.Update

    Retrieve record in asc order:
    RS.open "Select * From database Order By Year,Month,Inde x", conn,
    adOpenDynamic



    "Terry" <TRock98@aol.co m> wrote in message
    news:1106222107 .ead5bf9368f49d 6833298cede41b5 31c@teranews...[color=blue]
    > I have a text file with an unknown number of entries in it. The data
    > in the text file is in this format:
    >
    > 22.9,"June",200 4
    > 6.7,"July",2003
    > 18.3,"June",200 4
    >
    >
    > dblIndex, strMonth, intYear
    >
    > How do I sort these by date (from newest to oldest) and if the records
    > have the same date, from lowest dblIndex to highest?
    >
    > Any help with this problem would be greatly appreciated.
    >[/color]


    Comment

    • Bob Walpole

      #3
      Re: Sorting help please


      "Terry" <TRock98@aol.co m> wrote in message
      news:1106222107 .ead5bf9368f49d 6833298cede41b5 31c@teranews...[color=blue]
      >I have a text file with an unknown number of entries in it. The data
      > in the text file is in this format:
      >
      > 22.9,"June",200 4
      > 6.7,"July",2003
      > 18.3,"June",200 4
      >
      >
      > dblIndex, strMonth, intYear
      >
      > How do I sort these by date (from newest to oldest) and if the records
      > have the same date, from lowest dblIndex to highest?
      >
      > Any help with this problem would be greatly appreciated.[/color]


      I had a similar problem
      my approach was to calculate the days from a arbiatary date assuming yours
      dates are in a List (List)

      For a = 0 To List.ListCount - 1
      dte = List.List(a)
      numberofdays = DateDiff("d", 1 / 1 / 1900, dte)
      temp = Str(numberof days)
      'To be sure that each day length is the same eg. 45, 4400 become 000045,
      004400 for correct sort
      Do Until Len(temp) > 6
      temp = temp & "0"
      Loop
      'Put into a sorted list (lList1)
      List1.List(a) = temp & "|"& List.List(a)
      ' | to work in the split function to retrieve date part
      'You can then retrieve them forwards or backwards using For a= (Start or
      End) Step (1 or -1)


      Comment

      Working...