google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: VB Examples

VB Examples


Your browser does not support the HTML5 canvas tag.

Program 1:-To create Visual Basic application to find area of rectangle.

VB_image1

Code:-
Private Sub Command1_Click() Text3.Text = Text1.Text * Text2.Text End Sub
Private Sub Command2_Click()
Text1.Text = " " Text2.Text = " " Text3.Text = " " End Sub
Private Sub Command3_Click()
Unload Me
End Sub

Output:-
VB_image2



Program 2:- To create Visual Basic application to average of 3 numbers.

Design Window:-
VB_image3

Code:-
Private Sub Command1_Click()
Text4.Text = Str((Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)) / 3)
End Sub

Private Sub Command2_Click()
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
End Sub

Private Sub Command3_Click()
Unload Me
End Sub
Output :-
VB_image4



Program 3: To create Visual Basic application to illustrate Date-Time functions.


Code:-
Private Sub Command1_Click ()
Text1.Text = Date
Text2.Text = Time ()
Text3.Text = Year (Date)
Text4.Text = Month (Date)
End Sub
Output :-
VB_image5



Program 4:To create Visual Basic application program to find maximum number among two numbers.

Code:-
Private Sub Command1_Click ()
Dim a As Integer
Dim b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
If (a > b) Then
        Label3.Caption = "a is maximum number"
Else
        Label3.Caption = "b is maximum number"
End If
End Sub
 Output : -
VB_image6



Program 5:To create Visual Basic application program to perform arithmetic operations with the use of Option button.


Code:-

Private Sub Option1_Click ()
Text3.Text = Val (Text1.Text) + Val (Text2.Text)
End Sub

Private Sub Option2_Click ()
Text3.Text = Val (Text1.Text) - Val (Text2.Text)
End Sub

Private Sub Option3_Click ()
Text3.Text = Val (Text1.Text) * Val (Text2.Text)
End Sub

Private Sub Option4_Click ()
Text3.Text = Val (Text1.Text) / Val (Text2.Text)
End Sub
Output :-
VB_image7



6.Visual Basic program for Prime number

Private Sub Command1_Click()
Dim no As Integer, i As Integer
For no = 1 To 100
    For i = 2 To no - 1
        If no Mod i = 0 Then
        Exit For
        End If
        Next
              If i = no Then
                Form1.Print no
                End If
             Next
End Sub
 


7. Visual Basic program for Armstrong number
Private Sub Command1_Click()
Dim no As Integer
Dim s As Integer
Dim t As Integer

For no = 1 To 1000
    t = no
    s = arm(t)
   
    If s = no Then
        Form1.Print no
    End If
   
Next
End Sub


Function arm(n As Integer) As Integer

Dim d As Integer
    arm = 0
   
    Do While n > 0
        d = n Mod 10
        n = n \ 10
        arm = arm + d * d * d
       
    Loop
End Function





8.Visual Basic program for Sum of first and last number
Private Sub Command1_Click()
Dim a(10) As Integer, no As Integer, s As Integer, i As Integer
i = 0
s = 0
no = CInt(text1.Text)
If no > 9 Then
Do While no > 0
a(i) = no Mod 10
no = no \ 10
i = i + 1
Loop
s = a(0) + a(i - 1)
MsgBox s
Else
  MsgBox no
End If
End Sub




9.Visual Basic program to print reverse of a number
Private Sub Command1_Click()
Dim no As Integer, s As Integer, d As Integer
no = CInt(Text1.Text)
s = rev(no)
MsgBox s
End Sub

Function rev(n As Integer) As Integer
rev = 0
Do While n > 0
d = n Mod 10
n = n \ 10
rev = rev * 10 + d
Loop
End Function
 


10.Visual Basic program to print Fibonacci Series

Private Sub Command1_Click()
Dim no As Integer, a As Integer, b As Integer, c As Integer
no = CInt(InputBox("enter the no"))
a = 0
b = 1
c = 0
Text2.Text = a
Do While c <= no
c = a + b
If c <= no Then
Text2.Text = Text2.Text & "  " & c
End If
a = b
b = c
Loop
End Sub




11. VB program to find sum of digits in number
Private Sub Command1_Click()
Dim no As Integer, s As Integer, d As Integer
s = CInt(Text1.Text)
Do While s > 9
no = s
s = 0
Do While no > 0
d = no Mod 10
no = no \ 10
s = s + d
Loop
Loop
MsgBox s
End Sub



12.Visual Program to find factorial of a program
Private Sub Command1_Click()

Dim n As Integer
Dim fact As Integer
fact = 1
n = Val(Text1.Text)
For i = 1 To n
fact = fact * i
Next
MsgBox "factorial of " & n & " is = " & fact

End Sub





13.Program to find even and odd numbers from array

Private Sub Command1_Click()

Dim a() As Integer
n = InputBox("How many elements do u want to enter")
ReDim a(n)
Print "Array is : "
For i = 0 To n - 1
a(i) = Val(InputBox("Enter the Elements"))
Print a(i)
Next
Print "Even; Numbers; are: "
For i = 0 To n - 1
If a(i) Mod 2 = 0 Then
Print a(i)
End If
Next

Print "Odd; Numbers; are: "
For i = 0 To n - 1
If a(i) Mod 2 <> 0 Then
Print a(i)
End If
Next

End Sub


14.Program to find roots of quadratic equation.

Private Sub Command1_Click()
Dim f, a, b, c As Integer
Dim s, r1, r2, e, d As Double
b = Val(InputBox("enter value for b"))
a = Val(InputBox("enter value for a"))
c = Val(InputBox("enter value for c"))
d = b * b
e = 4 * a * c
f = d - e
s = Sqr(f)
r1 = (b + s) / (2 * a)
r2 = (-b + s) / (2 * a)
Text1.Text = r1
Text2.Text = r2
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Command3_Click()
Text1.Text = “”
Text2.Text = “”
End Sub

रघुपति राघव राजाराम पतित पावन सीताराम ॥

 रघुपति राघव राजाराम पतित पावन सीताराम ॥ सुंदर विग्रह मेघश्याम गंगा तुलसी शालग्राम ॥ भद्रगिरीश्वर सीताराम भगत-जनप्रिय सीताराम ॥  जानकीरमणा स...