3. Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub Command2_Click()
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
End Sub
Private Sub Command3_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
End Sub
Private Sub Command4_Click()
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End Sub
5. Type Storage Range of Values
Byte 1 byte 0 to 255
Integer 2 bytes -32,768 to 32,767
Long 4 bytes -2,147,483,648 to 2,147,483,648
Single 4 bytes
-3.402823E+38 to -1.401298E-45 for negative values
1.401298E-45 to 3.402823E+38 for positive values.
Double 8 bytes
-1.79769313486232e+308 to -4.94065645841247E-324 for negative values
4.94065645841247E-324 to 1.79769313486232e+308 for positive values.
Currency 8 bytes -922,337,203,685,477.5808 to 922,337,203,685,477.5807
Decimal 12 bytes
+/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use
+/- 7.9228162514264337593543950335 (28 decimal places).
6. Data Type Storage Range
String(fixed length) Length of string 1 to 65,400 characters
String(variable length) Length + 10 bytes 0 to 2 billion characters
Date 8 bytes
January 1, 100 to December 31,
9999
Boolean 2 bytes True or False
Object 4 bytes Any embedded object
Variant(numeric) 16 bytes Any value as large as Double
Variant(text) Length+22 bytes Same as variable-length string
7. Identifier type character Data type Example
% Integer Dim L%
& Long Dim M&
@ Decimal Const W@ = 37.5
! Single Dim Q!
# Double Dim X#
$ String Dim V$ = "Secret"
11.
Value = 10 ' = ةةةة10 Value ةةة
ةةةةةةة ةةةةةة
Text1.Text = Valu 'ةة ةةةةةة ةةة ة
ةةةةةةة ةةة ةةةةة
Dim
Dim Value As Integer
Option Explicit
12. Option Explicit
Option Explicit 'in Declarations section
Private Sub Command1_Click()
Dim n As Integer 'You must declare n, otherwise
n = 20 'it will show error
Print n + 1
End Sub
13. 'Declarations section
Dim n As Integer 'n is accessible from all the procedures
____________________________________
Private Sub cmdShow1_Click)(
n = 7
Print n
End Sub
____________________________________
Private Sub cmdShow2_Click)(
Print n + 1
End Sub
14. Dim VariableName As DataType
Dim VariableName1 As DataType1, VariableName2 As DataType2
Dim password As String
Dim yourName As String
Dim firstnum As Integer
Dim secondnum As Integer
Dim total As Integer
Dim doDate As Date
Dim password As String, yourName As String, firstnum As Integer
15. Constant
Constants are different from variables in the sense that their
values do not change during the running of the program.
Const Constant Name As Data Type = Value
Const Pi As Single=3.142
Const Temp As Single=37
Const Score As Single=100
17. Operator Mathematical function Example
^ Exponential 2^4=16
* Multiplication 4*3=12, (5*6))2=60
/ Division 12/4=3
Mod Modulus(return the remainder from an
integer division)
15 Mod 4=3 255 mod 10=5
Integer Division(discards the decimal
places)
194=4
+ or & String concatenation "Visual"&"Basic"="Visual
Basic"
19. Private Sub cmdEnterValues_Click)(
a = Val(InputBox("Enter the value of a", "Input value"((
b = Val(InputBox("Enter the value of b", "Input value"((
MsgBox "The sum is " & a + b, vbInformation, "Output"
End Sub
20.
21. Dim firstName As String
Dim secondName As String
Dim yourName As String
Private Sub Command1_Click()
firstName = Text1.Text
secondName = Text2.Text
yourName = secondName + " " + firstName
Label1.Caption = yourName
End Sub
22. Dim number1, number2, number3 as Integer
Dim total, average as variant
Private sub Form_Click
number1=val(Text1.Text)
number2=val(Text2.Text)
number3= val(Text3.Text)
Total=number1+number2+number3
Average=Total/3
Label1.Caption=Total
Label2.Caption=Average
End Sub
23. Operator Meaning
And Both sides must be true
or One side or other must be true
Xor One side or other must be true but
not both
Not Negates truth
Operator Meaning
= Equal to
> More than
< Less Than
>= More than and equal
<= Less than and equal
<> Not Equal to