1)WRITE A VB PROGRAM TO DESING A SIMPLE CALCULATOR TO
PERFORM ADDITION,SUBTRACTION,MULTIPLICATION AND DIVISION
(USE FUNCTIONS FOR THE CALCULATION).
Dim a As Long
Dim b As Long
Dim op As String
Private Sub Command1_Click(Index As Integer)
[Link] = [Link] + Command1(Index).Caption
End Sub
Private Sub Cmdplus_Click()
a = Val([Link])
[Link] = ""
op = "+"
End Sub
Private Sub Cmdsubt_Click()
a = Val([Link])
[Link] = ""
op = "-"
End Sub
Private Sub Cmdmul_Click()
a = Val([Link])
[Link] = ""
op = "*"
End Sub
Private Sub Cmdequal_Click()
b = Val([Link])
[Link] = ""
If op = "+" Then
[Link] = add(ByVal a, ByVal b)
Else
If op = "-" Then
[Link] = subt(ByVal a, ByVal b)
Else
If op = "*" Then
[Link] = mul(ByVal a, ByVal b)
Else
If op = "/" Then
[Link] = div(ByVal a, ByVal b)
End If
End If
End If
End If
End Sub
Function add(ByVal a As Integer, ByVal b As Integer) As Integer
add = a + b
End Function
Function subt(ByVal a As Integer, ByVal b As Integer) As Integer
subt = a - b
End Function
Function mul(ByVal a As Integer, ByVal b As Integer) As Integer
mul = a * b
End Function
Function div(ByVal a As Integer, ByVal b As Integer) As Integer
div = a / b
End Function
Private Sub Cmddiv_Click()
a = Val([Link])
[Link] = ""
op = "/"
End Sub
Private Sub Command7_Click()
[Link] = ""
End Sub
2>DESIGN A VB APPLICATION WHICH HAS MDI AND CHILD FORMS
.CREATE A MENU HAVING THE ITEMS SUCH AS FILE
(NEW,OPEN),FORMAT(FONT,REGULAR,BOLD,ITALIC)AND EXIT IN THE
MOI [Link] CREATE A TEXT BOX AND USE A COMMON DIALOG
BOX CONTROL FOR CHANGING THE FONT ,FORECOLOR AND BACK
COLOR OF THE TEXT BOX.
Private Sub mnuarial_Click()
[Link] = "Arial"
End Sub
Private Sub mnubold_Click()
[Link] = True
End Sub
Private Sub mnucalibiri_Click()
[Link] = "calibiri"
End Sub
Private Sub mnuexit_Click()
Unload Me
End Sub
[Link] = "garamond"
Private Sub mnuimpact_Click()
[Link] = "impact"
End Sub
Private Sub mnuitalic_Click()
[Link] = True
End Sub
Private Sub mnulucida_Click()
[Link] = "lucida"
End Sub
Private Sub mnunew_Click()
[Link]
End Sub
Private Sub mnuopen_Click()
[Link]
End Sub
Private Sub mnuregular_Click()
[Link] = False
[Link] = False
End Sub
Private Sub Cmdexit_Click()
Unload Me
End Sub
Private Sub Cmdsave_Click()
Dim filelocation As String
'loads save as box
If [Link] <> "" Then
[Link]
filelocation = [Link]
If filelocation <> "" Then
'append saves over file if it assists
Open filelocation For Append As #1
Print #1, [Link]
Close #1
Else
MsgBox "filename not [Link] cannot be saved"
End If
Else
MsgBox "text box is empty"
End If
End SubPrivate Sub Cmdopen_Click()
Dim filelocation As String
'show open box
[Link]
filelocation = [Link]
If filelocation <> "" Then
'input files into [Link]
Open filelocation For Input As #1
Do Until EOF(1)
Input #1, Data
[Link] = [Link] + Data + vbNewLine
Loop
Close #1
Else
MsgBox "no filename selected ->->"
End If
End Sub
Private Sub Cmdexit_Click()
Unload Me
End Sub
3>DESIGN A SMALL ALARM CLOCK APPLICATION.
Private Sub Command1_Click()
[Link] = [Link]
End Sub
Private Sub Command2_Click()
[Link] = True
End Sub
Private Sub Text1_gotfocus()
[Link] = "[Link]"
End Sub
Private Sub Timer1_Timer()
If Format(Time, "hh:mm:ss") = [Link] Then
'beep
MsgBox ("message.......")
End If
End Sub
Private Sub Timer2_Timer()
[Link] = Format(Time, "hh:mm:ss")
End Sub
4>VB PROGRAM TO CREATE A SEQUENTIAL FILE CONTAINING THE
FIELDS,ADDRESS,CITY,PIN,CODE AND PHONE [Link] THE
RECORDS IN A NEAT FORMAT.
Private Sub Cmdwrite_Click()
Open "D:\data\[Link]" For Append As #1
Write #1, Txtname, Txtaddr, Txtstate, Txtcity, Txtpin, Txtphon
Close #1
clrtext
End Sub
Private Sub Cmddisplay_Click()
Dim no As Integer
[Link]
[Link] = True
[Link](0, 0) = "slno"
[Link](0, 1) = "name"
[Link](0, 2) = "address"
[Link](0, 3) = "state"
[Link](0, 4) = "city"
[Link](0, 5) = "pincode"
[Link](0, 6) = "phoneno"
Open "D:\data\[Link]" For Input As #1
no = 1
slno = 1
While Not EOF(1)
[Link] = [Link] + 1
Input #1, v1, v2, v3, v4, v5, v6
[Link](no, 0) = slno
[Link](no, 1) = v1
[Link](no, 2) = v2
[Link](no, 3) = v3
[Link](no, 4) = v4
[Link](no, 5) = v5
[Link](no, 6) = v6
no = no + 1
slno = slno + 1
Wend
Close #1
End Sub
Private Sub Form_Load()
[Link](0) = 550
[Link](1) = 1000
[Link](2) = 1500
[Link](3) = 1200
[Link](4) = 1200
[Link](5) = 1100
End Sub
Private Sub clrtext()
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
End SUB
5>Write a vb program to validate the username and password from the
database and display the appropriate message
Dim rs As New [Link]
Dim conn As New [Link]
Private Sub Cmdcancel_Click()
Unload Me
End Sub
Private Sub Cmdlogin_Click()
If [Link] = "" Then
MsgBox "Enter the username", vbInformation + vbOKOnly, "login"
[Link]
Exit Sub
End If
If [Link] = "" Then
MsgBox "Enter the password", vbInformation + vbOKOnly, "login"
[Link]
Exit Sub
End If
If [Link] <> "" And [Link] <> "" Then
If [Link] = 1 Then
[Link]
Else
[Link] "select* from login where username='" & Text1 & "' and password=
'" & Text2 & "'", conn, adOpenDynamic, adLockOptimistic, adCmdText
End If
If [Link] = True Then
MsgBox " Invalid username and password", vbCritical + vbOKOnly,
"login"
[Link] = ""
[Link] = ""
[Link]
Else
MsgBox " Username and password correct", vbInformation + vbOKOnly,
"login"
End If
End If
End Sub
Private Sub Form_Load()
[Link] "Provider=[Link].4.0;Data Source=C:\Users\P
Sandhya\Documents\[Link];persist security info=false"
End Sub
6>Design a vb application to record the employee details such as empid,
Empname,designation,and basic [Link] DA,HRA,Deduction and
Gross salary[make the necessary assumption].Use select case for
Decision making.
Private Sub Command1_Click()
Dim bp, da, hra, ded, gp, np As Integer
If [Link] = " " Or [Link] = "" Or [Link] = "" Or [Link] = ""
Then
MsgBox "fields cannot be left blank"
[Link]
End If
bp = Val([Link])
Select Case bp
Case 0 To 2000
da = 2 / 100 * bp
hra = 3 / 100 * bp
ded = 50
[Link] = Val(da)
[Link] = Val(hra)
[Link] = Val(ded)
Case 2001 To 5000
da = 4 / 100 * bp
hra = 5 / 100 * bp
ded = 100
[Link] = Val(da)
[Link] = Val(hra)
[Link] = Val(ded)
Case 5001 To 10000
da = 6 / 100 * bp
hra = 7 / 100 * bp
ded = 1000
[Link] = Val(da)
[Link] = Val(hra)
[Link] = Val(ded)
Case Is > 10000
da = 8 / 100 * bp
hra = 9 / 100 * bp
ded = 1500
[Link] = Val(da)
[Link] = Val(hra)
[Link] = Val(ded)
Case Else
MsgBox "enter the basic pay"
End Select
gp = bp + da + hra
[Link] = Val(gp)
np = gp - ded
[Link] = Val(np)
End Sub
Private Sub Command2_Click()
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link]
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Text4_keypress(keyascii As Integer)
If (keyascii < 48 And keyascii <> 46 And keyascii <> 8) Or (keyascii > 57)
Then
keyascii = 0
MsgBox "Enter numeric value"
[Link]
End If
End Sub
7>Create a vending machine application ,that display images for four
Snacks,and corresponding labels that indicate number for each snack.
The GUI should contain a textbox in which the user specifies the number
Of thedesired [Link] the dispence snack button is [Link] should
Display on label the name of the snack [Link] end it should print
The bill of the product.
Dim slno As Integer
Dim rno As Integer
Dim totalbill As Integer
Private Sub Command1_Click()
Dim sname As String
[Link] = ""
If [Link] = "" Or Val([Link]) <= 0 Then
MsgBox "quantity cannot be blank or 0 or negative"
Exit Sub
End If
If [Link] = False And [Link] = False And
[Link] = False And [Link] = False Then
MsgBox " Please select atleast one snack"
End If
If [Link] = True Then
sname = [Link]
sprice = 20
ElseIf [Link] = True Then
sname = [Link]
sprice = 25
ElseIf [Link] = True Then
sname = [Link]
sprice = 25
ElseIf [Link] = True Then
sname = [Link]
sprice = 25
End If
[Link] = sname
[Link](0, 0) = "slno"
[Link](0, 1) = "sname"
[Link](0, 2) = "sprice"
[Link](0, 3) = "qty"
[Link](0, 4) = "totalbill"
[Link] = [Link] + 1
[Link] = sname
[Link] = [Link] + 1
[Link](rno, 0) = slno
[Link](rno, 1) = sname
[Link](rno, 2) = sprice
[Link](rno, 3) = [Link]
[Link](rno, 4) = Val([Link]) * sprice
totalbill = totalbill + Val([Link](rno, 4))
Textbill = totalbill
slno = slno + 1
rno = rno + 1
Txtqty = ""
End Sub
Private Sub Command2_Click()
MsgBox "totalbillamount is" + [Link]
End
End Sub
Private Sub Form_Load()
rno = 1
slno = 1
[Link] = 5
[Link](0) = 800
[Link](1) = 3000
[Link](2) = 1200
[Link](3) = 1200
[Link](4) = 1200
[Link] = "pepsi"
[Link] = "almond"
[Link] = "samosa"
[Link] = "chocolate” End Sub
8>Change the font of the text in a text box using the control listbox,
Checkbox for effect,combo box for size and colour and option button
For font style.
Private Sub Check1_Click()
If [Link] = Checked Then
[Link] = True
ElseIf [Link] = Unchecked Then
[Link] = False
End If
End Sub
Private Sub Check2_Click()
If [Link] = Checked Then
[Link] = True
ElseIf [Link] = Unchecked Then
[Link] = False
End If
End Sub
Private Sub Combo1_Click()
[Link] = [Link]
End Sub
Private Sub Combo2_Click()
If [Link] = "red" Then
[Link] = vbRed
ElseIf [Link] = "blue" Then
[Link] = vbBlue
ElseIf [Link] = "green" Then
[Link] = vbGreen
End If
End Sub
Private Sub Form_Load()
For i = 1 To 198
[Link] [Link](i)
Next i
[Link] "red"
[Link] "blue"
[Link] "green"
[Link] 10
[Link] 14
[Link] 18
[Link] 24
[Link] 28
End Sub
Private Sub List1_Click()
[Link] = [Link]
End Sub
Private Sub Option1_Click()
If [Link] = True Then
[Link] = True
[Link] = False
End If
End Sub
Private Sub Option2_Click()
If [Link] = True Then
[Link] = False
[Link] = True
End If
End Sub
Private Sub Option3_Click()
If [Link] = True Then
[Link] = False
[Link] = False
End If
End Sub
Private Sub Option4_Click()
If [Link] = True Then
[Link] = True
[Link] = True
End If
End Sub
9>VC++ program to create a dialogbox and display the position of mouse
Pointer with in the dialog box.
{
//TODO:Add your message handler code here and/or call default
CString strMessage;
[Link](“Mouse position=(%d %d)”,point.x,point.y);
m_strname=strMessage;
UpdateData(FALSE);
CDialog::OnMouseMove(nFlags,point);
}
10>VC++ program to create and load a simple menu in a window.
#include<afxwin.h>
#include "resource.h"
class myframe:public CFrameWnd
{
public:
myframe()
{
Create(0,"load menu using
MAKEINTRESOURCE",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEI
NTRESOURCE(IDR_MENU1));
}
};
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe();
p->ShowWindow(1);
m_pMainWnd=p;
return 1;
}
};
myapp a;
11>Design a user interface(UJ)to accept the student details such as name,
Department,and total [Link] the input data and calculate the
Percentage and division.
Dim sum As Integer
Dim avg As Integer
Private Sub Command1_Click()
sum = Val([Link]) + Val([Link]) + Val([Link])
average = sum / 3
[Link] = average
If average > 75 Then
[Link] = "a"
ElseIf average > 50 Then
[Link] = "b"
ElseIf average > 35 Then
[Link] = "c"
Else
[Link] = "d"
End If
End Sub
Private Sub Command2_Click()
[Link] = " "
[Link] = " "
[Link] = " "
[Link] = " "
[Link] = " "
End Sub
Private Sub Command3_Click()
End
End Sub
12>VB Program to encrypt and decrypt a string(use RndO to generate the
Encryption and decryptrion keys).
Option Explicit
Dim x As String
Dim y As String
Private Sub Command1_Click()
x = encryptdecrypt([Link], True)
[Link] = x
End Sub
Private Sub Command2_Click()
[Link] = ""
[Link] = ""
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Public Function encryptdecrypt(ByVal strval, ByVal blndec As Boolean)
As String
Dim int1, int2, int3 As Integer
Dim str1, str2, str3, str4 As String
str1 = strval
int1 = Len(str1)
int2 = 1
Randomize
Do While int2 <> (int1 + 1)
str2 = Mid(str1, int2, 1)
If blndec = True Then
int3 = Asc(str2) - 3
Else
int3 = Asc(str2) + 3
End If
str3 = Chr(int3)
str4 = str4 & str3
int2 = int2 + 1
Loop
encryptdecrypt = str4
End Function
Private Sub Command4_Click()
x = encryptdecrypt([Link], False)
[Link] = x
End Sub
13>Design a VB application to accept the
itemdetails(itemid,itemname,mfddate,unit of measure,and rate per unit).
Itemid should be a system generated id. The application should allow the
Operations-add,modify,delete,update and navigation of the [Link]
ADO data controls and grid controls.
Private Sub Cmdadd_Click()
Dim id As Integer
On Error GoTo errmsg
[Link]
[Link]
id = [Link]("item_id") + 1
[Link]
[Link] = id
[Link]
Exit Sub
errmsg:
[Link]
[Link] = 1
[Link]
End Sub
Private Sub Cmddelete_Click()
On Error GoTo errmsg
Dim wish As Integer
wish = MsgBox("do you really want to delete (y/n)?", vbYesNo +
vbQuestion + vbDefaultButton1)
If wish = vbYes Then
[Link]
[Link]
If [Link] Then
[Link]
End If
MsgBox "item deleted successfully"
End If
Exit Sub
errmsg:
MsgBox [Link]
End Sub
Private Sub Cmdexit_Click()
End
End Sub
Private Sub cmdfirst_Click()
On Error GoTo errmsg
[Link]
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdlast_Click()
On Error GoTo errmsg
[Link]
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdnext_Click()
On Error GoTo errmsg
[Link]
If [Link] Then
[Link]
MsgBox "reached last record'"
End If
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdprevious_Click()
On Error GoTo errmsg
[Link]
If [Link] Then
[Link]
MsgBox "reached first record"
End If
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdsave_Click()
On Error GoTo errmsg
[Link]
MsgBox "record saved"
Exit Sub
errmsg:
MsgBox "[Link]"
End Sub
Private Sub Cmdsearch_Click()
On eroor GoTo errmsg
Dim id1 As Integer
[Link]
id1 = InputBox("enter the item id", "item list is to be checked")
[Link] "item_id=" & id1
If [Link] Then
MsgBox "item id does not found"
Exit Sub
End If
Exit Sub
errmsg:
MsgBox "[Link]"
End Sub
Private Sub Cmdupdate_Click()
[Link]
End Sub
14>Design an application to design a screen saver.
Private Sub Timer1_Timer()
Call drawflower
End Sub
Private Sub drawflower()
Dim totalradian, r, a, theta, x, y As Single
Randomize
Scale (3, -3)-(-3, 3)
totalradian = 8 * Atn(1)
ForeColor = RGB(Rnd() * 256, Rnd() * 256, Rnd() * 256)
a = 3 * Rnd()
For theta = 0.01 To totalradian Step 0.01
r = a * Sin(10 * theta)
x = r * Cos(theta)
y = r * Sin(theta)
PSet (x, y)
Next
End Sub
15>An application to demonstrate the usage of scroll bar.
Private Sub HScroll1_Change()
[Link] = RGB([Link], [Link],
[Link])
[Link] = [Link]
End Sub
Private Sub HScroll2_Change()
[Link] = RGB([Link], [Link],
[Link])
[Link] = [Link]
End Sub
Private Sub HScroll3_Change()
[Link] = RGB([Link], [Link],
[Link])
[Link] = [Link]
End Sub
16>Program to load an image using drive listbox,directory listbox,
File listbox and image control.
Private Sub Command1_Click()
Dim img1 As String
If Right([Link], 1) = "\" Then
img1 = [Link] + [Link]
Else
img1 = [Link] + "\" + [Link]
End If
[Link] = img1
[Link] = LoadPicture(img1)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Dir1_Change()
[Link] = [Link]
End Sub
Private Sub Drive1_Change()
[Link] = [Link]
End Sub
Private Sub File1_Click()
Dim img1 As String
If Right([Link], 1) = "\" Then
img1 = [Link] + [Link]
Else
img1 = [Link] + "\" + [Link]
End If
[Link] = img1
[Link] = LoadPicture(img1)
End Sub
17>VC++ PROGRAM TO CREATE STATUS BAR SHOWING THE STATUS OF CAPS
LOCK, SCROLL LOCK AND NUM LOCK KEYS
#include<afxwin.h>
#include<afxext.h>
class myframe : public CFrameWnd
{
private :
CStatusBar s;
unsigned int indicators[4];
public :
myframe()
{
Create(0," STATUS OF TOGGLE KEY ");
}
int OnCreate(LPCREATESTRUCT l)
{
CFrameWnd::OnCreate(l);
[Link](this);
indicators[0]=0;
indicators[1]=ID_INDICATOR_CAPS;
indicators[2]=ID_INDICATOR_NUM;
indicators[3]=ID_INDICATOR_SCRL;
[Link](indicators,4);
return 0;
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
class myapp : public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe();
p->ShowWindow(1);
m_pMainWnd=p;
return 1;
}
};
myapp a;