0% found this document useful (0 votes)
128 views66 pages

My Project

The document contains code snippets for various basic programming concepts in Visual Basic like addition, subtraction, calculator operations, leap year, even-odd, arrays, palindrome, swap, and temperature conversion. It includes the code and output for each concept to demonstrate how to program them in Visual Basic.

Uploaded by

hitesh4010
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views66 pages

My Project

The document contains code snippets for various basic programming concepts in Visual Basic like addition, subtraction, calculator operations, leap year, even-odd, arrays, palindrome, swap, and temperature conversion. It includes the code and output for each concept to demonstrate how to program them in Visual Basic.

Uploaded by

hitesh4010
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 66

HOW WE WILL START VISUAL BASICS

ADD & SUBTRACT


CODING FOR ADD & SUBTRACT

CODE FOR ADD :

Private Sub Command1_Click()


Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a+b
Text3.Text = r

End Sub

CODE FOR SUBTRACT :

Private Sub Command2_Click()


Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a-b
Text3.Text = r

End Sub
RESULT

ADD :

SUBTRACT :
CALCULATOR
CODING FOR CALCULATOR
CODE FOR ADD

Private Sub Command1_Click()


Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a+b
Text3.Text = r

End Sub

CODE FOR SUBTRACT


Private Sub Command2_Click()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a–b
Text3.Text = r
End Sub

CODE FOR MULTIPLICATION


Private Sub Command3_Click()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a*b
Text3.Text = r

End Sub

CODE FOR DIVIDING

Private Sub Command4_Click()


Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a/b
Text3.Text = r

End Sub

CODE FOR MOD


Private Sub Command5_Click()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
Text3 = Text1 Mod Text2

End Sub

CODE FOR SQUAREROOT


Private Sub Command6_Click()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
Text3 = Sqr(Text1)

End Sub

CODE FOR EXIT


Private Sub Command7_Click()
End

End Sub

RESULT

ADD :
SUBTRACT :
MULTIPLY :

DIVIDE :
MODE :

SQUAREROOT :
LEAP YEAR
CODE FOR LEAP YEAR OR NOT

Private Sub Command1_Click()


n = Val(Text1.Text)
If (n Mod 400 = 0) Then
MsgBox "leap year"
ElseIf (n Mod 100 = 0) Then
MsgBox " not a leap year"
ElseIf (n Mod 4 = 0) Then
MsgBox "leap year"
Else
MsgBox " not a leap year"
End If

End Sub

RESULT
PROGRAM OF ODD OR
EVEN NUMBER
CODING FOR ODD & EVEN NUMBER :

Private Sub Command1_Click()


n = Val(Text1.Text)
If (n Mod 2 = 0) Then
MsgBox "number is even"
Else: MsgBox "odd"
End If

End Sub
RESULT

EVEN NUMBER :
ODD NUMBER :

PROGRAM OF USER NUMBER


CODING FOR USER NUMBER
CODE FOR COUNTING

Private Sub Command1_Click()


Dim a As Integer
a = Val(Text1.Text)
For i = 1 To a Step 1
Print i
Next i

End Sub

CODE FOR COUNTING UPTO 10

Private Sub Command2_Click()


Dim i As Integer
For i = 1 To 10 Step 1
Print i
Next i

End Sub

CODE FOR TABLE OF 2


Private Sub Command3_Click()
Dim i As Integer
For i = 2 To 20 Step 2
Print i
Next i

End Sub

CODE FOR ANY TABLE


Private Sub Command4_Click()
Form1.Cls
Dim a As Integer
a = Val(Text1.Text)
For i = a To (a * 10) Step a
Print i
Next i

End Sub

CODE FOR REVERSE COUNTING

Private Sub Command5_Click()


Form1.Cls
Dim a As Integer
a = Val(Text1.Text)
For i = a To 1 Step –
Print i
Next i
End Sub
RESULT
COUNTING
RESULT OF COMMAND “NUMBER UP TO 10” :

RESULT OF COMMAND “TABLE OF 2” :


RESULT OF COMMAND “ANY TABLE” :
PROGRAM OF “*” AND “ABC”
CODING FOR ABOVE PROGRAM
CODE TO PRINT *

Private Sub Command1_Click()


Dim a As Integer
a = Val(Text1.Text)
For i = 1 To a Step 1
For j = 1 To i Step 1
Print "*";
Next j
Print
Next i

End Sub

CODE TO PRINT “ABC”

Private Sub Command2_Click()


For i = 65 To 69 Step 1
For j = 65 To i Step 1
Print Chr(j);
Next j
Print
Next i

End Sub

CODE TO PRINT * IN REVERSE


Private Sub Command3_Click()
Dim a As Integer
a = Val(Text1.Text)
For i = a To 1 Step -1
For j = 1 To i Step 1
Print "*";
Next j
Print
Next i
End Sub

CODE TO PRINT * IN ASC & DESC.

Private Sub Command5_Click()


Dim a As Integer
a = Val(Text1.Text)
For i = 1 To a Step 1
For j = 1 To i Step 1
Print "*";
Next j
Print
Next i
a = Val(Text1.Text)
For i = a To 1 Step -1
For j = 1 To i Step 1
Print "*";
Next j
Print
Next i
End Sub

RESULT OF ABOVE PROGRAMMING :


RESULT OF COMMAND “PRINT * ” :

RESULT OF COMMAND “PRINT ABC” :


RESULT OF COMMAND “REVERSE OF *” :
RESULT OF COMMAND “ASC & DESC. OF*” :
SMALLER & GREATER NUMBER

CODE FOR ABOVE PROGRAMMING


CODE FOR “NUMBER IS GREATER”
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)

If (a >= b) Then
MsgBox "First number is greater"
Else
MsgBox "Second number is greater"
End If

End Sub

CODE FOR “NUMBER IS SMALLER”

Private Sub Command2_Click()


Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)

If (a <= b) Then
MsgBox "First number is smaller"
Else
MsgBox "Second number is smaller"
End If

CODE FOR “NUMBER IS EQUAL”


Private Sub Command3_Click()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)

If (a = b) Then
MsgBox "Both the numbers are equal "
Else
MsgBox "Both the numbers not are equal "
End If

End Sub

RESULT
NO. IS GREATER
NO. IS SMALLER

NO. IS EQUAL
SIMPLE INTEREST

CODE FOR ABOVE


Private Sub Command1_Click()
Dim p As Integer
Dim r As Integer
Dim t As Integer
Dim SI As Single
p = Val(Text1.Text)
r = Val(Text2.Text)
t = Val(Text3.Text)
SI = p * r * t / 100
MsgBox SI
END SUB

RESULT
COMPOUND INTEREST
CODE FOR COMPOUND INTEREST

Private Sub CompoundInterest(ByVal x As Integer, ByVal y As


Integer, ByVal z As Integer)
Dim a As Single
Dim b As Single
Dim c As Single
Dim d As Single
Dim CI As Single
a=x
b=y
c=z
d = a * (1 + b / 100) ^ c
CI = d - a
MsgBox CI

End Sub

Private Sub Command1_Click()


p = Val(Text1.Text)
r = Val(Text2.Text)
t = Val(Text3.Text)
Call CompoundInterest(p, r, t)

End Sub

RESULT
PROGRAM OF TRAFFICE
LIGHT
CODE :

RESULT :
PROGRAM OF ARRAY

CODE :
RESULT:
PROGRAM OF ARRAY TO
CALCULATE AVG.
OF NUMBERS

Code :
RESULT :
PROGRAM TO CKECK WHETHER
“STRING”
IS “PALINDROME” OR NOT
CODE :
RESULT :
PROGRAM OF SWAP
CODE :
RESULT :
PROGRAM OF TEMPERATURE
CODE FOR CHANGING
TEMPERATURE
FROM “CELCIUS” TO
“FARENHEIT”
RESULT :
CODE FOR CHANGING
TEMPERATURE
FROM “FARENHEIT” TO
“CELCIUS”

RESULT :

You might also like