Author Topic: Loading numbers  (Read 206 times)


  • Moderator
  • Member
  • *****
  • Posts: 13284
  • Assembly is fun ;-)
    • MasmBasic
Loading numbers
« on: September 07, 2022, 11:09:02 PM »
While putting strings into a text file makes sense, rather than have to convert numbers both ways, having a structure of your own design with as many numbers as you wish to preserve as structure members is fast to load, save and internally process. This is why I use a binary file for numbers that must be preserved.

include \masm32\MasmBasic\         ; download
  sName$        db 20 dup(?)
  sNumber       dd ?
  sItemPrice    REAL4 ?
  sItemTax      REAL4 ?
  sAvgWeight    REAL4 ?
  sTotalWeight  REAL4 ?

  Print cfm$("#  Price\tTax\tWeight\tItem\n")   ; describe the records in the first line
  Recall "Sales.dat", sales() As SALES
  For_ ecx=0 To eax-1
        PrintLine Str$(ecx+1), Str$("  %4f\t", sales(ecx, sItemPrice)), Str$("%3f\t", sales(ecx, sItemTax)), Str$("%i\t", sales(ecx, sAvgWeight)), addr sales(ecx, sName$)

Output (using the attached Sales.dat):
Code: [Select]
#  Price        Tax     Weight  Item
1  100.00       23.5    5       Vacuum cleaner
2  20.00        3.45    2       Accessories
3  50.00        6.45    22      Item #3
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.