VBA Jobsheets
VBA Jobsheets
Sub printval()
Dim x, y As Integer
x = 15
y=5
Debug.Print "addition="; (x + y)
Debug.Print "subtraction="; (x - y)
Debug.Print "multipication="; (x * y)
End Sub
OUTPUT:
value of x=15
value of y=5
addition= 20
subtraction= 10
multipication= 75
Job Sheet No. 2
Aim: Working with numeric data types -II
Objectives:
1) Create and use floating point variables
2) Use and compare single and double data types variables
3) Use the byte and Boolean data type variables
Procedure:
Task 1: create and use the floating point variables
Sub testfloat( )
Dim x As Single
Dim y As Single
x = 3.143
y = 22 / 7
Debug.Print "value of x is:" & x
Debug.Print "value of y is:" & y
End Sub
OUTPUT:
value of x is:3.143
value of y is:3.142857
Task 2: Use and compare nature of single and double data type variables
Sub test2( )
Dim a As Single
Dim b As Single
Dim c As Double
a = 3.143
b = 22 / 7
Debug.Print "value of single type variable a is:" & a
Debug.Print "value of single type variable b is:" & b
c = 22 / 7
Debug.Print "value of double type variable c is:" & c
End Sub
OUTPUT:
Sub testbyte( )
Dim x As Byte
x = 145
Debug.Print "value of x is:" & x
End Sub
OUTPUT:
value of x is:145
Now, assign an out of range value to x by changing the value of x to 256 and
check the result.
OUTPUT:
Sub testbool( )
Dim x As Boolean
Debug.Print "The default value of Boolean x is:" & x
x=0
Debug.Print "Now the value of Boolean x is:" & x
x = False
Debug.Print "once again the value of Boolean x is:" & x
x=1
Debug.Print "now again the value of Boolean x is:" & x
End Sub
OUTPUT:
Sub test1()
Dim string1 As String
string1 = "Namasthe"
Debug.Print string1
End Sub
OUTPUT:
Namasthe
My birthday is:1/1/1990
TASK 5:Use the variant data type
Sub test_variant()
Dim name As Variant
Dim joiningday As Variant
Dim salary As Variant
name = "sachin"
joiningday = #1/1/2014#
salary = 10000
Debug.Print "Name is:" & name
Debug.Print "Joining date is:" & joiningday
Debug.Print "Salary is:" & salary
End Sub
OUTPUT:
Name is:sachin
Salary is:10000
My birthday is:1/1/1990
Sub test2( )
Dim name As String
name = InputBox("Your name please")
Debug.Print "Good morning," & name
End Sub
OUTPUT:
Good morning,suyash
Sub test_if( )
Dim marks As Integer
marks = InputBox("Enter your marks")
Debug.Print "Your marks are :" & marks
If (marks < 45) Then
Debug.Print "Sorry, you have failed to clear the test!"
End If
End Sub
OUTPUT:
Sub nestedif()
Dim x, y, z As Integer
Dim large As Integer
x = 34
y = 55
z = 12
Debug.Print "Value of x is:" & x
Debug.Print "Value of y is:" & y
Debug.Print "Value of z is:" & z
If (x > y) Then
If (x > z) Then
large = x
Else
large = z
End If
Value of x is:34
Value of y is:55
Value of z is:12
TASK 3: Write and test the VBA program to find if the given number is even
or odd.
OUTPUT:
TASK 4: Write and test the VBA program to find if the given year is leap year
or not.
OUTPUT: