Solved

Using Format in loops

Posted on 2001-07-29
7
133 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
  • 4
  • 3
7 Comments
 
LVL 69

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 69

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 69

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 69

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now