March 28, 2024, 07:09:36 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Question with PRINT USING()

Started by Bruce Peaslee, October 14, 2009, 04:09:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

October 14, 2009, 04:09:45 PM Last Edit: October 14, 2009, 04:58:34 PM by Larry McCaughn
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?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

ZeroDog

To left justify the output in the field use a minus sign (-) as a leading character.
print using("-%f$#####,###", #pTempData.fAmount)

Bruce Peaslee

That works, except I want it right-justified  ;)
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

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
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

If your printing in a window then you need to be using a non-proportional font or right justification is meaningless. 

Ionic Wind Support Team

ZeroDog

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)

Bruce Peaslee

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.

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

LarryMc

Try Courier instead of Courier New and see if it makes any difference.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

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
Ionic Wind Support Team

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

You are correct.  Looks like the comma is throwing it off.  I'll look into it further this weekend.

Paul.
Ionic Wind Support Team

Bruce Peaslee

Did you ever find the time to look at it?

Thanks.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

peterpuk

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.
Peter

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

peterpuk

 :) 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.
Peter

Bruce Peaslee

I am still encountering this problem as I try to get currency to line up in a list view.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

billhsln

I would use "Courier New" as font and right justify in the listview box.

Bill
When all else fails, get a bigger hammer.