1. EDB Question

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 
new topic     » topic index » view message » categorize

2. Re: EDB Question

tbohon said...

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.

new topic     » goto parent     » topic index » view message » categorize

3. Re: EDB Question

tbohon said...

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:

  1. 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).
  2. The function db_table_size() already provides the number of records in the table. Your for loop is redundant.
  3. 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

new topic     » goto parent     » topic index » view message » categorize

4. Re: EDB Question

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu