473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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",2004
6.7,"July",2003
18.3,"June",2004
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.

Jul 17 '05 #1
2 4355
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("Index") = dblIndex
RS.Fields("Month") = intMonth
RS.Fields("Year") = intYear
RS.Update

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

"Terry" <TR*****@aol.com> wrote in message
news:1106222107.ead5bf9368f49d6833298cede41b531c@t eranews...
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",2004
6.7,"July",2003
18.3,"June",2004
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.

Jul 17 '05 #2

"Terry" <TR*****@aol.com> wrote in message
news:1106222107.ead5bf9368f49d6833298cede41b531c@t eranews...
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",2004
6.7,"July",2003
18.3,"June",2004
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.

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)
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
2
by: D. Roshani | last post by:
Hello ! I wonder if any one can help me to create a cosomize sorting order (as Macro or added small program in c++ or c# which does this work) in a Access Database contaning one table only words...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
2
by: mahesh123 | last post by:
Hi, I am using gridview in my form and binded the gridview with object datasource.I am trying to implement sorting for my grid view and i am getting following error.i am using asp.net with VB ...
5
by: lemlimlee | last post by:
hello, this is the task i need to do: For this task, you are to develop a Java program that allows a user to search or sort an array of numbers using an algorithm that the user chooses. The...
3
by: nagmvs | last post by:
Hi to all I have one table with 6 columns and 20 rows.I want to sort each and every column when i click the column name in the table. for sorting i create one more page.when i click the column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.