1. EDB Question
- Posted by tbohon Nov 30, 2015
- 1225 views
Trying to count and display number of records in a simple EDB file. Pretty sure I have the logic correct below but when it prints it shows a graphics character rather than a number so I'm missing something ... and it's driving me nuts!
Any help you can provide is most appreciated.
Thanks.
Tom
procedure show_count(file_number f) atom rcount rcount = 0 for rec = 1 to db_table_size() do rcount = rcount + 1 end for puts(f, "\n\nRecord count: " & rcount & "\n\n") end procedure
2. Re: EDB Question
- Posted by jimcbrown (admin) Nov 30, 2015
- 1210 views
Trying to count and display number of records in a simple EDB file. Pretty sure I have the logic correct below but when it prints it shows a graphics character rather than a number so I'm missing something ... and it's driving me nuts!
Any help you can provide is most appreciated.
puts(f, "\n\nRecord count: " & rcount & "\n\n")
Change that one line to this:
printf(f, "\n\nRecord count: %d\n\n", rcount)
There are other solutions as well, like
puts(f, "\n\nRecord count: " & sprint(rcount) & "\n\n")
Or using the writef method.
3. Re: EDB Question
- Posted by ghaberek (admin) Nov 30, 2015
- 1203 views
Trying to count and display number of records in a simple EDB file. Pretty sure I have the logic correct below but when it prints it shows a graphics character rather than a number so I'm missing something ... and it's driving me nuts!
Any help you can provide is most appreciated.
Thanks.
Tom
procedure show_count(file_number f) atom rcount rcount = 0 for rec = 1 to db_table_size() do rcount = rcount + 1 end for puts(f, "\n\nRecord count: " & rcount & "\n\n") end procedure
Okay, a few things:
- You can declare and assign a variable in one line. No need to separate them into separate statements (this was only required for Euphoria pre-4.0).
- The function db_table_size() already provides the number of records in the table. Your for loop is redundant.
- puts() is used only for character strings, so the value of rcount is being printed as if it were a character. "puts" is short for "put string". You can use printf() to print a formatted string or use to_string() to convert rcount to a string value for printing.
include std/eds.e include std/convert.e procedure show_count(file_number f) atom rcount = db_table_size() puts(f, "\n\nRecord count: " & to_string(rcount) & "\n\n") -- or -- printf(f, "\n\nRecord count: %d\n\n", {rcount} ) end procedure
-Greg
4. Re: EDB Question
- Posted by tbohon Nov 30, 2015
- 1194 views
Duh! Figured it was something really stupidly simple ... can I plead old age and it being a Monday??? :)
Thanks guys - appreciate it. Going to look for my meds now ...
Tom