0% found this document useful (0 votes)
45 views

VB Lab Programs

The document provides an index of various VB programs with brief descriptions. It includes programs for simple arithmetic calculations, loops and decision making statements like the Fibonacci series, sum of numbers, and symbols in triangle format. Other programs cover creating menus and MDI forms, input screens for reading and writing files, using rich text boxes to create and edit files and directories, common dialog box controls, student and employee registration forms using data access and data controls, and animation using timers. For each item in the index, the document lists the title and page number for the corresponding program details.

Uploaded by

sridharan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

VB Lab Programs

The document provides an index of various VB programs with brief descriptions. It includes programs for simple arithmetic calculations, loops and decision making statements like the Fibonacci series, sum of numbers, and symbols in triangle format. Other programs cover creating menus and MDI forms, input screens for reading and writing files, using rich text boxes to create and edit files and directories, common dialog box controls, student and employee registration forms using data access and data controls, and animation using timers. For each item in the index, the document lists the title and page number for the corresponding program details.

Uploaded by

sridharan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

INDEX

S.NO Date Name of the Program Page No.

1 Simple Arithmetic calculator

Programs in Loops and Decision Making


Statements
2 a. Fibonacci Series
b. Sum of N Numbers
c. Symbols in Triangle Format

3 Creating Menu and MDI Forms

4 Creating input screens to read/write File

Creating, Editing Files and Directories using


5
Rich Textbox Control

6 Common Dialog box Control Usage

7 Student Registration Form Using Data Access

8 Employee Registration using ADODC

Personal Information System using Data


9
Controls

10 Animation Using Timers


SIMPLE ARITHMETIC CALCULATOR

FORM DESIGN:
SOURCE CODE:
Dim a As Integer
Dim s As Integer

Private Sub Command1_Click()


Frame1.Enabled = True
End Sub

Private Sub Command10_Click()


Text1.Text = Text1.Text + Command10.Caption
End Sub

Private Sub Command11_Click()


Text1.Text = Text1.Text + Command11.Caption
End Sub

Private Sub Command12_Click()


a = Val(Text1.Text)
Text1.Text = " "
s=3
End Sub

Private Sub Command13_Click()


a = Val(Text1.Text)
Text1.Text = " "
s=4
End Sub

Private Sub Command14_Click()


Text1.Text = Text1.Text + Command14.Caption
End Sub

Private Sub Command15_Click()


Text1.Text = Text1.Text + Command15.Caption
End Sub
Private Sub Command16_Click()
Text1 , Text = Text1.Text + Command16.Caption
End Sub

Private Sub Command17_Click()


Text1.Text = Val(Text1.Text) ^ 0.5
End Sub

Private Sub Command18_Click()


Text1.Text = Val(Text1.Text) * Val(Text1.Text)
End Sub

Private Sub Command19_Click()


Text1.Text = Text1.Text + Command19.Caption
End Sub

Private Sub Command2_Click()


Text1.Text = " "
End Sub

Private Sub Command20_Click()


Text1.Text = Text1.Text + Command20.Caption
End Sub

Private Sub Command21_Click()


Select Case s
Case 1
Text1.Text = a + Val(Text1.Text)
Case 2
Text1.Text = a - Val(Text1.Text)
Case 3
Text1.Text = a * Val(Text1.Text)
Case 4
Text1.Text = a / Val(Text1.Text)
Case 5
Text1.Text = a ^ Val(Text1.Text)
End Select
End Sub

Private Sub Command22_Click()


Text1.Text = Val(Text1.Text) * Val(Text1.Text) * Val(Text1.Text)
End Sub

Private Sub Command23_Click()


a = Val(Text1.Text)
s=5
Text1.Text = " "
End Sub

Private Sub Command24_Click()


End
End Sub

Private Sub Command3_Click()


Frame1.Enabled = False
End Sub

Private Sub Command4_Click()


Text1.Text = Text1.Text + Command4.Caption
End Sub

Private Sub Command5_Click()


Text1.Text = Text1.Text + Command5.Caption
End Sub

Private Sub Command6_Click()


Text1.Text = Text1.Text + Command6.Caption
End Sub
Private Sub Command7_Click()
a = Val(Text1.Text)
Text1.Text = " "
s=1
End Sub

Private Sub Command8_Click()


a = Val(Text1.Text)
Text1.Text = " "
s=2
End Sub

Private Sub Command9_Click()


Text1.Text = Text1.Text + Command9.Caption
End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)


Text1.Text -Text1.Enabled = False
Frame1.Enabled = False
End Sub
Output:
FIBONACCI SERIES
FORM DESIGN:
SOURCE CODE:

Private Sub Command1_Click()


Dim N, A, B, C As Integer
N = Val(Text1.Text)
A=0
B=1
Picture1.Cls
Picture1.Print A &Space(2);
Picture1.Print B &Space(2);
For I = 1 To N - 2
C=A+B
A=B
B=C

Picture1.Print C &Space(2);
Next I
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Picture1.Cls
End Sub

Private Sub Command3_Click()


Unload Me
End Sub
OUTPUT:
SUM OF THE SERIES

FORM DESIGN:
SOURCE CODE:

Private Sub Command1_Click()


Dim SUM As Integer
If Val(Me.Text1.Text) < 0 Then
MsgBox "INVALID INPUT!",vbCritical
Else
For I = 1 To Val(Me.Text1.Text) Step 1
SUM = SUM + I
Next I
Text2.Text = "SUM OF N NUMBERS FROM 1 TO "& Me.Text1.Text & " :" & SUM
End If
End Sub

Private Sub Command2_Click()


End
End Sub
OUTPUT:
SYMBOLS IN TRIANGLE SHAPE

FORM DESIGN:
SOURCE CODE:
Private Sub Command1_Click()
Dim N As Integer
Dim I As Integer
N = Val(InputBox("ENTER NO OF ROWS"))
For I = 1 To N
Picture1.Print Space(N - I) + String(I, "$")
Next I
End Sub

Private Sub Command2_Click()


End
End Sub
Output:
CREATING MENU’S AND MDI FORMS

FORM DESIGN:
SOURCE CODE:
Option Explicit
Private Sub mnubold_Click()
rtb.SelBold = True
End Sub

Private Sub mnucolor_Click()


cdb.ShowColor
rtb.SelColor = cdb.Color
End Sub

Private Sub mnuexit_Click()


End
End Sub

Private Sub mnufont_Click()


cdb.ShowFont
rtb.SelFontName = cdb.FontName
End Sub

Private Sub mnuitalic_Click()


rtb.SelItalic = True
End Sub

Private Sub mnuopen_Click()


cdb.ShowOpen
rtb.LoadFilecdb.FileName
End Sub

Private Sub mnusave_Click()


cdb.ShowSave
rtb.SaveFilecdb.FileName
End Sub
OUTPUT:
CREATING, EDITING FILES & DIRECTORY USING
RICH TEXT BOX CONTROL

FORM DESIGN:
SOURCE CODE:
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Dir1_Change()


File1.Path = Dir1.Path
End Sub
Private Sub cmdOpen_Click()
rtb.LoadFile File1.FileName
End Sub

Private Sub cmdEdit_Click()


cdb1.ShowColor
rtb.BackColor = cdb1.Color
cdb1.Flags = &H3 Or&H100
cdb1.ShowFont
rtb.SelBold = cdb1.FontBold
rtb.SelItalic = cdb1.FontItalic
rtb.SelStrikeThru = cdb1.FontStrikethru
rtb.SelUnderline = cdb1.FontUnderline
rtb.SelFontName = cdb1.FontName
rtb.SelFontSize = cdb1.FontSize
rtb.SelColor = cdb1.Color
End Sub

Private Sub cmdSave_Click(Index As Integer)


cdb1.ShowSave
rtb.SaveFile cdb1.FileName
End Sub

Private Sub cmdExit_Click(Index As Integer)


End
End Sub
OUTPUT:
USAGE OF COMMON DIALOG BOX CONTROLS

FORM DESIGN:
SOURCECODE:
Private Sub Open_Click()
CDB.ShowOpen
RTB.LoadFileCDB.FileName
End Sub

Private Sub Edit_Click()


CDB.ShowColor
RTB.BackColor = CDB.Color
CDB.Flags = &H3 Or&H100
CDB.ShowFont
RTB.SelBold = CDB.FontBold
RTB.SelItalic = CDB.FontItalic
RTB.SelStrikeThru = CDB.FontStrikethru
RTB.SelUnderline = CDB.FontUnderline
RTB.SelFontName = CDB.FontName
RTB.SelFontSize = CDB.FontSize
RTB.SelColor = CDB.Color
End Sub

Private Sub Save_Click()


CDB.ShowSave
RTB.SaveFileCDB.FileName
End Sub

Private Sub Clear_Click()


RTB = " "
End Sub
Private Sub Exit_Click()
End
End Sub
OUTPUT:
STUDENT REGISTRATION FORM USING DATA ACCESS

FORM DESIGN:

LOGIN FORM:
SOURCE CODE:
Private Sub Command1_Click()

Dim user As String

Dim pass As String

user = "ADMIN"

pass = "ADMIN"

If (user = username.TextAnd pass = password.Text) Then

register.Show

Else

MsgBox "invalid username or password", vbOKOnly, "login Failed"

End If

End Sub

Private Sub Command2_Click()

End

End Sub
REGISTRATION FORM:
SOURCE CODE:
Private Sub Command1_Click()

Adodc1.Recordset.Fields("ID") = Text1.Text

Adodc1.Recordset.Fields("Name") = Text2.Text

Adodc1.Recordset.Fields("Class") = Text3.Text

Adodc1.Recordset.Fields("Address") = Text4.Text

Adodc1.Recordset.Fields("Phone number") = Text5.Text

Adodc1.Recordset.Update

End Sub

Private Sub Command3_Click()

End

End Sub

Private Sub Form_Load()

Adodc1.Recordset.Update

Adodc1.Recordset.AddNew

End Sub
OUTPUT:
EMPLOYEE REGISTRATION USING ADODB

FORM DESIGN:
SOURCE CODE :

Dim con As New ADODB.Connection


Dim rec As New ADODB.Recordset

Private Sub cmdNEW_Click()


rec.AddNew
End Sub

Private Sub cmdADD_Click()


rec.Update
End Sub

Private Sub cmdEDIT_Click()


rec.Update
End Sub

Private Sub cmdDELETE_Click()


rec.Delete
End Sub

Private Sub cmdFIRST_Click()


rec.MoveFirst
End Sub

Private Sub cmdPREV_Click()


rec.MovePrevious
End Sub

Private Sub cmdNEXT_Click()


rec.MoveNext
End Sub

Private Sub cmdLAST_Click()


rec.MoveLast
End Sub
Private Sub cmdSEARCH_Click()
con.Close
con.Open "provider =microsoft.jet.OLEDB.4.0; data
source=C:\Users\SANTHOSH SANKAR\Documents\DATA.MDB;"
rec.CursorLocation = adUseClient
DataGrid1.Refresh
rec.Open "select * from table1 where ID like '%" & Text5.Text & "%'", con,
adOpenDynamic, adLockOptimistic
If rec.EOF Then
MsgBox "no record found"
Else
Set DataGrid1.DataSource = rec
End If
End Sub

Private Sub cmdEXIT_Click()


End
End Sub

Private Sub Form_Load()


Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
con.Open "provider =microsoft.jet.OLEDB.4.0; data
source=C:\Users\SANTHOSH SANKAR\Documents\DATA.MDB;"
rec.CursorLocation = adUseClient
rec.Open "select * from table1", con, adOpenDynamic, adLockOptimistic
Set Text1.DataSource = rec
Text1.DataField = "ID"
Set Text2.DataSource = rec
Text2.DataField = "NAME"
Set Text3.DataSource = rec
Text3.DataField = "POSITION"
Set Text4.DataSource = rec
Text4.DataField = "SALARY"
Set DataGrid1.DataSource = rec
End Sub
OUTPUT :
PERSONAL INFORMATION SYSTEM

FORM DESIGN:
SOURCE CODE:
Private Sub add_Click()
text1.SetFocus
Data1.Recordset.AddNew
End Sub
Private Sub delete_Click()
Data1.Recordset.delete
MsgBox "record deleted"
End Sub

Private Sub exit_Click()


End
End Sub

Private Sub first_Click()


Data1.Recordset.MoveFirst
End Sub

Private Sub last_Click()


Data1.Recordset.MoveLast
End Sub

Private Sub next_Click()


Data1.Recordset.MoveLast
End Sub

Private Sub previous_Click()


Data1.Recordset.MovePrevious
End Sub

Private Sub update_Click()


Data1.Recordset.update
MsgBox "record updated"
clear
End Sub
Private Sub clear()
text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
End Sub
OUTPUT:
ANIMATION USING TIMERS

FORM DESIGN
SOURCE CODE
Dim flag As Boolean
Private Sub cmdcontrol_Click()
If flag = False Then
flag = True
cmdcontrol.Caption = "stop"
Else
flag = False
cmdcontrol.Caption = "start"
End If
End Sub

Private Sub Form_Load()


cmdcontrol.Caption = "stop"
flag = True
End Sub

Private Sub Timer1_Timer()


If flag = True Then
Image1.Left = Image1.Left + 100
Label2.Left = Label2.Left + 100
End If
End Sub
OUTPUT:
SIMPLE INPUT SCREEN TO READ/ WRITE FILE

FORM DESIGN
SOURCE CODE

Private Sub cmdclear_Click()


Text1.Text = ""
rtb.Text = ""
End Sub

Private Sub cmdExit_Click(Index As Integer)


End
End Sub

Private Sub cmdRead_Click(Index As Integer)


cdb.ShowOpen
rtb.LoadFilecdb.FileName
End Sub

Private Sub cmdWrite_Click(Index As Integer)


Dim namefile
namefile = Text1
Open App.Path& ("/" + namefile + ".txt") For Output As #1
Write #1, rtb.Text
MsgBoxrtb.Text, vbDefaultButton1, " File READ/WRITE"
Close #1
End Sub
OUTPUT:

You might also like