How to read in numbers lager then Integers?

Stellaferox

Active Member
Licensed User
Hi guys,

I fear I keep bugging you all with questions.......

I am trying (as suggested) to read in a textfile with Table and then sort it on the first key. The problem is that the numbers (strings actually) are larger then integers (e.g. 10131543907). Reading it in as a string gives sortingresults like 1,2,3,3302,4,41 etc.
How can I get a good result sorting? Do I need to convert the strings otherwise? I cannot enforce typecasting as int64.
Also representing the string in Scientific notation disregards the powers, only sorts on the number itself.
Thnx in advance and thank you for your time
Marc
 

specci48

Well-Known Member
Licensed User
Longtime User
I fear I keep bugging you all with questions.......
:sign0105: :)

If you declare the columns as cNumber first, the loaded data is treated as numbers and not as a string, even it is bigger than an int.
I tested this
B4X:
Sub App_Start
    Table1.AddCol(cNumber, "Col1", 100)
    Table1.AddCol(cNumber, "Col2", 100)
    Table2.AddCol(cNumber, "Column1", 0)
    Table2.AddCol(cNumber, "Column", 0)
    Table1.LoadCSV("test1.txt", "," ,False, False)
    Table1.TableSort("Col1 ASC")
    Form1.Show   
    For i = 0 To Table1.RowCount - 1
        Table2.AddRow(Table1.Cell("Col1",i),Table1.Cell("Col2",i))
    Next
    Table2.SaveCSV("test2.txt", "," ,False)
End Sub
with this data
B4X:
201315439073333,201315439073333
10131543907,10131543907
999999999999999,999999999999999
555555555555555,555555555555555
12131543907,12131543907
5,5
999912131543907,999912131543907
4,4
20131543907,20131543907
12131543907,12131543907
202315439073333,202315439073333
121,121
This works fine as long as the table does not use exponentials to store its numbers, e.g due to a row of 9999999999999999,9999999999999999.
In this case the sorting is still ok but the exponential view is written bach to the new file.


specci48
 

Stellaferox

Active Member
Licensed User
Specci48,

Thanks for your time and solution. It works like a charm! Now I can really make some speed on the PPC in running this this application.
Marc
 
Top