Tuesday, October 27, 2009

Procedure vb

okay,
as you know about functions as i had explain previously.
in programing, object oriented programing.
it consists of function and procedure.
what is the difference u may ask?
hmm..,
in function its like: "Sum(a,b)"
bt in procedure u call it: "call Space"
well, procedure may not need any input at all.

For example:

Private Sub Form_Activate()
Dim space As Single
Dim i As Single
space = InputBox("Line spacing")

For i = 1 To space
Print 'space each line
Next i
Call line1
End Sub

Private Sub line1()
Print "-----------------------------------------------------------"
End Sub

In this above, it will skip the number of lines key in "Space".
it doesn't has input for the procedure, "Call line1"

Here is another example,
bt for this procedure there are input:

Private Sub Form_Activate()
Dim n As Integer
Dim a As String

a = InputBox("name")
n = InputBox("age")

Call Name1(a, n)

End Sub

Private Sub Name1(a As String, n As Integer)
Print "My name is " & a & " and i am at the age of " & n

End Sub

Basically, this one has a procedure that collects the input n and a.
Then print it.

Next example is an example of using both type of procedure:

Private Sub Form_Activate()
Dim n As Integer
Dim s As Single

s = InputBox("Price per unit")
n = InputBox("Number of units")


Call Header

Call Sum(s, n)
End Sub

Private Sub Header()
Print "The total price is RM";
End Sub

Private Sub Sum(s As Single, n As Integer)
Dim sum1 As Integer

sum1 = n * s
sum1 = Format(sum1, "currency")
Print sum1

End Sub

Well, it jz calculates the price.
thats all.
The format(sum1, "currency")
is to make it in money. xx.xx

kk
thats all.
bb
miss me? i had not update in a long time.
hahax.. i guess not.

No comments: