Anda di halaman 1dari 4

Lesson 7

End, Remarks Statement and VB Functions


End Statement
Remarks
VB Functions

OBJECTIVES:
1. Apply comment and statements in Visual Basic Programming.
2. Simulate the importance of comments and statements in program
design and development.
3. Analyze the importance of Visual Basic Functions.
4. Create program using different Functions available in Visual Basic.
THE END STATEMENT
The End statement ends an application immediately. No code after the

End statement is executed.


Private Sub cmdQuit_Click( )
End
End Sub

VISUAL BASIC REMARKS


Remarks are notes that you write in your code. These notes are
commonly used to help clarify some code, explain codes to readers, state the
programmers name and the date the program was written, and describe the
purpose of the program.
Remarks that begin with the Rem statement or apostrophe
Examples:
Rem
1|Page

Programmer: Maricris M. Usita

Rem

Occidental Mindoro National College

Information Technology Department


This program computes for the average of 3 numbers
VAL(), STR(), AND ISNUMERIC FUNCTIONS
The Val(), Str(), IsNumeric Functions are useful for data conversion: from
numbers to Strings and from Strings to numbers.

Val() converts Strings to numbers and Text property of a TextBox to a


number. Text property of TextBoxes and the Caption property of Labels are
Strings in type, thus conversion must be done if you need their number value.

Str() complements Val() it converts numbers to Strings.


IsNumeric() returns True if a String argument can represent a number.
For example, if you require the users age, and the user enters letters, you might
want to notify the user of wrong input.
The following are examples of how we use the 3 functions.
strNumber = 122
intNumber = Val(strNumber) intNumber is assigned the numeric value 122
strNum = Str(intNumber)

strNum is assigned the string 122

intAge = Val(txtAge.Text)

intAge is assigned the numeric value of

txtAge.Text
y = IsNumeric(intNumber)

y receives True

FORMAT FUNCTION
The Format() function enables you to format how data are displayed. If
variable total_cost contains the total amount of a product, you might want to
display the value of this variable in currency format (in 2 decimal places with a
currency sign).

2|Page

Format() does not change a value, it only changes the way a value looks.
This function returns a variant. The following is Format()s syntax:
Format(<expression>, <strFormat>)
<expression> can be any variable, expression, or a constant. <strFormat>
may be a value in the following table:
strFormat

Description

Currency

A dollar sign appears before the formatted value. The value has
a comma thousands separator and 2 decimal places. Negative
values are automatically enclosed in parentheses.

Fixed

Displays at least one digit before and two digits following the
decimal point, with no thousands separator.

General

Displays the number with no thousands separator.

Number
Percent

Displays the number, multiplied by 100, and adds appends


percent sign to the right of the number.

You can also create your own strFormat. Youll just need a combination
of pound sign and zeros to format values. Each pound sign indicates where a
significant digit goes. The zero indicates that you want either leading or trailing
zeros, whether the zero or significant or not.
Examples:
A = 123.3232
B = 23.0002
C = 12233
D = .34
Format Expression

Result

Format(A, Currency)

$ 123.32

Format(D, Percent)

34%

Format(B, Fixed)

23.00

Format(D, ###)

Nothing

Format(D, ##.###)

.34

3|Page

Format(D,0.000)

0.340

Format(C,#,###.00)

12,233.00

Format(C,#,###.##)

12,233.

Format(C, P #,##0.00)

P 12, 233.00

4|Page

Anda mungkin juga menyukai