Slow Solution
Here is the slow solution of the ASCII file import.
| inFile db note values |
"Startup runtime system"
AbtLnEnvironment startUp.
"Open the import database"
db := AbtLnConnection local openDatabase: 'vasample\perf.nsf'.
"Open the text file"
inFile := CfsReadFileStream open: 'c:\notes\data\vasample\test.txt'.
"Read lines till the end of the file"
[inFile atEnd] whileFalse: [
"Convert line into a collection, words are tab (9) separated"
values := inFile nextLine subStrings: (9 asCharacter).
"Create a new document from the form definition"
"Execute the default value formulas"
"This is time consuming !!"
note := db newNoteFromComputedForm: 'CustomerData'.
"Set values"
note at: 'Name' put: (values at: 1).
note at: 'Zip' put: (values at: 2).
note at: 'Sales' put: ((values at: 3) asNumber ).
"store the document"
note store.
].
"Close the database and the file"
db close.
inFile close.
"Shutdown runtime system"
AbtLnEnvironment shutDown.
After importing the data comes the second part of the job: Find the best sales for a certain region (defined by the first digit of the zip code).
| inFile db highScore zipRegion zipScore currentScore time |
"Start runtime system"
AbtLnEnvironment startUp.
"Open the database"
db := AbtLnConnection local openDatabase: 'vasample\perf.nsf'.
"Initialize the highscore dictionary"
highScore := Dictionary new.
"Read every note"
"This is time consuming because you actually have to open
every note in the database"
db allNotes do: [ :note |
note fill.
"Find the zip region and compare the sales"
zipRegion := ((note at: 'Zip' ) at: 1).
currentScore := (note at: 'Sales').
zipScore := highScore at: zipRegion
ifAbsent: [ highScore at: zipRegion put: currentScore.].
(zipScore <= currentScore)
ifTrue: highScore at: zipRegion put: currentScore ]
].
db close.
AbtLnEnvironment shutDown.
Last modified date: 01/29/2015