School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,412 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,593 people online right now. Registration is fast and FREE... Join Now!




Formatting Functions in VB6

 
Reply to this topicStart new topic

> Formatting Functions in VB6, three functions are explained here - tab, space and format

Nikhil_07n
Group Icon



post 26 Jan, 2009 - 07:34 PM
Post #1


Formatting output is a very important part of programming so that the data can be presented systematically and clearly to the users. Data in the previous lesson were presented fairly systematically through the use of commas and some of the functions like Int, Fix and Round. However, to have better control of the output format, we can use a number of formatting functions in Visual basic.

The three most common formatting functions in VB are Tab, Space, and Format

(i) The Tab function

Tab (n); x

The item x will be displayed at a position that is n spaces from the left border of the output form. There must be a semicolon in between Tab and the items you intend to display (VB will actually do it for you automatically).

Example

CODE


Private Sub Form_Activate

         Print "I"; Tab(5); "like"; Tab(10); "to"; Tab(15); "learn"; Tab(20); "VB"

         Print

         Print Tab(10); "I"; Tab(15); "like"; Tab(20); "to"; Tab(25); "learn"; Tab(20); "VB"

         Print

         Print Tab(15); "I"; Tab(20);; "like"; Tab(25); "to"; Tab(30); "learn"; Tab(35); “VB"


' The Combined output is shown in the picture below

End sub



Output :
IPB Image
By nikhil_07n at 2009-01-26

(ii) The Space function

The Space function is very closely linked to the Tab function. However, there is a minor difference. While Tab (n) means the item is placed n spaces from the left border of the screen, the Space function specifies the number of spaces between two consecutive items. For example, the procedure

Example 2

CODE

Private Sub Form_Activate()

Print "Visual"; Space(10); "Basic"

End Sub


Means that the words Visual and Basic will be separated by 10 spaces



(iii) The Format function

The Format function is a very powerful formatting function which can display the numeric values in various forms. There are two types of Format function, one of them is the built-in or predefined format while another one can be defined by the users.

(i) The format of the predefined Format function is

Format (n, “style argument”)

where n is a number and the list of style arguments is given below

1)General Number
To display the number without having separators between thousands.


Format(8972.234, “General Number”)=8972.234

2)Fixed
To display the number without having separators between thousands and rounds it up to two decimal places.


Format(8972.2, “Fixed”)=8972.23

3)Standard
To display the number with separators or separators between thousands and rounds it up to two decimal places.


Format(6648972.265, “Standard”)= 6,648,972.27

4)Currency
To display the number with the dollar sign in front, has separators between thousands as well as rounding it up to two decimal places.


Format(6648972.265, “Currency”)= $6,648,972.27

5)Percent
Converts the number to the percentage form and displays a % sign and rounds it up to two decimal places.


Format(0.56324, “Percent”)=56.32 %


Example

CODE


Private Sub Form_Activate()

Print Format (8972.234, "General Number")

Print Format (8972.2, "Fixed")

Print Format (6648972.265, "Standard")

Print Format (6648972.265, "Currency")

Print Format (0.56324, "Percent")

End Sub



Output is :

IPB Image
By nikhil_07n at 2009-01-26

Was'nt that easy?
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 11:11PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month