You are on page 1of 58

CODING

1. WAP of Mousedown and Mouseup event in which it is shows


in a textbox wheither a mousedown or a mouseup event is
invoked.
Private Sub Command1_Click()
Text1.Text = ""
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Text1.Text = ""
Text1.Text = "mousedown event"
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single,
Y As Single)
Text1.Text = ""
Text1.Text = "mouseup event
End sub

2.WAP of Gotfocus event shows the application of gotfocus


event. There are some objects on the form of the project.when
an object gets the focus,the forms background color is
changed.
Private Sub Command1_GotFocus()
Form1.BackColor = vbGreen
End Sub
Private Sub Command2_GotFocus()
Form1.BackColor = vbBlue
End Sub
Private Sub Picture1_GotFocus()
Form1.BackColor = vbBlack
End Sub
Private Sub Text1_GotFocus()
Form1.BackColor = vbRed
End Sub

3.WAP for how the option explicit statement works.


Option Explicit
Private Sub Command1_Click()
Dim n As Integer
n = 30
Print n + 1
End Sub

4.WAP for general declaration which shows what actually happens


when a variable is declared in the declaration section.
Dim n As Integer
Private Sub Command1_Click()
n=5
Print n
End Sub
Private Sub Command2_Click()
Print n + 5
End Sub

5.WAP of static variable.This program displays the number of


clicks the user has made.that means it counts the user clicks.
Private Sub Command1_Click()
Static n As Integer
n=n+1
Print n
End Sub

6.WAP for set properties which shows several useful properties.


Private Sub Command1_Click()
'backcolor and forecolor properties
Label1.BackColor = vbRed
Label1.ForeColor = vbBlue
Form1.BackColor = vbGreen
Text1.BackColor = vbBlack
Text1.ForeColor = vbYellow
Frame1.BackColor = vbCyan
Frame1.ForeColor = vbpink
'front properties
Text1.FontSize = 16
Text1.FontItalic = True
Text1.Font = "tahoma"
'caption property
Label1.Caption = "name"
End Sub

7.WAP which demonstrates the password char properties of


textbox.IF correct password is entered,the program displaya
success message . This is a very important concept as it can be
implemented in some real life software projects.
Private Sub Command1_Click()
If Text1.Text = "12345" Then
MsgBox "successful!!!", vbInformation, ""
Else
MsgBox "incorrect password!", vbCritical, ""
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
End Sub

8.WAP for form.


Private subform_load()
Form1.show
PrintWelcome to vb
End sub

9.WAP for textbox which shows how text is displayed in the


textbox object.
Private Sub Command1_Click()
Text1.Text = "Hello"
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Text1.Text = ""
End Sub

10.WAP to display the message taken from a textbox.


Private Sub Command1_Click()
Dim n As String
n = Text1.Text
Print n
End Sub
Private Sub Command2_Click()
Cls
End Sub

11.WAP to print something.


Private Sub Form_activate()
Print 20 + 10
Print 20 - 10
Print 20 * 10
Print 20 / 10
End Sub

12.WAP to add string.


Private Sub Form_Activate()
A = "Prachi"
B = "likes"
C = "studying"
Print A & B & C
End Sub

13.WAP to add values in textbox1 and textbox2.


Private Sub Command1_Click()
Sum = Val(Text1.Text) + Val(Text2.Text)
Text3.Text = Sum
End sub

14.WAP for Default and Cancel property in which when we


press enter from the keyboard a particular message is
displayed.
Private Sub Command1_Click()
MsgBox "you have pressed the default button!", vbInformation, ""
End Sub
Private Sub Command2_Click()
End
End Sub

15.WAP for Inputbox or Msgbox in which a no. is taken as input


and the same is shown in msgbox.
Private Sub Form_Load()
n = InputBox("enter a no.")
MsgBox "you entered" & n
End Sub

16.WAP in which two numbers are entered through input


box,and the sum is shown in the msgbox.
Private Sub Command1_Click()
a = Val(InputBox("enter the value of a", "input value"))
b = Val(InputBox("enter the value oif b", "input value"))
MsgBox "The sum is" & a + b, vbinformattion, "input"
End Sub

17.WAP shows how to show msg in picture Box.The print and


cls methods are used.
Private Sub Command1_Click()
Picoutput.Print "Hello!"
End Sub
Private Sub Command2_Click()
Picoutput.Print "Welcome to VB"
End Sub
Private Sub Command3_Click()
Picoutput.Cls
End Sub

18.WAP for largest no. among three using if-else.


Private Sub Command1_Click()
Dim a, b, c As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a > b And b > c Then
Text4.Text = a
ElseIf b > a And b > c Then
Text4.Text = b
Else
Text4.Text = c
End If
End Sub

19.WAP tells length of string.


Private sub cmdstart_click()
Dim word as string,N as integer
Word=inputbox(Enter the word,Input)
N=Len(word)
Select case N
Case 0
Printyou have not entered word
Case 1
PrintThis is a one letter word
Case 2
Print This s a two letter word
End select
End sub

20.WAP to show your name.


Dim firstname 'secondname'thirdname as string
Private Sub Command1_Click()
firstname = Text1.Text
secondname = Text2.Text
yourname = firstname + " " + secondname
Text3.Text = yourname
End Sub

21.WAP for password for DO.Loop.The loop continues


until password matches.
Private Sub Form_Load()
Do
a=Inputbox(Enter the password)
if a=visual then
msgboxAccess granted!!!
else
msgboxAccess denied..pleas try again
end if
Loop until a=visual
End Sub

22.WAP which formats text in a label control using option


button controls.
Private Sub Option1_Click()
Label1.ForeColor = vbBlue
End Sub
Private Sub Option2_Click()
Label1.ForeColor = vbGreen
End Sub
Private Sub Option3_Click()
Label1.ForeColor = vbCyan
End Sub

23.WAP for check box controls and makes some orders of


restaurant.
Private Sub Command1_Click()
Dim total As Integer
total = 0
Tea = ""
Sandwich = ""
Pizza = ""
If Check1.Value = 1 Then
Tea = "Tea,"
total = total + 5
End If
If Check2.Value = 1 Then
Sandwich = "Sandwich,"
total = total + 20
End If
If check3Pizza.Value = 1 Then
Pizza = "Pizza,"
total = total + 50
End If
Msgbox"you have ordered"Tea&Sandwich&Pizza"and the total price
is"&total,vbinformation,"Thanks"
End Sub

24.WAP which teaches you how to make a shortcut key in


vb.The program enables you to make form green by pressing
ctrl+G.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyG And Shift = vbCtrlMask Then
Form1.BackColor = vbGreen
End If
End Sub

25.WAP for use of timer control to show digital clock.


Private Sub Command1_Click()
Timer1.Enabled = True

End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Text1.Text = 10
End Sub

26.WAP to show a pop menu on the form.


Private Sub Blue_Click()
Form1.BackColor = vbBlue
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
If Button = vbRightButton Then
PopupMenu mnucolors
End If
End Sub
Private Sub Green_Click()
Form1.BackColor = vbGreen
End Sub
Private Sub Red_Click()
Form1.BackColor = vbRed
End Sub
Private Sub White_Click()
Form1.BackColor = vbWhite
End Sub
Private Sub Yellow_Click()
Form1.BackColor = vbYellow
End Sub

27.WAP for login.


Private Sub Command1_Click()
If Text1.Text = "" Then

MsgBox "Enter the username!" 'vbexclamation,""


Exit Sub
End If
If Text2.Text = "" Then
MsgBox "Enter Password!", vbExclamation, ""
Exit Sub
End If
If Text1.Text = "prachi" And Text2.Text = "12345" Then
Form1.Show
Unload Me
Else: MsgBox "username or password,or both are wrong!", vbExclamation, ""
End If
End Sub
Private Sub Command2_Click()
End
End Sub

28.WAP of Lostfocus shows which command button among two


has lost the focus.
Private Sub cmd_Lostfocus()

Msgboxcommand1 has lost the focus


End Sub

29.WAP for mouse capture which show x,y coordinates of the


mouse pointer while you move the mouse on the form and
shows which mouse button has been pressed.
Private Sub Form_mouseDown()

If Button and vbLeftButton then


lblmouseButton.caption=Left
lblmouseButton.caption=Right
lblmouseButton.caption=Middle
end if
lblx.caption=x
lbly.caption=y
end sub
Private Sub Form_mousemove()
lblx.caption=x
lbly.caption=y
End Sub

30.WAP to add,substract,multiply and divide two numbers.


Private Sub Command1_Click()
Me.Text3.Text = Val(Text1.Text) + Val(Text2.Text)

Me.Text4.Text = Val(Text1.Text) - Val(Text2.Text)


Me.Text5.Text = Val(Text1.Text) * Val(Text2.Text)
Me.Text6.Text = Val(Text1.Text) / Val(Text2.Text)
End Sub
Private Sub Form_Load()
MsgBox ("Hello Welcome to perform operations")
End Sub

31.WAP to show the working of Timer.


Private Sub Timer1_Timer()
If Shape1.Visible = True Then

Shape2.Visible = True
Shape1.Visible = False
Shape3.Visible = False
ElseIf Shape2.Visible Then
Shape3.Visible = True
Shape2.Visible = False
Shape1.Visible = False
ElseIf Shape3.Visible Then
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
End If
End Sub

32.WAP to print following series:


1
12

123
1234
12345

Private Sub Form_Click()


For r = 1 To 5
For c = 1 To r
Print c;
Next
Print
Next
End Sub
33.WAP to print a table on the form.
Private Sub Command1_Click()
For k = 1 To 10
Print Val(Text1.Text) * k
Next
End Sub

33.WAP which accepts a no. and multiply it by 2.


Private sub form_Load()
Dim num as integer,ans as integer
Num=Inputbox(Enter a number)

If num>0 Then
Ans=num*2
Else
Unload me
Endif
Tet1.text=ans
Form1.Backcolor=vbBlue
End Sub

34.WAP which accept a no. and display the no. of digit places.
Dim a as integer
Private sub command1.click()
If a<0 Then

Msgboxone digit number


Elseif a>10 and a<100 Then
MsgbxThree digit number
Elseif a>1000 and a<100000 Then
MsgboxFour digit number
End if
Unload me
End Sub
Private Sub form_Load()
Form1.Backcolor=vbGreen
a=Inputbox(Enter your no.)
End Sub

35.WAP to generate a multiplication table of 2.


Private Sub Form_click()
Form1.Backcolor=vbred
Dim num as integer

For num=1 to 10
Print2*;num;=;2*num
Nextnum
End Sub

36. WAP to display all the multiples of 5 from 1 to 25.


Private Sub Form_clck()
Dim num as integer
For num =1 to 5

Print 5*num
Nextnum
End Sub

37. WAP with the two textboxes and two option buttons,when
user enters no. in text1 and text2 display the square and
square root depending on option button selected.
Dim a as integer

Private Sub exit_click()


Unload me
End Sub
Private Sub Form_Load()
Form1.Backcolor=RGB(0,204,204)
End Sub
Private Sub option1_click()
a=val(Text1.Text)
Text2.Text=a*a
End Sub
Private Sub option2_click()
a=val(Text1.Text)
Text2.Text=sqr(a)
End Sub

38.Accept a string in txtbox ,display the length of the


string using msgbox when cmd button is clicked and display
the reverse of string in another txtbox on click another cmd
button.
Dim a as string
Private Sub Command1_click()

MsgboxLength of string:&Len(a)
End Sub
Private Sub Command2_click()
Text2.Text=StrReverse(a)
End Sub
Private Sub Command3_click()
Unload me
End Sub
Private Sub Form_Load()
Form1.Backcolor=RGB(102,255,51)
End Sub
Private Sub Text1_change()
a=Text1.Text
End Sub

39. Create an application using function to find the factorial of


a given no. by the user.
Private Sub Command1_Click()
Dim a As Integer
a = Me.Text1.Text

Print fac(a)
End Sub
Private Sub Command2_Click()
Unload Me
End Sub

Public Function fac(ByVal x)


Dim i As Integer, y
y=1
For i = 1 To x
y=i*y
Next
x=y
Me.Text2.Text = x
End Function

40. WAP in which form contain inputbox and msgbox


controls.A number is taken as input and the same is shown in
msgbox.
Private Sub Form_Load()
n=Inputbox (Enter a number)
msgboxyou entered&n

End Sub

42. WAP of Mousemove event in which when you move the mouse on the form, the
block of code in the mousemove event procedures is executed.As a result the form
becomes larger in size.
Private Sub Form_Mousemove(Button as integer,shift as integer,x as single,y as single)
Form1.Height=Form1.Height+5
Form1.Width=Form1.Width+5
End Sub

43.WAP of math Calculator.


Dim A, B, C, flag As Integer
Dim str As String
Private Sub Command1_Click()
Text1.Text = Me.Text1.Text + "1"
End Sub

Private Sub Command10_Click()


Text1.Text = Me.Text1.Text + "6"
End Sub

Private Sub Command11_Click()


Text1.Text = Me.Text1.Text + "9"
End Sub

Private Sub Command12_Click()


Text1.Text = Me.Text1.Text + "00"
End Sub

Private Sub Command13_Click()


A = Val(Me.Text1.Text)
Text1.Text = ""

str = "+"
End Sub

Private Sub Command14_Click()


A = Val(Me.Text1.Text)
Text1.Text = ""
str = "-"
End Sub

Private Sub Command15_Click()


B = Val(Me.Text1.Text)
Text1.Text = ""
Select Case str
Case "+": C = A + B
Case "-": C = A - B
Case "*": C = A * B
Case "/": C = A / B
Case "%": C = A * (B / 100)
End Select
Text1.Text = C
End Sub

Private Sub Command16_Click()


Me.Text1.Text = ""
A=0
B=0
C=0
str = ""
End Sub

Private Sub Command18_Click()


A = Val(Me.Text1.Text)

Text1.Text = ""
str = "/"
End Sub

Private Sub Command19_Click()


Unload Me
End Sub

Private Sub Command20_Click()


If Me.Text1.Text < 0 Then
MsgBox "can't calculate the square root of a negative number"
Else
Me.Text1.Text = Sqr(Val(Me.Text1.Text))
End If
End Sub

Private Sub Command21_Click()


A = Val(Me.Text1.Text)
Text1.Text = ""
str = "%"
End Sub

Private Sub Command22_Click()


If (Me.Text1.Text = C) Then
Text1.Text = A
ElseIf (Me.Text1.Text = A) Then
Text1.Text = B
Else
Text1.Text = C
End If
End Sub

Private Sub Command23_Click()


If (Me.Text1.Text = C) Then
Text1.Text = B
ElseIf (Me.Text1.Text = A) Then
Text1.Text = C
Else
Text1.Text = A
End If
End Sub

Private Sub Command6_Click()


Text1.Text = Me.Text1.Text + "5"
End Sub

Private Sub Command17_Click()


A = Val(Me.Text1.Text)
Text1.Text = ""
str = "*"
End Sub

Private Sub Command2_Click()


Text1.Text = Me.Text1.Text + "4"
End Sub

Private Sub Command3_Click()


Text1.Text = Me.Text1.Text + "7"
End Sub

Private Sub Command4_Click()


Text1.Text = Me.Text1.Text + "0"
End Sub

Private Sub Command5_Click()


Text1.Text = Me.Text1.Text + "2"
End Sub

Private Sub Command7_Click()


Text1.Text = Me.Text1.Text + "8"
End Sub

Private Sub Command8_Click()


Text1.Text = Me.Text1.Text + "."
End Sub

Private Sub Command9_Click()


Text1.Text = Me.Text1.Text + "3"
End Sub

44.WAP contain a textbox and enter a number if no. is greater then 0 then print
num*2.
Private Sub Form_Load()
Dim num As Integer, ans As Integer
num = InputBox("enter a number")
If num > 0 Then
ans = num * 2
Else
Unload Me
End If
Text1.Text = ans
Form1.BackColor = ubblue
End Sub

45. Create an application using function to calculate Compound Interest.


Private Sub Command1_Click()
p = Text1.Text
r = Text2.Text
y = Text3.Text
ci = intrest(p, r, y)
Text4.Text = ci
End Sub

Private Sub Command2_Click()


Unload Me
End Sub

Public Function intrest(ByVal pri As Double, ByVal rat As Double, ByVal yr As Double)
Dim p, r, y, ci As Double
Dim re As Double
re = (1 + (rat / 100)) ^ yr
re = pri * re
intrest = re
End Function

Private Sub Form_Load()


Form1.BackColor = vbRed
End Sub

46. Create an application in using function to swap the values.


Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Command2_Click()


Dim a As Integer
Dim b As Integer
Dim c As Integer
a = Text1.Text
b = Text2.Text
Text1.Text = ""
Text2.Text = ""
c = swap(a, b, c)
End Sub

Public Function swap(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer


z=x
x=y
y=z
Text1.Text = x
Text2.Text = y

End Function

Private Sub Form_Load()


Me.BackColor = vbGreen
End Sub

47. Create two forms to display details from the table product and supplier of the
database. Display these via menu option of MDI application.
FOR MDI FORM:Private Sub ex_Click()
Unload Me
End Sub
Private Sub pro_Click()
Form1.Show
End Sub
Private Sub sup_Click()
Form2.Show
End Sub

FOR SUPPLIER FORM:Private Sub Command1_Click()


Unload Me
End Sub
Private Sub Form_Load()
Me.BackColor = vbYellow
End Sub

FOR PODUCT FORM:-

Private Sub Command1_Click()


Unload Me
End Sub
Private Sub Form_Load()
Me.BackColor = vbGreen
End Sub

48. Create an application that determine the future value of an investment at a given
rate for a given number of years, and display the future value in currency format.
Private Sub Command1_Click()
Dim amt As Integer, rate As Integer, fvalue As Long, time As Integer
amt = Text1.Text
rate = Text2.Text
time = Text3.Text
fvalue = amt * (1 + rate / 100) ^ time
Text4.Text = FormatCurrency(fvalue, -1)
End Sub

Private Sub Command2_Click()


Me.Text1.Text = ""
Me.Text2.Text = ""
Me.Text3.Text = ""
Me.Text4.Text = ""
Me.Text1.SetFocus
End Sub

Private Sub Command3_Click()


Unload Me
End Sub

Private Sub Form_Load()

Me.BackColor = vbGreen
End Sub

49. Create an application using array of option control for changing the form back
color.
Dim m As Long
Private Sub Command1_Click()
Me.BackColor = m
End Sub

Private Sub Command2_Click()


Unload Me
End Sub

Private Sub Option1_Click(Index As Integer)


Select Case Index
Case 0: m = vbRed
Case 1: m = vbBlue
Case 2: m = vbGreen
Case 3: m = vbYellow
Case 4: m = vbBlack
Case 5: m = vbWhite
End Select
End Sub

50. Create an application using data grid control show the details of the table book.
Private Sub Form_Load()
Me.BackColor = vbBlue
End Sub
Private Sub mnu_ex_Click()
Unload Me
End Sub

You might also like