Sei sulla pagina 1di 41

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)
Text1.Text = Text1.Text + Command1(Index).Caption
End Sub
Private Sub Cmdplus_Click()
a = Val(Text1.Text)
Text1.Text = ""
op = "+"
End Sub
Private Sub Cmdsubt_Click()
a = Val(Text1.Text)
Text1.Text = ""
op = "-"
End Sub

Private Sub Cmdmul_Click()


a = Val(Text1.Text)
Text1.Text = ""
op = "*"
End Sub

Private Sub Cmdequal_Click()


b = Val(Text1.Text)
Text1.Text = ""
If op = "+" Then
Text1.Text = add(ByVal a, ByVal b)
Else
If op = "-" Then
Text1.Text = subt(ByVal a, ByVal b)
Else
If op = "*" Then
Text1.Text = mul(ByVal a, ByVal b)
Else
If op = "/" Then
Text1.Text = 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(Text1.Text)
Text1.Text = ""
op = "/"
End Sub
Private Sub Command7_Click()
Text1.Text = ""
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 FORM.ALSO 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()


MDIForm1.txtdemo.FontName = "Arial"
End Sub
Private Sub mnubold_Click()
MDIForm1.txtdemo.FontBold = True
End Sub
Private Sub mnucalibiri_Click()
MDIForm1.txtdemo.FontName = "calibiri"
End Sub

Private Sub mnuexit_Click()


Unload Me
End Sub
MDIForm1.txtdemo.FontName = "garamond"
Private Sub mnuimpact_Click()
MDIForm1.txtdemo.FontName = "impact"
End Sub
Private Sub mnuitalic_Click()
MDIForm1.txtdemo.FontItalic = True
End Sub
Private Sub mnulucida_Click()
MDIForm1.txtdemo.FontName = "lucida"
End Sub
Private Sub mnunew_Click()
frmch1.Show
End Sub
Private Sub mnuopen_Click()
Frmch2.Show
End Sub
Private Sub mnuregular_Click()
MDIForm1.txtdemo.FontBold = False
MDIForm1.txtdemo.FontItalic = False
End Sub
Private Sub Cmdexit_Click()
Unload Me
End Sub

Private Sub Cmdsave_Click()


Dim filelocation As String
'loads save as box
If TEXT1.Text <> "" Then
CommonDialog1.ShowSave
filelocation = CommonDialog1.FileName
If filelocation <> "" Then
'append saves over file if it assists
Open filelocation For Append As #1
Print #1, TEXT1.Text
Close #1
Else
MsgBox "filename not specified.file 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
CommonDialog1.ShowOpen
filelocation = CommonDialog1.FileName
If filelocation <> "" Then
'input files into text1.text
Open filelocation For Input As #1
Do Until EOF(1)
Input #1, Data
TEXT1.Text = TEXT1.Text + 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()


Label2.Caption = Text1.Text
End Sub
Private Sub Command2_Click()
Timer1.Enabled = True
End Sub
Private Sub Text1_gotfocus()
Text1.Text = "00:00:00"
End Sub
Private Sub Timer1_Timer()
If Format(Time, "hh:mm:ss") = Label2.Caption Then
'beep
MsgBox ("message.......")
End If
End Sub
Private Sub Timer2_Timer()
Label1.Caption = Format(Time, "hh:mm:ss")
End Sub
4>VB PROGRAM TO CREATE A SEQUENTIAL FILE CONTAINING THE
FIELDS,ADDRESS,CITY,PIN,CODE AND PHONE NUMBER.DISPLAY THE
RECORDS IN A NEAT FORMAT.

Private Sub Cmdwrite_Click()


Open "D:\data\write.txt" 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
grid1.Clear
grid1.Visible = True
grid1.TextMatrix(0, 0) = "slno"
grid1.TextMatrix(0, 1) = "name"
grid1.TextMatrix(0, 2) = "address"
grid1.TextMatrix(0, 3) = "state"
grid1.TextMatrix(0, 4) = "city"
grid1.TextMatrix(0, 5) = "pincode"
grid1.TextMatrix(0, 6) = "phoneno"
Open "D:\data\write.txt" For Input As #1
no = 1
slno = 1
While Not EOF(1)
grid1.Rows = grid1.Rows + 1
Input #1, v1, v2, v3, v4, v5, v6
grid1.TextMatrix(no, 0) = slno
grid1.TextMatrix(no, 1) = v1
grid1.TextMatrix(no, 2) = v2
grid1.TextMatrix(no, 3) = v3
grid1.TextMatrix(no, 4) = v4
grid1.TextMatrix(no, 5) = v5
grid1.TextMatrix(no, 6) = v6
no = no + 1
slno = slno + 1
Wend
Close #1
End Sub
Private Sub Form_Load()
grid1.ColWidth(0) = 550
grid1.ColWidth(1) = 1000
grid1.ColWidth(2) = 1500
grid1.ColWidth(3) = 1200
grid1.ColWidth(4) = 1200
grid1.ColWidth(5) = 1100
End Sub
Private Sub clrtext()
Txtname.Text = ""
Txtaddr.Text = ""
Txtstate.Text = ""
Txtcity.Text = ""
Txtpin.Text = ""
Txtphon.Text = ""
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 ADODB.Recordset


Dim conn As New ADODB.Connection
Private Sub Cmdcancel_Click()
Unload Me
End Sub

Private Sub Cmdlogin_Click()


If Text1.Text = "" Then
MsgBox "Enter the username", vbInformation + vbOKOnly, "login"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "Enter the password", vbInformation + vbOKOnly, "login"
Text2.SetFocus
Exit Sub
End If
If Text1.Text <> "" And Text2.Text <> "" Then
If rs.State = 1 Then
rs.Close
Else
rs.Open "select* from login where username='" & Text1 & "' and password=
'" & Text2 & "'", conn, adOpenDynamic, adLockOptimistic, adCmdText
End If
If rs.EOF = True Then
MsgBox " Invalid username and password", vbCritical + vbOKOnly,
"login"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
Else
MsgBox " Username and password correct", vbInformation + vbOKOnly,
"login"
End If
End If
End Sub

Private Sub Form_Load()


conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\P
Sandhya\Documents\sandhya.mdb;persist security info=false"
End Sub

6>Design a vb application to record the employee details such as empid,


Empname,designation,and basic pay.calculate 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 Text1.Text = " " Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = ""
Then
MsgBox "fields cannot be left blank"
Text1.SetFocus
End If
bp = Val(Text4.Text)
Select Case bp
Case 0 To 2000
da = 2 / 100 * bp
hra = 3 / 100 * bp
ded = 50
Text5.Text = Val(da)
Text6.Text = Val(hra)
Text7.Text = Val(ded)
Case 2001 To 5000
da = 4 / 100 * bp
hra = 5 / 100 * bp
ded = 100
Text5.Text = Val(da)
Text6.Text = Val(hra)
Text7.Text = Val(ded)
Case 5001 To 10000
da = 6 / 100 * bp
hra = 7 / 100 * bp
ded = 1000
Text5.Text = Val(da)
Text6.Text = Val(hra)
Text7.Text = Val(ded)
Case Is > 10000
da = 8 / 100 * bp
hra = 9 / 100 * bp
ded = 1500
Text5.Text = Val(da)
Text6.Text = Val(hra)
Text7.Text = Val(ded)
Case Else
MsgBox "enter the basic pay"
End Select
gp = bp + da + hra
Text10.Text = Val(gp)
np = gp - ded
Text9.Text = Val(np)
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text1.SetFocus
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"
Text4.SetFocus
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 snack.When the dispence snack button is clicked.It should
Display on label the name of the snack dispend.At 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
Lbldisplay.Caption = ""
If Txtqty.Text = "" Or Val(Txtqty.Text) <= 0 Then
MsgBox "quantity cannot be blank or 0 or negative"
Exit Sub
End If
If Optsnack1.Value = False And Optsnack2.Value = False And
Optsnack3.Value = False And Optsnack4.Value = False Then
MsgBox " Please select atleast one snack"
End If
If Optsnack1.Value = True Then
sname = Optsnack1.Caption
sprice = 20
ElseIf Optsnack2.Value = True Then
sname = Optsnack2.Caption
sprice = 25
ElseIf Optsnack3.Value = True Then
sname = Optsnack3.Caption
sprice = 25
ElseIf Optsnack4.Value = True Then
sname = Optsnack4.Caption
sprice = 25
End If
Lbldisplay.Caption = sname
MSFlex1.TextMatrix(0, 0) = "slno"
MSFlex1.TextMatrix(0, 1) = "sname"
MSFlex1.TextMatrix(0, 2) = "sprice"
MSFlex1.TextMatrix(0, 3) = "qty"
MSFlex1.TextMatrix(0, 4) = "totalbill"
MSFlex1.Rows = MSFlex1.Rows + 1
Lbldisplay.Caption = sname
MSFlex1.Rows = MSFlex1.Rows + 1
MSFlex1.TextMatrix(rno, 0) = slno
MSFlex1.TextMatrix(rno, 1) = sname
MSFlex1.TextMatrix(rno, 2) = sprice
MSFlex1.TextMatrix(rno, 3) = Txtqty.Text
MSFlex1.TextMatrix(rno, 4) = Val(Txtqty.Text) * sprice
totalbill = totalbill + Val(MSFlex1.TextMatrix(rno, 4))
Textbill = totalbill
slno = slno + 1
rno = rno + 1
Txtqty = ""
End Sub
Private Sub Command2_Click()
MsgBox "totalbillamount is" + Textbill.Text
End
End Sub
Private Sub Form_Load()
rno = 1
slno = 1
MSFlex1.Cols = 5
MSFlex1.ColWidth(0) = 800
MSFlex1.ColWidth(1) = 3000
MSFlex1.ColWidth(2) = 1200
MSFlex1.ColWidth(3) = 1200
MSFlex1.ColWidth(4) = 1200
Optsnack1.Caption = "pepsi"
Optsnack2.Caption = "almond"
Optsnack3.Caption = "samosa"
Optsnack4.Caption = "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 Check1.Value = Checked Then
Text1.FontUnderline = True
ElseIf Check1.Value = Unchecked Then
Text1.FontUnderline = False
End If
End Sub
Private Sub Check2_Click()
If Check2.Value = Checked Then
Text1.FontStrikethru = True
ElseIf Check2.Value = Unchecked Then
Text1.FontStrikethru = False
End If
End Sub
Private Sub Combo1_Click()
Text1.FontSize = Combo1.Text
End Sub
Private Sub Combo2_Click()
If Combo2.Text = "red" Then
Text1.ForeColor = vbRed
ElseIf Combo2.Text = "blue" Then
Text1.ForeColor = vbBlue
ElseIf Combo2.Text = "green" Then
Text1.ForeColor = vbGreen
End If
End Sub
Private Sub Form_Load()
For i = 1 To 198
List1.AddItem Screen.Fonts(i)
Next i
Combo2.AddItem "red"
Combo2.AddItem "blue"
Combo2.AddItem "green"
Combo1.AddItem 10
Combo1.AddItem 14
Combo1.AddItem 18
Combo1.AddItem 24
Combo1.AddItem 28
End Sub
Private Sub List1_Click()
Text1.Font = List1.Text
End Sub
Private Sub Option1_Click()
If Option1.Value = True Then
Text1.FontBold = True
Text1.FontItalic = False
End If
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
Text1.FontBold = False
Text1.FontItalic = True
End If
End Sub
Private Sub Option3_Click()
If Option3.Value = True Then
Text1.FontBold = False
Text1.FontItalic = False
End If
End Sub
Private Sub Option4_Click()
If Option4.Value = True Then
Text1.FontBold = True
Text1.FontItalic = 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;
strMessage.Format(“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 marks.Validate the input data and calculate the
Percentage and division.

Dim sum As Integer


Dim avg As Integer
Private Sub Command1_Click()
sum = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)
average = sum / 3
Text4.Text = average
If average > 75 Then
Text5.Text = "a"
ElseIf average > 50 Then
Text5.Text = "b"
ElseIf average > 35 Then
Text5.Text = "c"
Else
Text5.Text = "d"
End If
End Sub
Private Sub Command2_Click()
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
Text5.Text = " "
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(Text1.Text, True)
Text1.Text = x
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
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(Text1.Text, False)
Text2.Text = 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 items.Use
ADO data controls and grid controls.

Private Sub Cmdadd_Click()


Dim id As Integer
On Error GoTo errmsg
Adodc1.Refresh
Adodc1.Recordset.MoveLast
id = Adodc1.Recordset("item_id") + 1
Adodc1.Recordset.AddNew
Text1.Text = id
Text2.SetFocus
Exit Sub
errmsg:
Adodc1.Recordset.AddNew
Text1.Text = 1
Text2.SetFocus
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
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
If adosc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
MsgBox "item deleted successfully"
End If
Exit Sub
errmsg:
MsgBox Err.Description
End Sub
Private Sub Cmdexit_Click()
End
End Sub
Private Sub cmdfirst_Click()
On Error GoTo errmsg
Adodc1.Recordset.MoveFirst
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdlast_Click()
On Error GoTo errmsg
Adodc1.Recordset.MoveLast
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdnext_Click()
On Error GoTo errmsg
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
MsgBox "reached last record'"
End If
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdprevious_Click()
On Error GoTo errmsg
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
MsgBox "reached first record"
End If
Exit Sub
errmsg:
MsgBox "item list is empty"
End Sub
Private Sub Cmdsave_Click()
On Error GoTo errmsg
Adodc1.Recordset.Update
MsgBox "record saved"
Exit Sub
errmsg:
MsgBox "err.description"
End Sub
Private Sub Cmdsearch_Click()
On eroor GoTo errmsg
Dim id1 As Integer
Adodc1.Refresh
id1 = InputBox("enter the item id", "item list is to be checked")
Adodc1.Recordset.Find "item_id=" & id1
If Adodc1.Recordset.EOF Then
MsgBox "item id does not found"
Exit Sub
End If
Exit Sub
errmsg:
MsgBox "err.descripition"
End Sub
Private Sub Cmdupdate_Click()
Text1.SetFocus
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()


Text1.ForeColor = RGB(HScroll1.Value, HScroll2.Value,
HScroll3.Value)
lblred.Caption = HScroll1.Value
End Sub
Private Sub HScroll2_Change()
Text1.ForeColor = RGB(HScroll1.Value, HScroll2.Value,
HScroll3.Value)
lblgreen.Caption = HScroll2.Value
End Sub
Private Sub HScroll3_Change()
Text1.ForeColor = RGB(HScroll1.Value, HScroll2.Value,
HScroll3.Value)
lblblue.Caption = HScroll3.Value
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(File1.Path, 1) = "\" Then
img1 = File1.Path + File1.FileName
Else
img1 = File1.Path + "\" + File1.FileName
End If
Label1.Caption = img1
Image1.Picture = LoadPicture(img1)
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Dim img1 As String
If Right(File1.Path, 1) = "\" Then
img1 = File1.Path + File1.FileName
Else
img1 = File1.Path + "\" + File1.FileName
End If
Label1.Caption = img1
Image1.Picture = 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);
s.Create(this);
indicators[0]=0;
indicators[1]=ID_INDICATOR_CAPS;
indicators[2]=ID_INDICATOR_NUM;
indicators[3]=ID_INDICATOR_SCRL;
s.SetIndicators(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;

Potrebbero piacerti anche