It is currently Tue Apr 25, 2017 7:29 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Multiple variables output
Unread postPosted: Mon Feb 20, 2017 5:33 am 
Offline

Joined: Wed Dec 28, 2011 12:42 pm
Posts: 5
Hello,

Just a simple question about FORMAT$
I read the documentation and forum but didn't find the answer

I would like to format an output for multiple variables and well aligned results
let's say : Units : 10 Unit Price : 10,55 Total : 105,50

I tried from the PRINT command :
PRINT FORMAT$(" #####.###", c)

but cannot find the right syntax to have multiple formatted variables on the same line, mixing standard text i.e. Unit Price and variable : 10,55

Sorry for this basic question

Many thanks.

Rgds.


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Mon Feb 20, 2017 6:58 am 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 624
To format and align could be seen as many things.
Here is sample code doing all in one string and all in a column.
Attachment:
AlignFormat.apk [474.88 KiB]
Downloaded 4 times
Attachment:
AlignFormat.zip [2.97 KiB]
Downloaded 6 times

ImageImage

Code Snippet
Code:
ONCLICK_RndBtn1:
   Units = 10
   Price = 10.55
   Amount = Units * Price

!   As previously created
!   For Screen1[TxtBtn1] to TxtBtn3 ===> GR.TEXT.ALIGN 3
   GR.MODIFY Screen1[TxtBtn1], "text", FORMAT$( "###", Units)
   GR.MODIFY Screen1[TxtBtn2], "text", FORMAT$( "####.##", Price)
   GR.MODIFY Screen1[TxtBtn3], "text", FORMAT$( "#####.##", Amount)

!   All in one string
   Display$ = "Units : "
   Display$ = Display$ + LTRIM$(FORMAT$( "###", Units))
   Display$ = Display$ + " Price/unit : "
   Display$ = Display$ + LTRIM$(FORMAT$( "####.##", Price))
   Display$ = Display$ + " Total : "
   Display$ = Display$ + LTRIM$(FORMAT$( "#####.##", Amount))
   GR.MODIFY Screen1[TxtTxtLine4], "text", Display$

   GoSub WAITTOUCHUP
RETURN

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Mon Feb 20, 2017 8:59 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 642
Location: UK
leonlelion wrote:
I would like to format an output for multiple variables and well aligned results
let's say : Units : 10 Unit Price : 10,55 Total : 105,50

I tried from the PRINT command :
PRINT FORMAT$(" #####.###", c)

RSA's answer is very high quality but rather deep. Maybe you just need a hint that the crucial bit is merely to concatenate all your components into a single string using multiple plus "+" signs just like a numeric expression.

So you could write
Code:
PRINT "Units: " + FORMAT$(" #####.###", c) + " Price: " ...


But alignment into columns is trickier because you would have to define the tabs! That's when you probably need RSA's solution...

HTH, Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Mon Feb 20, 2017 9:15 am 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 624
Mike wrote:
PRINT "Units: " + FORMAT$(" #####.###", c) + " Price: " ...

No this wont do. The LTRIM$() does the trick.
The FORMAT$() gives leading zero's or SPACES. Thus the left trim. ;)

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Mon Feb 20, 2017 10:56 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 642
Location: UK
RSA wrote:
Mike wrote:
PRINT "Units: " + FORMAT$(" #####.###", c) + " Price: " ...

No this wont do. The LTRIM$() does the trick.
The FORMAT$() gives leading zero's or SPACES. Thus the left trim. ;)

Sorry, I was paying no attention whatever to the FORMAT() itself, assuming the format was as was wanted! It's sad that there is no format pattern that suppresses the leading spaces.

I subsequently looked up the PRINT command and refreshed my memory that the "+" can be replaced with "," or ";" if preferred...

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Mon Feb 20, 2017 11:05 am 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 624
Hi Mike
Don't worry I am also careless most of the time. :lol:
Keep well
Emile

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Tue Feb 21, 2017 2:36 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 642
Location: UK
RSA wrote:
Hi Mike
Don't worry I am also careless most of the time. :lol:
Keep well
Emile

leonlelion hasn't come back and thanked either of us, so maybe we were just wasting our time...

But I thought if a simple answer was enough, one way to get it would have been to look at the sample programs, e.g. f07_print_format.bas

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Thu Feb 23, 2017 11:36 am 
Offline

Joined: Tue Jan 10, 2017 11:58 am
Posts: 6
You might look at some rosettacode solutions. The Run Basic solution looks decent and easily converted.

http://rosettacode.org/wiki/Align_columns


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Thu Feb 23, 2017 12:34 pm 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 642
Location: UK
knoWare wrote:
You might look at some rosettacode solutions. The Run Basic solution looks decent and easily converted.

http://rosettacode.org/wiki/Align_columns

Ooh, treason! ;-)


Report this post
Top
 Profile  
 
 Post subject: Re: Multiple variables output
Unread postPosted: Thu Feb 23, 2017 1:01 pm 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 624
I found this there?
Image

Mike do you want to buy it ?
It has columns too, I mean three!

No offense knoWare, we also need some fun :lol:

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred