Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Thursday, August 11, 2011

VB-101 : Add 2 numbers(Pass by Value method)

Add 2 number by Pass by Value method.

 Taken from VB-Tutorial CDs ...

Refer the same program in normal programming code : Simple Programs(3)  and Declare a function(Pass by reference)



(A)Program Design : 





(B) Property(Controls Used) :
  • 3 Labels
  • 3 TextBoxes
  • One Command Button



Refer  Simple Programs(3) to know the details about property.


(C) Attaching Code to the Object :



Private Sub Command1_Click()
Dim first As Integer, second As Integer, answer As Integer
First = Val(Text1.Text)
Second = Val(Text2.Text)
Answer = Add(First, Second)
Text3.Text = Answer
End Sub
------------------------------------------------------------------------------------------------
Public Function Add(a As Integer, b As Integer) As Integer
Dim f As Integer
f = a + b
Add = f
End Function



Double click on Form and go to code window ( For Function)
Select Tools--> Add Procedure
Give Name - Add
Type  - Function
Scope - Public



(E) Errors :
If found any errors while running your VB program, or want to put your comment about any  program , please click Comment section , to post.
====================================================================
===========================================================

No comments: