Solved

Using Format in loops

Posted on 2001-07-29
7
138 Views
Last Modified: 2010-05-02
I have a loop

for a=1 to 5

printer.print format(firstvalue(a),"####.##"), format(secondvalue(a),"###.00"), format(thirdvalue(a)," ###.##")

next a

How do I get the following layout using format?

   7.89      0.34    6.12
1245.00   3452.56   34.00
    .01     70.00    1.34

etc

also variation for no decimal places in say firstvalue?

Thank you
0
Comment
Question by:bemson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6332386
Use this mask: "####.00"
0
 

Author Comment

by:bemson
ID: 6332430
format shown after submission not the same as I typed it

using your suggestion for following values

78,2456,0.12
23.34,0.12,346

I get the following
- represents a space in case of what I type is not clear

78.00,2456.00,.12
23.34,.12----,346.00

- represents a space in case of what I type is not clear

I want the following


78.00,2456.00,----.12
23.34,----.12, 346.00

thank you

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6332470
You can use something like this:

Private Sub Command1_Click()
Debug.Print EMFormat(7.89, 7) & "," & EMFormat(0.34, 7) & "," & EMFormat(6.12, 7)
End Sub

Private Function EMFormat(ByVal psngValue As Single, ByVal pbytLen As Byte) As String
    EMFormat = Right$(Space$(pbytLen) & Format$(psngValue, "####.00"), pbytLen)
End Function
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bemson
ID: 6332509
OK,

However I would like to vary the function capabilty
by changing 7 to 4 to get the following
for the first two values, ie 78 first line, 23 second line

Printer.Print EMFormat(78, 4), EMFormat(2456, 7), EMFormat(0.12, 7)
Printer.Print EMFormat(23.34, 4), EMFormat(0.12, 7), EMFormat(346, 7)

although 23 should be 24 if figure was 23.78

78,2456.00,---.12
23,----.12,346.00

what I get is:

8.00,2456.00,---.12
3.34,----.12,346.00

thank you
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 6332552
In this case, use this:

Private Sub Command1_Click()
Debug.Print EMFormat2(7.89, 4) & "," & EMFormat(0.34, 7) & "," & EMFormat(6.12, 7)
End Sub

Private Function EMFormat(ByVal psngValue As Single, ByVal pbytLen As Byte) As String
   EMFormat = Right$(Space$(pbytLen) & Format$(psngValue, "####.00"), pbytLen)
End Function

Private Function EMFormat2(ByVal psngValue As Single, ByVal pbytLen As Byte) As String
   EMFormat = Right$(Space$(pbytLen) & Format$(psngValue, "###0"), pbytLen)
End Function
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6332602
Why a B when I give you exactly what you want?
0
 

Author Comment

by:bemson
ID: 6336017


I now have to figure out how to use your function to perform a function that vb should have for all other combinations with both format and number of characters,
in any case by using your function, if Format2 and using "###0" then default obviously would be 4, so why specify pbytLen?

if I pass 346.3,2 to your function I get 46, no error that it should be 346

in dos with qbasic
the statement "print using "####", firstvalue
provided the spacing

I would have got " 346"



obviously whoever designed vb has missed the point of formatting

basically I (and others) need a single function to provide spaces to properly format numbers

So for every format I need I have to create a new function for every possibility, both for number formatting & how many numbers to display

If you have a better solution I am willing to give 100
points and an A

even so, thanks for your help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 192
SLMGR Switches Are Not Working On KMS Host 3 141
Set email body to html using vbscript 6 71
Problem to line 23 73
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question