Page 1 of 1

How to sort the records of a text database file

Posted: Sat Sep 04, 2010 2:23 am
by alex298
Hello,

I have a .csv text database file with about 2,000 records. The content of the .csv text file is something like:
Peter,30,35000,Mary
David,28,68000,Single
...........................
...........................
...........................
I need to sort the Age (30, 28........) in Ascending and Descending order and put into a field. I am thinking and trying for a few hours. However it seems not an easy task.

Anybody has done similar task before? Could you please share your ideas or codes?

Thanks and best regards

Re: How to sort the records of a text database file

Posted: Sat Sep 04, 2010 9:47 am
by Klaus
Hi Alex,

...
sort lines of your_var_with_csv_content numeric by item 2 of each
## sort lines of your_var_with_csv_content descending numeric by item 2 of each
...

should do the job :D


Best

Klaus

Re: How to sort the records of a text database file

Posted: Sat Sep 04, 2010 10:38 am
by alex298
Hi Klaus,

Thanks for your help.

I am consider using the Data Grid. It seems a better solution. However I have some problem in importing the .csv text file.

The data structure of the csv file is something like, for example:
Staff Number, Staff Address, Staff Age, Staff Salary
I knew how to import a single column:
put ("file:Files/staff_list.txt") into tempFile
put url tempFile into tFile

put empty into tDatei

## Link all daten
Repeat for each line i in tFile
put item 1 of i & CR after tDatei
End Repeat

put "Staff Number" & cr & tDatei into theText

## Let Data Grid know that first line has column names
put true into firstLineContainsColumnNames
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid 1" to theText
I tried some times but still cannot figure out how to link all codes together so that all columns can be imported at the same time.

Please help!

Thanks and best regards

Re: How to sort the records of a text database file

Posted: Sat Sep 04, 2010 11:05 am
by Klaus
Hi Alex,

just:

Code: Select all

...
## maybe sort your_var_with_csv_content first?
replace COMMA with TAB in your_var_with_csv_content
put "Staff Number" & TAB & "Staff Address" & TAB & "Staff Age" & TAB & "Staff Salary" & CR before your_var_with_csv_content
set the dgtext[TRUE]  of grp "your data grid here" to your_var_with_csv_content
## HINT! This (dgtext[true]) requires that all necessary columns have already been created!
...
Not tested, but should work :D


Best

Klaus

Re: How to sort the records of a text database file

Posted: Mon Sep 06, 2010 11:12 am
by alex298
Hi Klaus,

Thanks, it works perfectly :D

Best regards