IonicWind Software

IWBasic => General Questions => Topic started by: Bruce Peaslee on October 14, 2009, 04:09:45 PM

Title: Question with PRINT USING()
Post by: Bruce Peaslee on October 14, 2009, 04:09:45 PM
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?
Title: Re: Question with PRINT USING()
Post by: ZeroDog on October 14, 2009, 04:22:17 PM
To left justify the output in the field use a minus sign (-) as a leading character.
print using("-%f$#####,###", #pTempData.fAmount)
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on October 14, 2009, 04:51:49 PM
That works, except I want it right-justified  ;)
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on October 14, 2009, 04:57:24 PM
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
Title: Re: Question with PRINT USING()
Post by: Ionic Wind Support Team 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. 

Title: Re: Question with PRINT USING()
Post by: ZeroDog on October 14, 2009, 05:18:26 PM
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)
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on October 15, 2009, 10:20:43 AM
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.

Title: Re: Question with PRINT USING()
Post by: LarryMc on October 15, 2009, 11:02:56 AM
Try Courier instead of Courier New and see if it makes any difference.

Larry
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on October 15, 2009, 11:36:27 AM
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.
Title: Re: Question with PRINT USING()
Post by: Ionic Wind Support Team on October 15, 2009, 04:49:41 PM
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
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on October 15, 2009, 10:16:01 PM
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.
Title: Re: Question with PRINT USING()
Post by: Ionic Wind Support Team on October 16, 2009, 04:16:32 AM
You are correct.  Looks like the comma is throwing it off.  I'll look into it further this weekend.

Paul.
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on December 22, 2009, 09:50:47 AM
Did you ever find the time to look at it?

Thanks.
Title: Re: Question with PRINT USING()
Post by: 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.
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on December 22, 2009, 03:43:27 PM
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.
Title: Re: Question with PRINT USING()
Post by: peterpuk on December 22, 2009, 03:52:22 PM
 :) 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.
Title: Re: Question with PRINT USING()
Post by: Bruce Peaslee on September 30, 2010, 11:29:33 AM
I am still encountering this problem as I try to get currency to line up in a list view.
Title: Re: Question with PRINT USING()
Post by: billhsln on September 30, 2010, 03:23:57 PM
I would use "Courier New" as font and right justify in the listview box.

Bill