Assignment File
-
Upload
ranaindia2011 -
Category
Documents
-
view
10 -
download
0
description
Transcript of Assignment File
Assignment 1 :-
Assignment 1 :-
Write a Program to add two numbers by using two text box, three labels control and one command button.
Proprties :-
Control
Properties
Seeting
Textbox 1
name
txtfirst
Caption
--------
Textbox 2
name
txtsecond
Caption
--------
Label1
name
lblresult
Caption
---------
Command button
name
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
txtusername
Caption
---------
Textbox2
name
txtpassword
Caption
---------
Command Button
name
cmdlogin
Caption
LoginOption 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" _
& "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
SeetingCommand Button
name
command1
Caption
Area
Command Button
name
command2
Caption
&Input Value
Label
name
lblresult
Caption
----------
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
label1
Caption
&Enter The Number
Label
name
label2
Caption
&Table
Text Box
name
txtnumber
Text
----------
List Box
name
lsttable
Command Button
name
cmdtable
Caption
&table
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
label1
Caption
No Of Week
Text Box
name
txtnumber
Text
----------
Command Button
name
cmdday
Caption
&Corresponding Day
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
Assignment 8:-
Design a list box and add the items entered in the text box.
Proprties :-
Control
Properties
Seeting
Label
name
label1
Caption
&Item
Text Box
name
txtnumber
Text
-------
Command Button
name
cmdadd
Caption
&ADD
List box
name
lstlist
Coding :-
Private Sub cmdadd_Click()
Dim a
a = txtnumber.Text
lstlist.AddItem a
End Sub
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
name
label1
Caption
add Item
Command Button
name
cmdadd1
Caption
&ADD
Command Button
name
cmdadd2
Caption
&ADD
Command Button
name
cmdcopy
Caption
© to Left
Command Button
name
command1
Caption
c&opy to Right
List Box
name
list1
List Box
name
list2
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
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
name
txtinput
Label
name
lblinput
Caption
Enter A String
Command Button
name
cmdok
Caption
&OK
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
Assignment 11 :-
Write a program to calculate simple interest by using three labels and text box and one command button.
Proprties :-
Control
Properties
Seeting
Label
name
label1
Caption
&Principal Amount
Label
name
label2
Caption
&interest Rate
Label
name
label3
Caption
&Time Of Interest In
Year
Label
name
label4
Caption
Simple Interest
Label
name
lblresult
Caption
---------
Textbox
name
txtamont
Text
----------
Textbox
name
txtrate
Text
----------
Textbox
name
txttime
Text
---------
Command Button
name
cmdinterest
Caption
&Simple Interest
Coding:-
Private Sub cmdinterest_Click()
lblresult.Caption = (Val(txtamount.Text) * Val(txtrate.Text) * _ Val(txttime.Text)) / 100
End Sub
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
list1
List
Factorial
Power
Even Number
Sum Of Digit
Label
name
label2
Caption
result
Label
name
lblresult
Caption
-----------
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
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
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
label1
Caption
Procedure
Command Button
name
command 1
Caption
Take A Value
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
Assignment 14 :-
Write a program to change image by using image box using timer.
Proprties :-
Control
Properties
Seeting
Image Box
name
imageScr1
Image Box
name
imageScr 2
Image Box
name
imageScr3
Image Box
name
imageScr 4
Command Button
name
cmdstartstop
Caption
&Start Rtation
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
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 SubAssignment 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
chkred(0)
Caption
Red
Check Box
name
chkred(1)
Caption
Green
Check Box
name
chkred(2
Caption
Blue
Check Box
name
chkred(3)
Caption
Yellow
List Box
name
list1
Coding :-
Private Sub chkRed_Click(Index As Integer)
If chkRed(Index).Value = 1 Then
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
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
label1
Caption
Phone Number
Label
name
label2
Caption
STD code
Label
name
label3
Caption
Phone Number
Text Box
name
text1
Text
--------
Text Box
name
txtpin
Caption
--------
Text Box
name
txtphone
Text
----------
Command Button
name
command1
Caption
&Show
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
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
label1
Caption
Quantity
Text box
name
txtquantity
Text
----------
Check Box
name
chkpencil
Caption
Pencil
Check Box
name
chkpen
Caption
Pen
Check Box
name
chkcutter
Caption
cutter
Check Box
name
chkrubber
Caption
rubber
Command Button
name
cmdamount
Caption
Amount
Label
name
lblresult
Caption
----------
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
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
Assignment :- 19
Designe a form to enter two number by using interface (input box control) display the number on form.
Proprties :-
Control
Properties
Seeting
Command Button
name
command 1
Caption
Show on Form
Command Button
name
command 1
Caption
Input Number
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
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
lblname
Caption
Name
Label
name
lblroll
Caption
Roll Number
Label
name
lblclass
Caption
Class
Label
name
lblage
Caption
Age
Label
name
lbladdress
Caption
Address
Text Box
name
txtname
Text
-------
Text Box
name
txtroll
Text
-------
Text Box
name
txtClass
Text
--------
Text Box
name
txtage
Text
-------
Text Box
name
txtaddress
Text
-------
Command Button
name
cmdfirst
Caption
Command Button
name
cmdLast
Caption
>>
Command Button
name
cmdadd
Caption
&ADD
Command Button
name
cmdrem
Caption
&Remove
Command Button
name
cmdmodify
Caption
&Modify
Command Button
name
cmdsearch
Caption
&Search
Command Button
name
cmdupdate
Caption
&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
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
'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
Assignment 21 :-
Designe a Calculator.
Proprties :-
Control
Properties
Seeting
Command Button
name
cmdclear
Caption
Clear
Command Button
name
Plus
Caption
+
Command Button
name
div
Caption
/
Command Button
name
minus
Caption
-
Command Button
name
times
Caption
*
Command Button
name
equals
Caption
=
Label
name
lblscreen
Caption
---------
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 = "-"
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
1