You are on page 1of 40

Assignment 1 :Write a Program to add two numbers by using two text box, three labels control and

one command button.

Proprties :Control

Properties

Textbox 1

Seeting

name
Caption
name
Caption
name
Caption
name

Textbox 2
Label1
Command button

txtfirst
-------txtsecond
-------lblresult
--------cmdsum

caption

&sum

Coding:Private Sub cmdsum_Click()


lblresult.Caption = Val(txtfirst.Text) + Val(txtsecond.Text) End sub

Assignment 2 :Designe a Login form

Proprties :-

Control

Properties

Seeting

Textbox1

name
Caption
name
Caption
name
Caption

txtusername
--------txtpassword
--------cmdlogin
Login

Textbox2
Command Button

Option Explicit
Dim strMyusername As String, strMyPassword As String
Private Sub cmdLogin_Click()
'Variable declaration
Dim strUserName As String, strPassword As String
Dim intResponse As Integer
Static intAttempt As Integer
'Check if user attempted 3 times then exit the application
If intAttempt = 2 Then
MsgBox "You have made 3 wrong attempt" _
2

& "so now application will have to close immediately"


End
End If
'Fetch the username and password in from txtUserName and txtPassword
respectively
strUserName = txtUserName.Text
strPassword = txtPassword.Text
'check wheather given username and password is match or not
If strUserName = strMyusername And strPassword = strMyPassword Then
MsgBox "Welcome to your account", , "Welcome"
End
Else
intAttempt = intAttempt + 1
intResponse = MsgBox("Invalid username or password" & vbCrLf _
& "Would you like to retry ?", vbRetryCancel, "Login Error")
If intResponse = vbRetry Then
txtUserName.SetFocus
Else
End
End If
End If
End Sub
Private Sub Form_Load()
'Set the username and password
strMyusername = "Brajmohan"
strMyPassword = "Gamer"
End Sub
Private Sub txtPassword_GotFocus()
txtPassword.SelStart = 0
txtPassword.SelLength = Len(txtPassword.Text)
End Sub
Private Sub txtUserName_GotFocus()
txtUserName.SelStart = 0
txtUserName.SelLength = Len(txtUserName.Text)
End Sub

Assignment 4 :Write a program to calculate areaf of circle , the value is input by using inputbox.

Proprties :-

Control

Properties

Command Button

name
Caption
name
Caption
name
Caption

Command Button
Label

Seeting
command1
Area
command2
&Input Value
lblresult
----------

Coding :Dim a As Double


Private Sub Command1_Click()
Dim b As Double
b = 3.14 * a * a
blresult.Caption = b
End Sub

Private Sub Command2_Click()


a = InputBox("Enter The Radious Of the circle", "RADIOUS ")
End Sub

Assignment 5 :Write a program to print the even number between 0-25.

Proprties :-

Control

Properties

Seeting

Command Button

name

cmdeven

Coding :Private Sub cmdeven_Click()


Dim a As Integer, i As Integer
For i = 1 To 25 Step 1
If i Mod 2 = 0 Then
Print i
End If
Next
End Sub

Assignment 6:Input any number and print the table of that number.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Caption
name
Text
name
name
Caption

label1
&Enter The Number
label2
&Table
txtnumber
---------lsttable
cmdtable
&table

Label
Text Box
List Box
Command Button

Coding :Private Sub cmdtable_Click()


Dim a As Integer, i As Integer, c As Integer
a = Val(txtnumber.Text)
For i = 1 To 10 Step 1
c=a*i
lsttable.AddItem c
Next
End Sub

Assignment 7 :Input Day if week in number and show through message box its corresponding day of
week in words.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Text
name
Caption

label1
No Of Week
txtnumber
---------cmdday
&Corresponding Day

Text Box
Command Button

Coding :Private Sub cmdday_Click()


Dim a As Integer
a = Val(txtnumber.Text)
If a = 1 Then
MsgBox " This is sunday", vbOKOnly, "Day"
ElseIf a = 2 Then
MsgBox " This is Monday", vbOKOnly, "Day"
ElseIf a = 3 Then
MsgBox " This is Tuesday", vbOKOnly, "Day"
ElseIf a = 4 Then
MsgBox " This is Wednesday", vbOKOnly, "Day"
ElseIf a = 5 Then
MsgBox " This is Thrusday", vbOKOnly, "Day"
ElseIf a = 6 Then
MsgBox " This is friday", vbOKOnly, "Day"
ElseIf a = 7 Then
MsgBox " This is saturday", vbOKOnly, "Day"
Else
MsgBox "This is Invalid Number", vbOKOnly, "Day"
End If
End Sub

10

Assignment 8:Design a list box and add the items entered in the text box.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Text
name
Caption
name

label1
&Item
txtnumber
------cmdadd
&ADD
lstlist

Text Box
Command Button
List box

Coding :Private Sub cmdadd_Click()


Dim a
a = txtnumber.Text
lstlist.AddItem a
End Sub

11

Assignment 9 :Design a two list box and to copy all the selected items from a multi select list box to
another list box.

Proprties :-

Control

Properties

Seeting

Label

List Box

name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name

label1
add Item
cmdadd1
&ADD
cmdadd2
&ADD
cmdcopy
&copy to Left
command1
c&opy to Right
list1

List Box

name

list2

Command Button
Command Button
Command Button
Command Button

12

Coding :Private Sub cmdadd1_Click()


List1.AddItem txttext.Text
End Sub
Private Sub cmdadd2_Click()
List2.AddItem txttext.Text
End Sub
Private Sub cmdcopy_Click()
Dim i As Integer
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) Then
List1.AddItem (List2.List(i))
End If
Next
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then
List2.AddItem (List1.List(i))
End If
Next
End Sub

13

Assignment 10:Input a string INDIA and show in this Way.


I
IN
IND
INDI
INDIA
INDI
IND
IN
I

Proprties :-

Control

Properties

Seeting

Text Box
Label

name
name
Caption
name
Caption

txtinput
lblinput
Enter A String
cmdok
&OK

Command Button

14

Coding :Option Explicit


Private Sub cmdOk_Click()
'Variable Declaration
Dim strInput As String, strTemp As String
Dim intTotChar As Integer, intLength As Integer
'Fetch the string from text box (txtInput) into strInput
strInput = txtInput.Text
'Get the length of string
intLength = Len(strInput)
'Clear the form contents if any
Form1.Cls
For intTotChar = 1 To intLength
strTemp = Left(strInput, intTotChar)
Form1.Print strTemp
Next intTotChar
For intTotChar = intLength - 1 To 1 Step -1
strTemp = Left(strInput, intTotChar)
Form1.Print strTemp
Next intTotChar
End Sub

15

Assignment 11 :Write a program to calculate simple interest by using three labels and text box and
one command button.

Proprties :-

Control

Properties

Label

name
Caption
name
Caption
name
Caption

Label
Label
Label

Seeting
label1
&Principal Amount
label2
&interest Rate
label3
&Time Of Interest In
Year
label4
Simple Interest
lblresult
--------txtamont
---------txtrate
---------txttime
--------cmdinterest
&Simple Interest

name
Caption
name
Caption

Label
Textbox

name

Textbox

name

Textbox

name

Text
Text
Command Button

Text
name
Caption

16

Coding:-

Private Sub cmdinterest_Click()


lblresult.Caption = (Val(txtamount.Text) * Val(txtrate.Text) * _
Val(txttime.Text)) / 100
End Sub

17

Assignment 12 :Design a list box and add following items.


1. factorial
2. power
3. even number
4. sum of digit
write a function of particular items and show the output after selecting any item from
a list box.

Proprties :-

Control

Properties

Seeting

List Box

name
List

Label

name
Caption
name
Caption

list1
Factorial
Power
Even Number
Sum Of Digit
label2
result
lblresult
-----------

Label

18

Coding :Private Sub List1_Click()


If List1.ListIndex = 0 Then
Call fact
ElseIf List1.ListIndex = 1 Then
Call power
ElseIf List1.ListIndex = 2 Then
Call even
ElseIf List1.ListIndex = 3 Then
Call sum
End If
End Sub
Sub fact()
Dim x As Integer, i As Integer, y As Integer
x = InputBox("Enter The Number", "Value")
y=1
For i = x To 1 Step -1
y=y*i
Next
lblresult.Caption = y
End Sub
Sub power()
Dim x As Integer, y As Integer, z As Integer
x = InputBox("Enter The Number", "Value")
y = InputBox("Enter The Power", "Power")
z=1
For i = 1 To y
z=z*x
Next
lblresult.Caption = z
End Sub
Sub even()
Dim x As Integer, y As Integer
x = InputBox("Enter The Value", "Value")
If x Mod 2 = 0 Then
MsgBox "The Number Is Even", vbOKOnly, "Result"
Else
MsgBox " The Number Is Odd", vbOKOnly, "Result"
End If
End Sub
19

Sub sum()
Dim x As Integer, y As Integer, a As Integer
x = InputBox("Enter The First Value ", "Value")
y = InputBox("Enter The Second Value ", "Value")
a=x+y
lblresult.Caption = a
End Sub

20

Assignment 13:Write a procedure that will take a number as an argument and that will return number
is even or odd.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Caption

label1
Procedure
command 1
Take A Value

Command Button

Coding :Private Sub Command1_Click()


Dim a As Integer, res As Integer
a = InputBox(" Enter The Number ", "Value")
res = find(a)
If res = 0 Then
MsgBox "number is Even", vbInformation, "Even"
Else
MsgBox "number is Odd", vbInformation, "Odd"
End If
End Sub

21

Assignment 14 :Write a program to change image by using image box using timer.

Proprties :-

Control

Properties

Seeting

Image Box
Image Box
Image Box
Image Box
Command Button

name
name
name
name
name
Caption

imageScr1
imageScr 2
imageScr3
imageScr 4
cmdstartstop
&Start Rtation

22

Coding :Option Explicit


Dim strPath1 As String, strPath2 As String, strPath3 As String, strPath4 As
String
Private Sub Image1_Click()
End Sub
Private Sub cmdStartStop_Click()
Static blnState As Boolean
blnState = Not blnState
Timer1.Enabled = blnState
If blnState Then
cmdStartStop.Caption = "Stop Rotation"
Else
cmdStartStop.Caption = "Start Rotation"
End If
End Sub
Private Sub Form_Load()
'Load all the image files from application path
strPath1 = App.Path & "\b1.jpg"
strPath2 = App.Path & "\b2.jpg"
strPath3 = App.Path & "\b3.jpg"
strPath4 = App.Path & "\b4.jpg"
'load the images
imgScr1.Picture = LoadPicture(strPath1)
imgScr2.Picture = LoadPicture(strPath2)
imgScr3.Picture = LoadPicture(strPath3)
imgScr4.Picture = LoadPicture(strPath4)
End Sub
Private Sub Timer1_Timer()
Static bytCounter As Byte
Select Case bytCounter
Case 0
imgScr1.Picture = LoadPicture(strPath4)
imgScr2.Picture = LoadPicture(strPath1)
imgScr3.Picture = LoadPicture(strPath2)
imgScr4.Picture = LoadPicture(strPath3)
bytCounter = 1
Case 1
imgScr1.Picture = LoadPicture(strPath3)
imgScr2.Picture = LoadPicture(strPath4)
imgScr3.Picture = LoadPicture(strPath1)
imgScr4.Picture = LoadPicture(strPath2)
bytCounter = 2
Case 2
23

imgScr1.Picture = LoadPicture(strPath2)
imgScr2.Picture = LoadPicture(strPath3)
imgScr3.Picture = LoadPicture(strPath4)
imgScr4.Picture = LoadPicture(strPath1)
bytCounter = 3
Case 3
imgScr1.Picture = LoadPicture(strPath1)
imgScr2.Picture = LoadPicture(strPath2)
imgScr3.Picture = LoadPicture(strPath3) imgScr4.Picture = LoadPicture(strPath4)
bytCounter = 0
End Select
End Sub

24

Assignment 15 :Design four checkbox any color i.e. selected by clicking on checkbox is add to list
box control.

Proprties :-

Control

Properties

Seeting

Check Box

name
Caption
name
Caption
name
Caption
name
Caption
name

chkred(0)
Red
chkred(1)
Green
chkred(2
Blue
chkred(3)
Yellow
list1

Check Box
Check Box
Check Box
List Box

Coding :Private Sub chkRed_Click(Index As Integer)


If chkRed(Index).Value = 1 Then
25

List1.AddItem chkRed(Index).Caption
Else
Dim a As Integer
For a = 0 To List1.ListCount - 1
If List1.List(a) = chkRed(Index).Caption Then
List1.RemoveItem a
Exit For
End If
End If
End Sub

26

Assigment 16 :Draw a form to enter phone number with city code, extract city and phone number in
two different textbox controls.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Caption
name
Caption
name
Text
name
Caption
name
Text
name
Caption

label1
Phone Number
label2
STD code
label3
Phone Number
text1
-------txtpin
-------txtphone
---------command1
&Show

Label
Label
Text Box
Text Box
Text Box
Command Button

27

Coding :Private Sub Command1_Click()


txtpin.Text = Left(Text1.Text, 3)
txtphone.Text = Right(Text1.Text, 7)
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txtpin.Text = Left(Text1.Text, 4)
txtphone.Text = Right(Text1.Text, 7)
End If
End Sub
Private Sub mnuexit_Click()
Unload Form1
Unload MDIForm1
End Sub
Private Sub mnuform_Click()
Form1.Show 1
End Sub
Private Sub mnuGreen_Click()
MDIForm1.BackColor = vbGreen
End Sub
Private Sub mnuRed_Click()
MDIForm1.BackColor = vbRed
End Sub
Private Sub mnuYellow_Click()
MDIForm1.BackColor = vbYellow
End Sub

28

Assigment 17 :Designe a checkbox any item like PEN 2/-, PENCILE 2/- i.e. selected in clicking on
checkbox and calculate their amount after input their quantity in textbox
.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Text
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption

label1
Quantity
txtquantity
---------chkpencil
Pencil
chkpen
Pen
chkcutter
cutter
chkrubber
rubber
cmdamount
Amount
lblresult
----------

Text box
Check Box
Check Box
Check Box
Check Box
Command Button
Label

29

Coding :Private Sub cmdamount_Click()


Dim a As Integer
a = Val(txtquantity.Text)
If chkpencil.Value = 1 Then
blresult.Caption = a * 2
lseIf chkpen.Value = 1 Then
blresult.Caption = a * 3
lseIf chkcutter.Value = 1 Then
blresult.Caption = a * 4
lseIf chkrubber.Value = 1 Then
blresult.Caption = a * 5
End If
End Sub

30

Assignment 18:Design a form with menu item color in sub menu red,Green , Blue on click form back
color should be change.

Proprties :-

Control

Properties

Seeting

Coding :Private Sub Blue_Click()


Form1.BackColor = vbBlue
End Sub
Private Sub Green_Click()
Form1.BackColor = vbGreen
End Sub
Private Sub Red_Click()
Form1.BackColor = vbRed
End Sub

31

Assignment :- 19
Designe a form to enter two number by using interface (input box control) display the
number on form.

32

Proprties :-

Control

Properties

Seeting

Command Button

name
Caption
name
Caption

command 1
Show on Form
command 1
Input Number

Command Button

Coding :Dim a As Integer, b As Integer


Private Sub Command1_Click()
Print a
Print b
End Sub
Private Sub Command2_Click()
a = InputBox("Enter The First Number", "Number")
b = InputBox("Enter The Second Number", "Number")
End Sub

33

Assignment 20 :In question , store student detail in a database (MS-Access) using data control
operation be ADD,EDIT,DELETE, and SAVE.

Proprties :-

Control

Properties

Seeting

Label

name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name

lblname
Name
lblroll
Roll Number
lblclass
Class
lblage
Age
lbladdress
Address
txtname

Label
Label
Label
Label
Text Box

34

Text Box
Text Box
Text Box
Text Box
Command Button
Command Button
Command Button
Command Button
Command Button
Command Button
Command Button
Command Button
Command Button

Text
name
Text
name
Text
name
Text
name
Text
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption

------txtroll
------txtClass
-------txtage
------txtaddress
------cmdfirst
<<
cmdprevious
<
cmdnext
>
cmdLast
>>
cmdadd
&ADD
cmdrem
&Remove
cmdmodify
&Modify
cmdsearch
&Search
cmdupdate
&Update

Coding :Private Sub cmdAdd_Click()


'Add new Record
Data1.Recordset.AddNew
For Each ctrl In Form1.Controls
If TypeOf ctrl Is TextBox Then
With ctrl
.Locked = False
.Text = ""
End With
End If
Next
txtName.SetFocus
End Sub
Private Sub cmdFirst_Click()
'Move to the first record
Data1.Recordset.MoveFirst
End Sub

35

Private Sub cmdLast_Click()


'Move to the last Record
Data1.Recordset.MoveLast
End Sub
Private Sub cmdModify_Click()
'Unlock all the text boxes on form
For Each ctrl In Form1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = False
End If
Next
Data1.Recordset.Edit
End Sub
Private Sub cmdNext_Click()
'Move to the next record
Data1.Recordset.MoveNext
'Check if end of file then move to the last record
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub cmdPrevious_Click()
'Move to the previous record
Data1.Recordset.MovePrevious
'Check if begining of file then move to the first record
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub cmdRem_Click()
'Delete the current record
Data1.Recordset.Delete
Data1.Recordset.MoveNext
'Check if end of file then move to the last record
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub cmdSearch_Click()
Dim intRoll As Integer
36

'Ask for the roll number of student


intRoll = Val(InputBox("Enter the roll number of student do you want to
search", "Roll number", "0"))
'Move to the first record
Data1.Recordset.MoveFirst
'Loop through all the records of database
Do While Data1.Recordset.EOF = False
'Check if desired record is found then exit loop
If Data1.Recordset.Fields("rollno") = intRoll Then
Exit Do
End If
Data1.Recordset.MoveNext
Loop
'if end of file then record is not found and move to the last record
If Data1.Recordset.EOF Then
MsgBox "Cannot find the specified record ", vbInformation, "No
such record"
Data1.Recordset.MoveLast
End If
End Sub
Private Sub cmdUpdate_Click()
'Update the record and lock all the text boxes of form
Data1.Recordset.Update
For Each ctrl In Form1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Locked = True
End If
Next ctrl
End Sub
Private Sub Form_Load()
'Connect to the database and bound all textboxes to that data control(data1)
Data1.DatabaseName = App.Path & "\student.mdb"
Data1.RecordSource = "student"
'Bound the controls
txtName.DataField = "name"
txtClass.DataField = "class"
txtAddress.DataField = "address"
txtAge.DataField = "age"
txtRoll.DataField = "rollno"
End Sub
37

Assignment 21 :Designe a Calculator.

Proprties :-

Control

Properties

Seeting

Command Button

name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name
Caption
name

cmdclear
Clear
Plus
+
div
/
minus
times
*
equals
=
lblscreen

Caption

---------

Command Button
Command Button
Command Button
Command Button
Command Button
Label

38

Coding :Option Explicit


Dim operand1 As Double, operand2 As Double
Dim operator As String
Dim cleardisplay As Boolean
Private Sub cmdclear_Click()
display.Caption = ""
End Sub
Private Sub digit_Click(Index As Integer)
If cleardisplay Then
display.Caption = ""
cleardisplay = False
End If
display.Caption = display.Caption + digit(Index).Caption
End Sub
Private Sub div_Click()
operand1 = Val(display.Caption)
operator = "/"
display.Caption = ""
End Sub
Private Sub dotbutton_Click()
If InStr(display.Caption, ".") Then
Exit Sub
Else
display.Caption = display.Caption + "."
End If
End Sub
Private Sub equals_Click()
Dim result As Double
operand2 = Val(display.Caption)
If operator = "+" Then result = operand1 + operand2
If operator = "-" Then result = operand1 - operand2
If operator = "*" Then result = operand1 * operand2
If operator = "/" And operand2 <> "0" Then
result = operand1 / operand2
End If
display.Caption = result
End Sub
Private Sub minus_Click()
operand1 = Val(display.Caption)
operator = "-"
39

display.Caption = ""
End Sub
Private Sub plus_Click()
operand1 = Val(display.Caption)
operator = "+"
display.Caption = ""
End Sub
Private Sub times_Click()
operand1 = Val(display.Caption)
operator = "*"
display.Caption = ""
End Sub

40

You might also like