Question about reading a data file as numeric.

Started by nrh7, July 11, 2024, 01:50:39 PM

Previous topic - Next topic

nrh7

Hello team!

I'm having a little doubt in something I'm trying to do.

I have this small code:


02150 LIST_BOX LOAD ACCOUNTS.CTL,""
02190 LET CH1=HFN
02200 OPEN (CH1,IOL=*)"dta_ACCOUNTS"
02230 SELECT IOL=ACCOUNTS_IOL FROM (CH1),KNO=1
02261 LIST_BOX LOAD ACCOUNTS.CTL,0,STR(KEY)+SEP+ACCOUNTNUMBER$+SEP+ACCOUNTNAME$
02270 NEXT RECORD
02280 CLOSE (CH1)
02330 RETURN

I tried to run this code to load the listbox in order of account number hence the KNO=1, that worked well, BUT it's loading the listbox in alphanumeric manner since the account number is an string variable, like:

300
3100
315

Leaving the variable as string, is there a way to read the file as if it where numeric so that it sorts the data in numeric order when filling the listbox?

Like:
300
315
3100

Thanks a lot!

Cedric

If you want to keep your data in a string, I think you should PAD your string to the left before saving to your database if that field is part of a key. 

So in your database, the data would be something like:

"       300"
"       315"
"      3100"

I'm not sure what these numbers are, but if they are a unique no, like a customer number for example, we would pad to the left with zeros instead of blanks.

Perhaps there's a better way, but this is how we do it.

nrh7

Ah great thanks for the reply.

I "think" I saw somewhere some day to either READ or SELECT from a data file as if they were numeric but I don't really remember where.

If not I'll have to try some different option like PAD.

John Spencer

Hello:

If your account number column is defined as numeric in the list_box (ie [Column]N10)you can:

ACCOUNTS.CTL'sort = 2

after you finish loading and it will display in ascending numeric order based on column 2.

This way you can leave your data 'as-is'.

Hope this helps.



John Spencer