This is my code:
print using("%f$#####,###", #pTempData.fAmount)
For fAmount equalling 190,000 and 1 and 12 I get:
$ 190,000
$ 1
$ 12
Notice that the 1 and 12 are not fully left right justified. Am I using the wrong string?
To left justify the output in the field use a minus sign (-) as a leading character.
print using("-%f$#####,###", #pTempData.fAmount)
That works, except I want it right-justified ;)
While I'm still interested in the solution, I put together a sub that handles my specific case.
Sub PriceToText(float price), string
Def length as int
Def result as string
Def text as string
text = using("%f#,######", price)
length = len(text)
result = "$" + space$(8-length) + text
Return result
EndSub
If your printing in a window then you need to be using a non-proportional font or right justification is meaningless.
You can lead the format string with a zero (0) and it will right justify using 0's to fill in the blanks.
text = using("0%f#,######", price)
Quote from: Paul Turley on October 14, 2009, 04:58:59 PM
If your printing in a window then you need to be using a non-proportional font or right justification is meaningless.
I'm using Courier New in a list view item.
Try Courier instead of Courier New and see if it makes any difference.
Larry
Quote from: Larry McCaughn on October 15, 2009, 11:02:56 AM
Try Courier instead of Courier New and see if it makes any difference.
Larry
No, same allignment.
Quote
I'm using Courier New in a list view item.
How are you setting the font for the item?
It works as expected in a window using either courier new or lucida console:
window win
openwindow win,0,0,400,400,@SIZE|@CAPTION,0,"Test",&handler
setfont win,"Courier New",10,400
'setfont win,"Lucida Console",10,400
move win,0,0
print win, pricetotext(190000.0)
move win,0,20
print win, pricetotext(1.0)
move win,0,40
print win, pricetotext(12.0)
waituntil win.hwnd = 0
end
sub handler
select @message
case @idclosewindow
closewindow win
endselect
endsub
Sub PriceToText(float price), string
Def length as int
Def result as string
Def text as string
text = using("%f#,######", price)
length = len(text)
result = "$" + space$(8-length) + text
Return result
EndSub
Sorry that I'm not being clear.
The first example, where I just use Using(), gives the problem. The second example, where I use the subroutine PriceToText(), works just fine.
You are correct. Looks like the comma is throwing it off. I'll look into it further this weekend.
Paul.
Did you ever find the time to look at it?
Thanks.
Why don't you use the textwidth of the string and then just position the cursor to the location. This is how tab stops, word wraps and justifications are calculated I guess.
I don't have an example (only VB code), but it goes something like-
- Get the position of the right align tab position into a variable,
- Get the textwidth of the string,
- Calculate the X,Y position to start printing (X=TABPOSITION-TEXTWIDTH)
Now if you want to align to a decimal point, just do the same above but use the decimal point position as the right tab position.
Quote from: peterpuk on December 22, 2009, 03:29:35 PM
Why don't you use the textwidth of the string and then just position the cursor to the location. This is how tab stops, word wraps and justifications are calculated I guess.
I don't have an example (only VB code), but it goes something like-
- Get the position of the right align tab position into a variable,
- Get the textwidth of the string,
- Calculate the X,Y position to start printing (X=TABPOSITION-TEXTWIDTH)
Now if you want to align to a decimal point, just do the same above but use the decimal point position as the right tab position.
I actually use something similar when I write to a window, but Using() with mono-spaced fonts works best with strings.
:) You're right. But I guess that any display or printing routines should hanlde all font styles.
That is why I always get the TextWidth of the string (not LEN) and then work from there. This way you can position correctly on the screen or printerDC.
Unfortunately I haven't used EB for this sort of requirement, so haven't tested it or have an example.
I am still encountering this problem as I try to get currency to line up in a list view.
I would use "Courier New" as font and right justify in the listview box.
Bill