Formatting Functions: Visual Basic
Formatting Functions: Visual Basic
VISUAL BASIC
Tab
Space
Format
Example:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("The Three common Formatting
Functions in VB are:" & vbNewLine & vbTab & "- The Tab
Function" & vbNewLine & vbTab & "- The Space Function"
& vbNewLine & vbTab & "- The Format Function ")
End Sub
End Class
Fig.1
Example
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("The Three Common Formatting
Functions in VB are:" & vbNewLine & "First:" & Space(5) &
"-The tab Function" & vbNewLine & "Second:" & Space(10)
& "-The Space Function" & vbNewLine & "Third" &
Space(10) & "- Format Function")
End Sub
End Class
Fig2
Style argument
General Number
Fixed
Standard
Currency
Percent
Explanation
To display the number without
having separators between
thousands.
To display the number without
having separators between thousands
and rounds it up to two decimal
places.
To display the number with
separators or separators between
thousands and rounds it up to two
decimal places.
To display the number with the dollar
sign in front, has separators between
thousands as well as rounding it up
to two decimal places.
Converts the number to the
percentage form and displays a %
sign and rounds it up to two decimal
places.
Example
Format(8972.234, General
Number)=8972.234
Format(8972.2, Fixed)=8972.23
Format(6648972.265, Standard)=
6,648,972.27
Format(6648972.265, Currency)=
$6,648,972.27
Format(0.56324, Percent)=56.32 %
Example:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Format(TextBox1.Text, "general
number") & vbNewLine & Format(TextBox1.Text, "Fixed")
& vbNewLine & Format(TextBox1.Text, "Standard") &
vbNewLine & Format(TextBox1.Text, "Currency") &
vbNewLine & Format(TextBox1.Text, "Percent"))
End Sub
End Class
Fig3
Example
Format(781234.57,0)
Explanation
Output
781235
781234.6
781234.58
781,234.58
$781,234.58
58%
57.68%
Example:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
MessageBox.Show(Format(Val(TextBox1.Text), "0") &
vbNewLine & Format(Val(TextBox1.Text), "0.0") & vbNewLine &
Format(Val(TextBox1.Text), "0.00") & vbNewLine &
Format(Val(TextBox1.Text), "#,##0.00") & vbNewLine &
Format(Val(TextBox1.Text), "$#,##0.00") & vbNewLine &
Format(Val(TextBox1.Text), "0%") & vbNewLine &
Format(Val(TextBox1.Text), "0.00%"))
End Sub
End Class
Fig4