Sunteți pe pagina 1din 76

Name-:Amol B Rukhe RollNo-338

Practical No. 1
Title: Creating Universal functions for validation purpose.

Create an application to understand preliminary use of objects.

1. To check whether the text box is empty.


2. To clear a text box.
3. To make the text box numeric.
4. To make the text box Alphabetic.
5. To Auto Increment a code number.
6. To convert the values inside the text box to Title Case.
7. To make the text box read only.
8. To make the text box normal.
9. To make the text box optional.
10. To enable and disable a frame.
11. To clear a combo box.
12. To check whether the combo box is empty.
13. To check if the email is valid.
14. To create text box for password, text box with fixed length.
15. To make the command button disabled.
16. To make the command button enabled
 What is validation? Explain the need of validation in VB Projects.
 What is Modular Programming? Explain its use.

Write the name of the controls, their properties used and the values set for each property in the
application in your answer sheet.

-1-
Name-:Amol B Rukhe RollNo-338

Practical No.1
Form 1 :

-2-
Name-:Amol B Rukhe RollNo-338

Practical No.1 :
Form 2 :

-3-
Name-:Amol B Rukhe RollNo-338

Practical No. 1
Form 1

Private Sub cmdclear_Click()


If ClearText(txtclear) = False Then Exit Sub
End Sub

Private Sub cmdfrm_Click()


Form2.Show
'Form1.Hide
Unload Me
End Sub

Private Sub cmdinc_Click()


Call AutoText(txtauto)
End Sub

Private Sub cmdn1_Click()


Call MakeNormal(txtro)
End Sub

Private Sub Form_Load()


Call MakeReadOnly(txtro)
Call BackC(txtopt)
End Sub

Private Sub txtauto_KeyPress(KeyAscii As Integer)


Call MakeNumeric(KeyAscii)
End Sub

Private Sub txtchar_KeyPress(KeyAscii As Integer)


Call MakeChar(KeyAscii)
End Sub

Private Sub txtemp_LostFocus()


If EmptyText(txtemp) = False Then Exit Sub
End Sub

Private Sub txtnum_KeyPress(KeyAscii As Integer)


Call MakeNumeric(KeyAscii)
End Sub

Private Sub txttitle_LostFocus()


Call Ucas(txttitle)
End Sub

-4-
Name-:Amol B Rukhe RollNo-338

Practical No. 1
Form 2

Private Sub cmdbdisa_Click()


Call makeBD(cmdbutton)
End Sub

Private Sub cmdbena_Click()


Call makeBE(cmdbutton)
End Sub

Private Sub cmdcmb_Click()


Call Clear(Combo1)
End Sub

Private Sub cmdempty_Click()


Call cmbempty(Combo1)
End Sub

Private Sub cmdfdisa_Click()


Call MakeFrameD(Fra2)
End Sub

Private Sub cmdfena_Click()


Call MakeFrameE(Fra2)
End Sub

Private Sub Form_Load()


Call makepassword(txtpw)
End Sub

Private Sub txtemail_LostFocus()


Call E_Mail(txtemail)
End Sub

-5-
Name-:Amol B Rukhe RollNo-338

Practical No. 1
Module

Public Function EmptyText(txtname As TextBox)


If Trim(txtname.Text) = "" Then
MsgBox txtname.Tag & " CAN NOT BE EMPTY"
EmptyText = False
txtname.SetFocus
End If
EmptyText = True
End Function

Public Function ClearText(txtname As TextBox)


txtname.Text = ""
End Function

Public Function MakeNumeric(KeyAscii As Integer)


Dim str As String
str = "0123456789"
If InStr(str, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Function

Public Function MakeChar(KeyAscii As Integer)


If Chr(KeyAscii) Like "[A-Za-z]" Or KeyAscii = 32 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Function

Public Function AutoText(txtname As TextBox)


txtname.Text = Val(txtname.Text) + 1

End Function

Public Function MakeReadOnly(txtname As TextBox)


txtname.Locked = True
txtname.Appearance = 0
txtname.ForeColor = vbGray
End Function

Public Function MakeNormal(txtname As TextBox)


txtname.Locked = False
txtname.Appearance = 1

-6-
Name-:Amol B Rukhe RollNo-338

Practical No. 1
Module

txtname.ForeColor = vbBlack
txtname.BackColor = vbWhite
End Function

Public Function Ucas(txtname As TextBox)


Dim str As String
str = UCase(Left(txtname.Text, 1))
If txtname.Text <> "" Then
txtname.Text = str + Right(txtname.Text, Len(txtname.Text) - 1)
End If
End Function

Public Function BackC(txtname As TextBox)


txtname.BackColor = 150
End Function

Public Function makepassword(txtname As TextBox)


txtname.MaxLength = 8
txtname.PasswordChar = "*"
End Function

Public Function MakeFrameE(Frame1 As Frame)


Frame1.Enabled = True
End Function

Public Function MakeFrameD(Frame1 As Frame)


Frame1.Enabled = False
End Function

Public Function makeBE(button1 As CommandButton)


button1.Enabled = True
End Function

Public Function makeBD(button1 As CommandButton)


button1.Enabled = False
End Function

Public Function E_Mail(txtname As TextBox)


Dim placerate As Integer
Dim placedot As Integer
'check for "."
If InStr(txtname, ".") = 0 Then
MsgBox "INVALID E-MAIL ADDRESS1"

-7-
Name-:Amol B Rukhe RollNo-338

Practical No. 1
Module

txtname.Text = ""
txtname.SetFocus
Exit Function
End If

If InStr(txtname, ".") = 1 Then


MsgBox "INVALID E-MAIL ADDRESS2"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If

'check for "@"


If InStr(txtname, "@") = 0 Then
MsgBox "INVALID E-MAIL ADDRESS3"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If
If InStr(txtname, "@") = 1 Then
MsgBox "INVALID E-MAIL ADDRESS4"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If
placerate = InStr(txtname, "@")
placedot = InStr(txtname, ".")

'check for "@@"


If InStr(placerate + 1, txtname.Text, "@") <> 0 Then
MsgBox "INVALID E-MAIL ADDRESS 5"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If
'check for "@."
If InStr(placerate + 1, txtname.Text, ".") = 0 Then
MsgBox "INVALID E-MAIL ADDRESS 6"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If

-8-
Name-:Amol B Rukhe RollNo-338

Practical No. 1
Module

'check for ".@"


If InStr(placerate + 1, txtname.Text, "@") <> 0 Then
MsgBox "INVALID E-MAIL ADDRESS 7"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If

'check for ".."


If InStr(placedot + 1, txtname.Text, ".") <> 0 Then
MsgBox "INVALID E-MAIL ADDRESS 8"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If

'check for @ at the end


If Right(txtname, 1) = "@" Then
MsgBox "INVALID EMAIL ADDRESSS 9"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If

'check for "." at the end


If Right(txtname, 1) = "." Then
MsgBox "INVALID EMAIL ADDRESSS 10"
txtname.Text = ""
txtname.SetFocus
Exit Function
End If
End Function

Public Function Clear(cmbname As ComboBox)


cmbname.Text = ""
End Function

Public Function cmbempty(cmbname As ComboBox)


cmbname.Clear
End Function

-9-
Name-:Amol B Rukhe RollNo-338

Practical No. 2
Title: Creating and Handling multiple forms.

Create a project that will produce a summary of amounts due for John's Auto
Repair Shop. Display a splash screen first; then display the main form.

The main form menu is


File Process Help
Exit Job Information About

On click of Job Information menu item “Job Information Form” should be displayed. “Job
Information form” must have textboxes for a user to enter the job number, customer name,
amount charged for parts and hours of labour. Include labels for sub total, sales tax and total.

Form has three command buttons for Calculate, Clear and Ok. Calculate
button finds the charges and displays them in label. The tax rate and the
hourly labour charge should be declared as named constants so that they can
be easily modified if either changes. Current charges are Rs. 30 per hour for
labour and 8 percent for the sales tax rate. Sales tax is charged only on parts,
not on labour.

The Clear button clears the text boxes and labels and resets the focus in the
first textbox.
The Ok button hides the job information form and displays the main form.

On click of “About” item, About form should be displayed. About form should have the program
name, programmer’s seat number, version number, a logo/ Small image and Ok button.

Write the name of the controls, their properties used and the values set for each property in the
application in your answer sheet.

- 10 -
Name-:Amol B Rukhe RollNo-338

Practical No.2
Form 1 :

- 11 -
Name-:Amol B Rukhe RollNo-338

Practical No.2
Splash Screen

- 12 -
Name-:Amol B Rukhe RollNo-338

Practical No.2
Form 1 :

Dim stotal As Double


Dim charge As Double
Dim labour As Double
Dim tax As Double
Dim total As Double

Private Sub cmdcal_Click()


labour = 30
stotal = Val(txtamt.Text) + (Val(txthrs.Text) * labour)
tax = Val(txtamt.Text) * 0.08
total = stotal + tax
lblsalestax.Caption = tax
lblsubtotal.Caption = stotal
lbltotal1.Caption = total
End Sub

Private Sub cmdclear_Click()


txtamt.Text = ""
txthrs.Text = ""
txtname.Text = ""
txtno.Text = ""
lblsalestax.Caption = ""
lblsubtotal.Caption = ""
lbltotal1.Caption = ""
End Sub

Private Sub cmdOK_Click()


End
End Sub

- 13 -
Name-:Amol B Rukhe RollNo-338

Practical No.2
MDIForm :

Private Sub mnuabt_Click()


frmAbout.Visible = True
End Sub

Private Sub mnuexit_Click()


End
End Sub

Private Sub mnujob_Click()


Frmjobinfo.Show
End Sub

Splash Screen :

Option Explicit

Private Sub Form_KeyPress(KeyAscii As Integer)


Unload Me
End Sub

Private Sub Form_Load()


lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
lblProductName.Caption = App.Title
End Sub

Private Sub Frame1_Click()


Unload Me
MDIForm1.Show
End Sub

- 14 -
Name-:Amol B Rukhe RollNo-338

Practical No. 3
Title: To Manipulate the Access database using VB ADODC

Create a database file “library” in Microsoft Access. The structure of table “Books” is as follows:
Fields Data types
ISBN Text
Title Text
Author Text
Publisher Text
Subject_code Text
Shelf Text
Fiction Yes/No
Step 1. Create a new form large enough to hold the controls.
Step 2. Click on data control tool and draw a data control along the bottom of the form.
Step 3 Create a large frame to hold the labels and text boxes then delete the frame’s caption
property.
Step 4. Create text boxes for ISBN, title, authors & publishers.
Step 5 Create combo boxes for subject code and shelf and Checkbox for fiction.
Step 6. Add following elements to the list property of subject_code.(ctrl + enter after each)
List: BSS, FNT, RLG, RMN, HMR, SCF, SLH, BSF, PHL, EDC, MST, BSN
Step 7 Add the following elements to the list property of shelf. (ctrl+enter after each)List:
RC1111, RC1112, RC1113.
Step 8 Add buttons for add, delete and navigating the records.
Step 9. The errors can be minimized by limiting user
actions.
E.g. when the user clicks on the add button several actions should occur.
i. An AddNew method clears the bound control to await entry of new data.
ii. The focus is set in the first text box.
iii. The navigation button and delete buttons are disabled.
iv. The save button enabled.
v. The caption of add button changes to cancel, which gives user only two
choices save and cancel.
Step 10. Use error handlers for some other errors.
Write the name of the controls, their properties used and the values set for each property in your
answer sheet.

Practical No.3

- 15 -
Name-:Amol B Rukhe RollNo-338

Form Design 1 :

Practical No.3

- 16 -
Name-:Amol B Rukhe RollNo-338

Form 1

Private Sub cmdadd_Click()


If cmdadd.Caption = "ADD" Then
fra1.Enabled = True
cmdadd.Caption = "SAVE"
txtisbn.SetFocus
Adodc1.Recordset.AddNew
Call disablebutton1(True, False, True, True)
Call disablebutton2(False, False, False, False)
Else
If cmdadd.Caption = "SAVE" Then
Adodc1.Recordset.Update
Call disablebutton1(True, True, True, True)
Call disablebutton2(True, True, True, True)
cmdadd.Caption = "ADD"
End If
End If
End Sub

Private Sub cmdcan_Click()


txtauthor.Text = ""
txtisbn.Text = ""
txtpub.Text = ""
txttitle.Text = ""
End Sub

Private Sub cmddel_Click()


Adodc1.Recordset.Delete
MsgBox "RECORD HAS BEEN DELETED"
Adodc1.Recordset.MoveFirst
End Sub

Private Sub cmdexit_Click()


End
End Sub

Private Sub cmdfirst_Click()


Adodc1.Recordset.MoveFirst
End Sub

Private Sub cmdlast_Click()


Adodc1.Recordset.MoveLast
End Sub

Practical No.3

- 17 -
Name-:Amol B Rukhe RollNo-338

Form 1

Private Sub cmdnext_Click()


'Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveFirst
Else
Adodc1.Recordset.MoveNext
End If
End Sub

Private Sub cmdpre_Click()


'Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveLast
Else
Adodc1.Recordset.MovePrevious
End If
End Sub

Private Sub Form_Load()


fra1.Enabled = False
txtauthor.Text = ""
txtisbn.Text = ""
txtpub.Text = ""
txttitle.Text = ""
cboshelf.Text = ""
cbosub.Text = ""
Adodc1.Refresh
End Sub

Private Sub txtauthor_LostFocus()


Call Ucas(txtauthor)
End Sub

Private Sub txtisbn_LostFocus()


If EmptyText(txtisbn) = False Then Exit Sub
End Sub

Practical No.3

- 18 -
Name-:Amol B Rukhe RollNo-338

Form 1

Private Sub txtpub_KeyPress(KeyAscii As Integer)


Call MakeChar(KeyAscii)
End Sub

Private Sub txttitle_KeyPress(KeyAscii As Integer)


Call MakeChar(KeyAscii)
End Sub

Private Sub txttitle_LostFocus()


Call Ucas(txttitle)
End Sub

Practical No.3

- 19 -
Name-:Amol B Rukhe RollNo-338

Module1

Public Function EmptyText(txtname As TextBox)


If Trim(txtname.Text) = "" Then
MsgBox txtname.Tag & " CAN NOT BE EMPTY"
EmptyText = False
txtname.SetFocus
End If
EmptyText = True
End Function

Public Function MakeNumeric(KeyAscii As Integer)


Dim str As String
str = "0123456789"
If InStr(str, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Function

Public Function MakeChar(KeyAscii As Integer)


If Chr(KeyAscii) Like "[A-Za-z]" Or KeyAscii = 32 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Function

Public Function AutoText(txtname As TextBox)


txtname.Text = Val(txtname.Text) + 1
End Function

Public Function Ucas(txtname As TextBox)


Dim str As String
str = UCase(Left(txtname.Text, 1))
If txtname.Text <> "" Then
txtname.Text = str + Right(txtname.Text, Len(txtname.Text) - 1)
End If
End Function

Public Function disablebutton1(badd As Boolean, bdel As Boolean, bcan As Boolean, bexit As


Boolean)
Form1.cmdadd.Enabled = badd
Form1.cmddel.Enabled = bdel
Form1.cmdcan.Enabled = bcan
Form1.cmdexit.Enabled = bexit

Practical No.3

- 20 -
Name-:Amol B Rukhe RollNo-338

Module1

End Function

Public Sub disablebutton2(bfirst As Boolean, blast As Boolean, bnext As Boolean, bpre As


Boolean)
Form1.cmdfirst.Enabled = bfirst
Form1.cmdlast.Enabled = blast
Form1.cmdnext.Enabled = bnext
Form1.cmdpre.Enabled = bpre
End Sub

- 21 -
Name-:Amol B Rukhe RollNo-338

Practical No. 4
Title: To Manipulate the Oracle database using VB ADODB

Design a code to make table “Animal“ in Oracle with the help of ADODB object.

The fields in the table are:

• Animal_id varchar2(6)Primary Key


• Name varchar2(15)
• Height number(5,2)
• Weight number(5,2)
• Age number(3)
• Color varchar2(10)
• Texture varchar2(10)

Modify the above program to provide facility to (Use ADODB Command Object)
• Add a record
• Modify a record
• Delete a record

To the existing program, add five buttons to provide the facility of (Use ADODB Recordset
Object)
• Move to next record
• Move to previous record
• Move to first record
• Move to last record
• Query
o Enter the name to get the corresponding details.

Also add the following validation

• The name can contain only alphabets


• The code has to be of the format ‘TGR001’. That is
o Three character code (first three characters of name)
o Last three characters should indicate the number of species.
o It should be auto incremented.(do not allow user to change).
• The field name should not be left blank.

Write the name of the controls, their properties used and the values set for each property in your
answer sheet.

- 22 -
Name-:Amol B Rukhe RollNo-338

Practical No. 4
Form 1 :

- 23 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Form1 :

Dim con As New ADODB.Connection


Dim rs As New ADODB.Recordset
Dim rsnav As New ADODB.Recordset
Dim id As String
Private Sub cmdadd_Click()
If cmdadd.Caption = "ADD" Then
cmdadd.Caption = "SAVE"
ClearAll
txtname.SetFocus
Call disablebutton1(True, False, False, False, True)
Call disablebutton2(False, False, False, False, False)
Else
If rs.State = 1 Then rs.Close
id = Left(txtname.Text, 3)
rs.Open "select count (*) as sid from animal1 where name like '" & id & "'", con,
adOpenDynamic, adLockOptimistic
If rs.EOF = False Then
id = id + (CStr(Right("000" + CStr(rs!sid + 1), 3)))
Else
id = id + "001"
End If
rs.Close
txtanimalid.Text = id
If rs.State = adStateOpen Then rs.Close
rs.Open "select * from animal1", con, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!Animal_id = txtanimalid.Text
rs!Name = txtname.Text
rs!Height = txtheight.Text
rs!Weight = txtweight.Text
rs!AGE = txtage.Text
rs!Color = txtcolor.Text
rs!Texture = txttexture.Text
rs.Update
MsgBox "RECORD ENTERED"
rs.Close
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
cmdadd.Caption = "ADD"
End If
End Sub

- 24 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Form1 :

Private Sub cmdcancel_Click()


ClearAll
cmdadd.Caption = "ADD"
cmdmodify.Caption = "MODIFY"
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
End Sub

Private Sub cmddel_Click()


rsnav.Delete
ClearAll
MsgBox "RECORD DELETED"
End Sub

Private Sub cmdexit_Click()


End
End Sub

Private Sub cmdfirst_Click()


rsnav.MoveFirst
Display
End Sub

Private Sub cmdlast_Click()


rsnav.MoveLast
Display

End Sub

Private Sub cmdmodify_Click()


If cmdmodify.Caption = "MODIFY" Then
cmdmodify.Caption = "UPDATE"
Call disablebutton1(False, False, True, False, True)
Call disablebutton2(False, False, False, False, False)
If rs.State = adStateOpen Then rs.Close

rs.Open "Select * from ANIMAL1 where ANIMAL_ID = '" & txtanimalid.Text & "'", con,
adOpenDynamic, adLockOptimistic
Else
rs!Animal_id = txtanimalid.Text
rs!Name = txtname.Text
rs!Height = txtheight.Text
rs!Weight = txtweight.Text

- 25 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Form1 :

rs!AGE = txtage.Text
rs!Color = txtcolor.Text
rs!Texture = txttexture.Text
rs.Update
MsgBox "RECORD ENTERED"
rs.Close
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
cmdmodify.Caption = "MODIFY"
End If
End Sub

Private Sub cmdnext_Click()


rsnav.MoveNext
Display
End Sub

Private Sub cmdprevious_Click()


rsnav.MovePrevious
Display
End Sub

Private Sub cmdsearch_Click()


Dim search As String
search = InputBox("ENTER ANIMAL ID")
If rs.State = 1 Then rs.Close
rs.Open "Select * from ANIMAL1 where ANIMAL_ID='" & search & "'", con,
adOpenDynamic, adLockOptimistic
If rs.EOF = True Then
MsgBox "ENTRY DOES NOT EXIST"
Else
txtanimalid = rs(0).Value
txtname = rs(1).Value
txtheight = rs(2).Value
txtweight = rs(3).Value
txtage = rs(4).Value
txtcolor = rs(5).Value
txttexture = rs(6).Value

End If

End Sub

- 26 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Form1 :

Private Sub Form_Load()

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.ConnectionString = "Data Source=D:\Documents and
Settings\Administrator\Desktop\Tybsc2008\VISUAL BASIC\pract4\animal.mdb"
con.Open
If con.State = adStateOpen Then
MsgBox "CONNECTION ESTABLISHED"
End If
rsnav.Open "select * from ANIMAL1", con, adOpenDynamic, adLockOptimistic
Display

End Sub
Public Sub Display()

If rsnav.BOF = True Then


rsnav.MoveFirst
MsgBox "This is first record"
Else
If rsnav.EOF = True Then
rsnav.MoveLast
MsgBox "This is last record"
End If
End If
txtanimalid = rsnav(0).Value
txtname = rsnav(1).Value
txtheight = rsnav(2).Value
txtweight = rsnav(3).Value
txtage = rsnav(4).Value
txtcolor = rsnav(5).Value
txttexture = rsnav(6).Value

End Sub

Private Sub txtage_KeyPress(KeyAscii As Integer)


Call MakeNumeric(KeyAscii)
End Sub

Private Sub txtanimalid_LostFocus()

Call Ucas(txtanimalid)

End Sub

- 27 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Form1 :

Private Sub txtcolor_KeyPress(KeyAscii As Integer)


Call MakeChar(KeyAscii)
End Sub

Private Sub txtheight_KeyPress(KeyAscii As Integer)


Call MakeNumeric(KeyAscii)
End Sub

Private Sub txtname_KeyPress(KeyAscii As Integer)


Call MakeChar(KeyAscii)
End Sub

Private Sub txtname_LostFocus()


Call Ucas(txtname)
End Sub

Private Sub txttexture_KeyPress(KeyAscii As Integer)


Call MakeChar(KeyAscii)
End Sub

Private Sub txttexture_LostFocus()


Call Ucas(txttexture)
End Sub

Public Function ClearAll()


Call ClearText(txtage)
Call ClearText(txtanimalid)
Call ClearText(txtcolor)
Call ClearText(txtname)
Call ClearText(txtheight)
Call ClearText(txttexture)
Call ClearText(txtweight)
End Function

- 28 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Module1 :

Dim con As New ADODB.Connection


Dim rs As New ADODB.Recordset
Dim rsnav As New ADODB.Recordset
Dim id As String

Public Function EmptyText(txtname As TextBox)


If Trim(txtname.Text) = "" Then
MsgBox txtname.Tag & " CAN NOT BE EMPTY"
EmptyText = False
txtname.SetFocus
End If
EmptyText = True
End Function

Public Function ClearText(txtname As TextBox)


txtname.Text = ""
End Function

Public Function MakeNumeric(KeyAscii As Integer)


Dim str As String
str = "0123456789"
If InStr(str, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Function

Public Function MakeChar(KeyAscii As Integer)


If Chr(KeyAscii) Like "[A-Za-z]" Or KeyAscii = 32 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Function

Public Function AutoText(txtname As TextBox)


txtname.Text = Val(txtname.Text) + 1
End Function

Public Function Ucas(txtname As TextBox)


Dim str As String
str = UCase(Left(txtname.Text, 1))
If txtname.Text <> "" Then
txtname.Text = str + Right(txtname.Text, Len(txtname.Text) - 1)
End If

- 29 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 4
Module1 :

End Function

Public Function disablebutton1(badd As Boolean, bdel As Boolean, bmod As Boolean, bsearch


As Boolean, bcan As Boolean)
Frmanimal.cmdadd.Enabled = badd
Frmanimal.cmddel.Enabled = bdel
Frmanimal.cmdmodify.Enabled = bmod
Frmanimal.cmdsearch.Enabled = bsearch
Frmanimal.cmdcancel.Enabled = bcan
End Function

Public Sub disablebutton2(bfirst As Boolean, bnext As Boolean, bpre As Boolean, blast As


Boolean, bexit As Boolean)
Frmanimal.cmdfirst.Enabled = bfirst
Frmanimal.cmdnext.Enabled = bnext
Frmanimal.cmdprevious.Enabled = bpre
Frmanimal.cmdlast.Enabled = blast
Frmanimal.cmdexit.Enabled = bexit
End Sub

- 30 -
Name-:Amol B Rukhe RollNo-338

Practical No. 5
Title: Creating and modifying text files from VB.

Create a Mini Notepad. Display a main screen with following menus.


File Edit Help
New Cut About
Open Copy
Save Paste
Exit Set Font

In the File menu, on click of “New” menu-item textbox should be cleared, “Open” menu-item
should display an open dialog box and user should select a.txt file to display its contents in a
textbox, “Save” menu-item saves the contents of the textbox in the file and “Exit” menu-item
stops the application.

In the Edit menu, on click of “Cut” menu item the selected text from the textbox should be cut,
“Copy” menu-item copies the selected contents, “Paste” menu-item pastes the selected contents
at the cursor position, “Set Font” menu-item will open a font dialog box, the user will select a
font from that font dialog box and then that font should be applied to the whole text.

About form should have the program name, programmer’s seat number, version number and a
logo/Small image and Ok button.

Write the name of the controls, their properties used and the values set for each property in the
application in your answer sheet.

- 31 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 5
Form1 :

- 32 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 5
Form1 :

Dim ans As String


Dim str As String
Dim strleft As String
Dim strright As String

Private Sub Form_Resize()


rtbmain.Height = frmNotepad.Height - 750
rtbmain.Width = frmNotepad.Width - 500
End Sub

Private Sub mnuabout_Click()


frmAbout.Show
End Sub

Private Sub mnucopy_Click()


str = rtbmain.SelText
End Sub

Private Sub mnucut_Click()


str = rtbmain.SelText
rtbmain.SelText = ""
End Sub

Private Sub mnuexit_Click()


End
End Sub

Private Sub mnunew_Click()


If rtbmain = "" Then
rtbmain.Text = ""
Else
ans = MsgBox("DO YOU WNAT TO SAVE IT???", vbYesNoCancel)
If ans = vbYes Then
rtbmain.SaveFile (CommonDialog1.FileName)
CommonDialog1.ShowSave
Else
If ans = vbCancel Then
rtbmain.Text = ""
If ans = vbNo Then
End
End If
End If
End If

- 33 -
Name-:Amol B Rukhe RollNo-338

Practical No. : 5
Form1 :

End If
End Sub

Private Sub mnuopen_Click()


CommonDialog1.ShowOpen
rtbmain.LoadFile (CommonDialog1.FileName)
End Sub

Private Sub mnupaste_Click()


strleft = Left(rtbmain.Text, rtbmain.SelStart)
MsgBox rtbmain.SelStart
strright = Right(rtbmain.Text, Len(rtbmain.Text) - rtbmain.SelStart)
MsgBox Len(rtbmain.Text)
MsgBox rtbmain.SelStart
rtbmain.Text = strleft & str & strright

End Sub

Private Sub mnusave_Click()


CommonDialog1.ShowSave
rtbmain.SaveFile (CommonDialog1.FileName)
End Sub

Private Sub mnuset_Click()


CommonDialog1.ShowFont
rtbmain.Font.Name = CommonDialog1.FontName
rtbmain.Font.Size = CommonDialog1.FontSize
rtbmain.Font.Bold = CommonDialog1.FontBold
rtbmain.Font.Italic = CommonDialog1.FontItalic
rtbmain.Font.Strikethrough = CommonDialog1.FontStrikethru
End Sub

- 34 -
Name-:Amol B Rukhe RollNo-338

Practical No. 6
Title: Creating and handling Multiple Document Interface Forms

Create a database in Oracle, which holds following tables.


Dept (Deptno, Dname, Loc)
Emp (Empno, Ename, Salary, Job, Deptno)
Create a MDI project, which uses the above tables. The main menu is as follows Generate any
three reports from the given

Data Entry Reports


Employee entry Department wise employee report
Department entry Employee report based on salary range.
Exit Job wise
Department wise Salary report
Job wise maximum salary report.
Employee’s service report (Up till today’s date)

Both data entry screen should contain Add, Update, and Delete command buttons to add a new
record, to modify a record & to delete a record from the database respectively. The same screen
is used for the viewing the data. Add appropriate navigation option on the form.

Write the name of the controls, their properties used and the values set for each property in your
answer sheet.

- 35 -
Name-:Amol B Rukhe RollNo-338

Practical No. 6
Form1

- 36 -
Name-:Amol B Rukhe RollNo-338

Practical No. 6
Form2

- 37 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Crystal Report: Department Wise Employee Report

- 38 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Crystal Report: Employee Report Based On Salary Range

- 39 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Crystal Report: Job Wise

- 40 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Crystal Report: Department Wise salary Report

- 41 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Crystal Report: Job Wise Maximum Salary Report

- 42 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Crystal Report: Employee’s Service Report

- 43 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 1

Dim rsemp As New ADODB.Recordset


Dim tname As String
Dim tname2 As String
Dim tidname As String
Dim tidvalue As String
Dim tvalue As Collection

Public Function ClearAll()


Call ClearText(txtempno)
Call ClearText(txtename)
Call ClearText(txtjob)
Call ClearText(txtsal)
cmbDeptNo.Text = ""
End Function

Public Function modifyvalue(ttname As String, ttidname As String, ttidvalue As String, ttvalue


As Collection)
If rs.State = adStateOpen Then rs.Close
rs.Open "Select * from " & ttname & " where " & ttidname & " = " & tidvalue & "", con,
adOpenDynamic, adLockOptimistic
For i = 1 To ttvalue.Count
j=i-1
rs.Fields(j) = ttvalue.Item(i)
Next i
rs.Update
End Function

Private Sub cmdadd_Click()


Set tvalue = New Collection
If cmdadd.Caption = "ADD" Then
Fraemp.Enabled = True
cmdadd.Caption = "SAVE"
txtempno.SetFocus
ClearAll
txtempno.SetFocus
Call disablebutton3(True, False, False, False, True)
Call disablebutton4(False, False, False, False, True)
Else
If cmdadd.Caption = "SAVE" Then
If txtempno.Text = "" Or txtename.Text = "" Or txtjob.Text = "" Or txtsal.Text = "" Then
MsgBox "textbox cannot be empty, select a record with navigation button"
cmdadd.Caption = "ADD"
Fraemp.Enabled = False

- 44 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 1

Call disablebutton3(True, True, True, True, True)


Call disablebutton4(True, True, True, True, True)
Exit Sub
End If
tvalue.Add Val(txtempno.Text)
tvalue.Add CStr(txtename.Text)
tvalue.Add Val(txtsal.Text)
tvalue.Add CStr(txtjob.Text)
tvalue.Add Val(cmbDeptNo.Text)
tname = "Emp"
'start check for duplicate primary key
If rs.State = adStateOpen Then rs.Close
rs.Open "select * from " & tname, con, adOpenDynamic, adLockOptimistic
While rs.EOF = False
If rs.Fields(0).Value = txtempno.Text Then
MsgBox "This record no is repeated , Please Enter Again ", vbInformation + vbOKOnly,
"Information"
cmdadd.Caption = "ADD"
Fraemp.Enabled = False
Call disablebutton3(True, True, True, True, True)
Call disablebutton4(True, True, True, True, True)
ClearAll
Exit Sub
End If
rs.MoveNext
Wend
rs.Close
Call addvalue(CStr(tname), tvalue)
MsgBox "RECORD ENTERED"
Fraemp.Enabled = False
cmdadd.Caption = "ADD"
Call disablebutton3(True, True, True, True, True)
Call disablebutton4(True, True, True, True, True)
End If
End If
End Sub

Private Sub cmdcan_Click()


Fraemp.Enabled = False
cmdadd.Caption = "ADD"
cmdmodify.Caption = "MODIFY"
Call disablebutton3(True, True, True, True, True)
Call disablebutton4(True, True, True, True, True)

- 45 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 1

ClearAll
End Sub

Private Sub cmddel_Click()


If txtempno.Text = "" And txtename.Text = "" And txtjob.Text = "" And txtsal.Text = "" Then
MsgBox "textbox cannot be empty, select a record with navigation button"
Exit Sub
Fraemp.Enabled = False
Call disablebutton3(True, True, True, True, True)
Call disablebutton4(True, True, True, True, True)
Else
rsemp.Delete
ClearAll
MsgBox "RECORD DELETED"
End If
End Sub

Private Sub cmdexit_Click()


Unload Me
MDIForm1.Show
End Sub

Private Sub cmdfirst_Click()


rsemp.MoveFirst
Display
End Sub

Private Sub cmdlast_Click()


rsemp.MoveLast
Display
End Sub

Private Sub cmdmodify_Click()


Set tvalue = New Collection
If cmdmodify.Caption = "MODIFY" Then
cmdmodify.Caption = "UPDATE"
tname = "Emp"
tidname = "EmpNo"
tidvalue = txtempno.Text
Fraemp.Enabled = True
Call disablebutton3(False, False, True, False, True)
Call disablebutton4(False, False, False, False, True)
Else

- 46 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 1

If txtempno.Text = "" Or txtename.Text = "" Or txtjob.Text = "" Or txtsal.Text = "" Or


cmbDeptNo.Text = "" Then
MsgBox "textbox cannot be empty, select a record with navigation button"
cmdmodify.Caption = "MODIFY"
Fraemp.Enabled = False
Call disablebutton3(True, True, True, True, True)
Call disablebutton4(True, True, True, True, True)
Exit Sub
End If
tvalue.Add Val(txtempno.Text)
tvalue.Add CStr(txtename.Text)
tvalue.Add CStr(txtsal.Text)
tvalue.Add CStr(txtjob.Text)
Call modifyvalue(CStr(tname), CStr(tidname), CStr(tidvalue), tvalue)
cmdmodify.Caption = "MODIFY"
MsgBox "RECORD UPDATED"
Fraemp.Enabled = False
Call disablebutton3(True, True, True, True, True)
Call disablebutton4(True, True, True, True, True)
End If
End Sub

Private Sub cmdnext_Click()


rsemp.MoveNext
Display
End Sub

Private Sub cmdpre_Click()


rsemp.MovePrevious
Display
End Sub

Public Sub Display()


If rsemp.BOF = True Then
rsemp.MoveFirst
MsgBox "This is first record"
Else
If rsemp.EOF = True Then
rsemp.MoveLast
MsgBox "This is last record"
End If
End If
txtempno = rsemp(0).Value

- 47 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 1

txtename = rsemp(1).Value
txtsal = rsemp(2).Value
txtjob = rsemp(3).Value
cmbDeptNo = rsemp(4).Value
End Sub

Private Sub cmdRange_Click()


If txtRan.Text = "" Or txtRan1.Text = "" Then
MsgBox "Please Enter Values"
Else
CrystalReportS.ReplaceSelectionFormula "{Emp.Salary}>" & (txtRan) & " and {Emp.Salary}<"
& (txtRan1) & ""
CrystalReportS.RetrieveDataFiles
CrystalReportS.Action = 1
End If
End Sub

Private Sub cmdsearch_Click()


Dim search As String
search = InputBox("ENTER EMPLOYEE NUMBER :")
If rs.State = 1 Then rs.Close
rs.Open "Select * from Emp where EmpNo=" & Val(search) & "", con, adOpenDynamic,
adLockOptimistic
If rs.EOF = True Then
MsgBox "ENTRY DOES NOT EXIST"
Else
txtempno = rs(0).Value
txtename = rs(1).Value
txtsal = rs(2).Value
txtjob = rs(3).Value
cmbDeptNo.Text = rs(4).Value
End If
End Sub

Private Sub Form_Load()


Fraemp.Enabled = False
If rsemp.State = 1 Then rsemp.Close
rsemp.Open "select * from Emp", con, adOpenDynamic, adLockOptimistic
Display
If rs.State = 1 Then rs.Close
rs.Open "select * from dept", con, adOpenDynamic, adLockOptimistic
While rs.EOF = False
cmbDeptNo.AddItem (rs.Fields(0).Value)

- 48 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 1

rs.MoveNext
Wend
rs.Close
Fill_EmpNo_List
End Sub

Private Sub Fill_EmpNo_List()


If rs.State = 1 Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "select * from Emp", con
cmbEmpNo.Clear
If rs.RecordCount <> 0 Then
For i = 1 To rs.RecordCount
cmbEmpNo.AddItem rs.Fields("EmpNo").Value
rs.MoveNext
Next i
End If
rs.Close
Set rs = Nothing
If rs.State = 1 Then rs.Close
rs.CursorLocation = adUseClient
rs.Open "select * from Dept order by DName", con
cmbDeptName.Clear
If rs.RecordCount <> 0 Then
For i = 1 To rs.RecordCount
cmbDeptName.AddItem rs.Fields("DName").Value
rs.MoveNext
Next i
End If
rs.Close
Set rs = Nothing
End Sub

Public Sub CheckEmpty()


Call EmptyText(txtempno)
Call EmptyText(txtename)
Call EmptyText(txtjob)
Call EmptyText(txtsal)
If cmbDeptNo.Text = "" Then
MsgBox "Select Dept No", vbInformation + vbOKOnly, "Information"
End If
End Sub

- 49 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 2

Dim rsdept As New ADODB.Recordset


Dim tvalue As Collection
Dim tname As String
Dim tname2 As String
Dim tidname As String
Dim tidvalue As String

Private Sub cmdadd_Click()

Set tvalue = New Collection


If cmdadd.Caption = "ADD" Then
Fradept.Enabled = True
cmdadd.Caption = "SAVE"
txtdno.SetFocus
ClearAll
txtdno.SetFocus
Call disablebutton1(True, False, False, False, True)
Call disablebutton2(False, False, False, False, True)
Else
If cmdadd.Caption = "SAVE" Then
If txtdno.Text = "" Or txtdname.Text = "" Or txtloc.Text = "" Then
MsgBox "textbox cannot be empty, select a record with navigation button"
cmdadd.Caption = "ADD"
Fradept.Enabled = False
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
Exit Sub
End If
tvalue.Add Val(txtdno.Text)
tvalue.Add CStr(txtdname.Text)
tvalue.Add CStr(txtloc.Text)
tname = "Dept"

'start check for duplicate primary key


If rs.State = adStateOpen Then rs.Close
rs.Open "select * from " & tname, con, adOpenDynamic, adLockOptimistic
While rs.EOF = False
If rs.Fields(0).Value = txtdno.Text Then
MsgBox "this record no is repeated , Enter Again "
cmdadd.Caption = "ADD"
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
ClearAll

- 50 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 2

Exit Sub
End If
rs.MoveNext
Wend
rs.Close

Call addvalue(CStr(tname), tvalue)


MsgBox "RECORD ENTERED"
cmdadd.Caption = "ADD"
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
End If
End If
End Sub

Public Function ClearAll()


Call ClearText(txtdname)
Call ClearText(txtdno)
Call ClearText(txtloc)
End Function

Private Sub cmddel_Click()


rsdept.Delete
ClearAll
MsgBox "RECORD DELETED"
End Sub

Private Sub cmdcan_Click()


cmdmodify.Caption = "MODIFY"
cmdadd.Caption = "ADD"
Fradept.Enabled = False
ClearAll
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
End Sub

Private Sub cmddelete_Click()


If txtdno.Text = "" Or txtdname.Text = "" Or txtloc.Text = "" Then
MsgBox "textbox cannot be empty, select a record with navigation button"
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
Exit Sub
Else

- 51 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 2

rsdept.Delete
Display
End If

End Sub

Private Sub cmdexit_Click()


Unload Me
MDIForm1.Show
End Sub

Private Sub cmdfirst_Click()


rsdept.MoveFirst
Display
End Sub

Private Sub cmdlast_Click()


rsdept.MoveLast
Display
End Sub

Public Function modifyvalue(ttname As String, ttidname As String, ttidvalue As String, ttvalue


As Collection)
If rs.State = adStateOpen Then rs.Close
rs.Open "Select * from " & ttname & " where " & ttidname & " = " & tidvalue & "", con,
adOpenDynamic, adLockOptimistic
For i = 1 To ttvalue.Count
j=i-1
rs.Fields(j) = ttvalue.Item(i)
Next i
rs.Update

End Function

Private Sub cmdmodify_Click()


Set tvalue = New Collection
If cmdmodify.Caption = "MODIFY" Then
cmdmodify.Caption = "UPDATE"
tname = "Dept"
tidname = "DeptNo"
tidvalue = txtdno.Text
Fradept.Enabled = True
Call disablebutton1(False, False, True, False, True)

- 52 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 2

Call disablebutton2(False, False, False, False, True)


If txtdno.Text = "" Or txtdname.Text = "" Or txtloc.Text = "" Then
MsgBox "textbox cannot be empty, select a record with navigation button"
cmdmodify.Caption = "MODIFY"
Fradept.Enabled = False
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
Exit Sub
End If
Else
tvalue.Add Val(txtdno.Text)
tvalue.Add CStr(txtdname.Text)
tvalue.Add CStr(txtloc.Text)
Call modifyvalue(CStr(tname), CStr(tidname), CStr(tidvalue), tvalue)
cmdmodify.Caption = "MODIFY"
MsgBox "RECORD UPDATED"
Fradept.Enabled = False
Call disablebutton1(True, True, True, True, True)
Call disablebutton2(True, True, True, True, True)
End If
End Sub

Private Sub cmdnext_Click()


rsdept.MoveNext
Display
End Sub

Private Sub cmdpre_Click()


rsdept.MovePrevious
Display
End Sub

Private Sub cmdsearch_Click()


Dim search As String
search = InputBox("ENTER DEPARTMENT")
If rs.State = 1 Then rs.Close
rs.Open "Select * from Dept where Deptno=" & Val(search) & "", con, adOpenDynamic,
adLockOptimistic
If rs.EOF = True Then
MsgBox "ENTRY DOES NOT EXIST"
Else
txtdno = rs(0).Value
txtdname = rs(1).Value

- 53 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Form 2

txtloc = rs(2).Value
End If

End Sub

Private Sub Form_Load()


Fradept.Enabled = False
If rsdept.State = 1 Then rsdept.Close
rsdept.Open "select * from Dept", con, adOpenDynamic, adLockOptimistic
Display
End Sub
Public Sub Display()
If rsdept.BOF = True Then
rsdept.MoveFirst
MsgBox "This is first record"
Else
If rsdept.EOF = True Then
rsdept.MoveLast
MsgBox "This is last record"
End If
End If
txtdno = rsdept(0).Value
txtdname = rsdept(1).Value
txtloc = rsdept(2).Value
End Sub

Private Sub txtdname_LostFocus()


Call Ucas(txtdname)
End Sub

Private Sub txtloc_LostFocus()


Call Ucas(txtloc)
End Sub

- 54 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
MDIForm1

Private Sub MDIForm_Load()


con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.ConnectionString = "Data Source=D:\Documents and
Settings\Administrator\Desktop\Tybsc2008\VISUAL BASIC\pract6\reports.mdb"
con.Open
If con.State = adStateOpen Then
MsgBox "CONNECTION ESTABLISHED"
End If
End Sub

Private Sub mnudemprep_Click()


If frmemployee.Check1.Value = 1 Then
CrystalReport1.ReplaceSelectionFormula ""
Else
CrystalReport1.ReplaceSelectionFormula "{Dept.DName} = '" &
frmemployee.cmbDeptName.Text & "'"
End If
CrystalReport1.RetrieveDataFiles
CrystalReport1.Action = 1
End Sub

Private Sub mnudept_Click()


frmdepartment.Show
frmemployee.Hide
End Sub

Private Sub mnudsalrep_Click()


CrystalReport4.RetrieveDataFiles
CrystalReport4.Action = 1
End Sub

Private Sub mnuemp_Click()


frmemployee.Show
frmdepartment.Hide
End Sub

Private Sub mnuexit_Click()


End
End Sub

Private Sub mnujobwise_Click()


CrystalReport3.RetrieveDataFiles
CrystalReport3.Action = 1

- 55 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
MDIForm1

End Sub

Private Sub mnumaxsal_Click()


CrystalReport5.RetrieveDataFiles
CrystalReport5.Action = 1
End Sub

Private Sub mnusalrange_Click()


If frmemployee.txtRan.Text = "" Or frmemployee.txtRan1.Text = "" Then
MsgBox "Please Enter Values"
Else
CrystalReport2.ReplaceSelectionFormula "{Emp.Salary}>" & (frmemployee.txtRan) & " and
{Emp.Salary}<" & (frmemployee.txtRan1) & ""
CrystalReport2.RetrieveDataFiles
CrystalReport2.Action = 1
End If
End Sub

Private Sub mnuservice_Click()


If frmemployee.Check1.Value = 1 Then
CrystalReport6.ReplaceSelectionFormula ""
Else
CrystalReport6.ReplaceSelectionFormula "{Emp.EmpNo}=" & (frmemployee.cmbEmpNo) & ""
End If
CrystalReport6.RetrieveDataFiles
CrystalReport6.Action = 1
End Sub

- 56 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Module1

Public con As New ADODB.Connection


Public rs As New ADODB.Recordset

Public Function addvalue(ttname As String, ttvalue As Collection)


Dim j As Integer

If rs.State = adStateOpen Then rs.Close


rs.Open "Select * from " & ttname, con, adOpenDynamic, adLockOptimistic
rs.AddNew

For i = 1 To ttvalue.Count
j=i-1
rs.Fields(j) = ttvalue.Item(i)
Next i
rs.Update

End Function

Public Function EmptyText(txtname As TextBox) As Boolean


If Trim(txtname.Text) = "" Then
MsgBox txtname.Tag & " cannot be empty", vbInformation + vbOKOnly, "Information"
EmptyText = False
txtname.SetFocus
End If
EmptyText = True
End Function

Public Function Ucas(txtname As TextBox)


Dim str As String
str = UCase(Left(txtname.Text, 1))
If txtname.Text <> "" Then
txtname.Text = str + Right(txtname.Text, Len(txtname.Text) - 1)
End If

End Function

Public Function ClearText(txtname As TextBox)


txtname.Text = ""
End Function

Public Function disablebutton1(badd As Boolean, bdel As Boolean, bmod As Boolean, bsearch


As Boolean, bcan As Boolean)

- 57 -
Name-:Amol B Rukhe RollNo-338

Practical No.6
Module1

frmdepartment.cmdadd.Enabled = badd
frmdepartment.cmddelete.Enabled = bdel
frmdepartment.cmdmodify.Enabled = bmod
frmdepartment.cmdsearch.Enabled = bsearch

frmdepartment.cmdcan.Enabled = bcan

End Function

Public Sub disablebutton2(bfirst As Boolean, bnext As Boolean, bpre As Boolean, blast As


Boolean, bexit As Boolean)
frmdepartment.cmdfirst.Enabled = bfirst
frmdepartment.cmdnext.Enabled = bnext
frmdepartment.cmdpre.Enabled = bpre
frmdepartment.cmdlast.Enabled = blast
frmdepartment.cmdexit.Enabled = bexit

End Sub

Public Function disablebutton3(badd As Boolean, bdel As Boolean, bmod As Boolean, bsearch


As Boolean, bcan As Boolean)
frmemployee.cmdadd.Enabled = badd
frmemployee.cmddel.Enabled = bdel
frmemployee.cmdmodify.Enabled = bmod
frmemployee.cmdsearch.Enabled = bsearch
frmemployee.cmdcan.Enabled = bcan

End Function

Public Sub disablebutton4(bfirst As Boolean, bnext As Boolean, bpre As Boolean, blast As


Boolean, bexit As Boolean)
frmemployee.cmdfirst.Enabled = bfirst
frmemployee.cmdnext.Enabled = bnext
frmemployee.cmdpre.Enabled = bpre
frmemployee.cmdlast.Enabled = blast
frmemployee.cmdexit.Enabled = bexit

End Sub

- 58 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Title: Displaying and manipulating data from a MSFlexGrid

Write a program to display client information in to a MSFlexGrid. Validate the data and trap the
errors. After entering or updating the data in the database the updated records should be
displayed in the MSFlexGrid.

The client table will have the following fields:

Write the name of the controls, their properties used and the values set for each property in the
application in your answer sheet.

- 59 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Form1

- 60 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Form1

Dim rsnav As New ADODB.Recordset


Dim rs As New ADODB.Recordset

Private Sub cmdAdd_Click()

If cmdAdd.Caption = "A&dd Record" Then


cmdAdd.Caption = "SAVE"
fraClient_Info.Enabled = True
fraList_Client.Enabled = False
ClearAll (Me)
txtName.SetFocus
Call Disablebutton1(True, False, False, True)
Else
If rs.State = 1 Then rs.Close
rs.Open "select * from ClientInfo", con, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!CompanyName = txtName.Text
rs!ContactPerson = txtPerson.Text
rs!CompanyAddress = txtAddress.Text
rs!ContactNumber = txtNumber.Text
rs!EmailAddress = txtEmail.Text
rs.Update
MsgBox "Record Entered"
rs.Close
Call Disablebutton1(True, True, True, True)
cmdAdd.Caption = "ADD"
ClearAll (Me)
fraList_Client.Enabled = True
End If
End Sub

Private Sub cmdCancel_Click()


Call ClearAll(Me)
Call Disablebutton1(True, True, True, True)
txtName.SetFocus
End Sub

Private Sub cmdDelete_Click()

Call DelValue("ClientInfo", "CompanyName", txtName)


ClearAll (Me)
Call AddtoGrid("ClientInfo", flxClientData, 4)

- 61 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Form1

End Sub

Private Sub cmdExit_Click()


End
End Sub

Private Sub cmdModify_Click()


If cmdModify.Caption = "&Update Record" Then
cmdModify.Caption = "UPDATE"
fraClient_Info.Enabled = True
fraList_Client.Enabled = False
Call Disablebutton1(False, False, True, True)
If rs.State = adStateOpen Then rs.Close
rs.Open "select * from ClientInfo where CompanyName ='" & txtName & "'", con,
adOpenDynamicl, adLockOptimistic
Else
rs!CompanyName = txtName.Text
rs!ContactPerson = txtPerson.Text
rs!CompanyAddress = txtAddress.Text
rs!ContactNumber = txtNumber.Text
rs!EmailAddress = txtEmail.Text
rs.Update
MsgBox "Record Updated"
rs.Close
fraList_Client.Enabled = True
Call Disablebutton1(True, True, True, True)
cmdModify.Caption = "&Update Record"
End If
End Sub

Private Sub flxClientData_Click()

flxClientData.Row = flxClientData.RowSel
flxClientData.Col = 0
txtName = flxClientData.Text
flxClientData.Col = 1
txtPerson = flxClientData.Text
flxClientData.Col = 2
txtAddress = flxClientData.Text
flxClientData.Col = 3
txtNumber = flxClientData.Text
flxClientData.Col = 4
txtEmail = flxClientData.Text

- 62 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Form1

End Sub

Private Sub Form_Load()

con.Provider = "Microsoft.jet.OLEDB.4.0"
con.ConnectionString = "data source=D:\TYBSC_2008\vb1\P7\ClientInfo.mdb"
con.Open
If con.State = adStateOpen Then
MsgBox "Connection Established"
End If
rsnav.Open "select * from ClientInfo", con, adOpenDynamic, adLockOptimistic
fraClient_Info.Enabled = False
Call NameGrid(0, 0, "CompanyName ", 2000, flxClientData)
Call NameGrid(1, 0, "ContactPerson", 2000, flxClientData)
Call NameGrid(2, 0, "CompanyAddress", 2000, flxClientData)
Call NameGrid(3, 0, "ContactNumber ", 1500, flxClientData)
Call NameGrid(4, 0, "EmailAddress", 2000, flxClientData)
Call AddtoGrid("ClientInfo", flxClientData, 4)

End Sub

- 63 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Module1

Dim rs As New ADODB.Recordset


Public con As New ADODB.Connection
Dim rsnav As New ADODB.Recordset

Public Function NameGrid(c As Single, r As Single, n As String, w As Integer, flxGrid As


MSFlexGrid)
flxGrid.Col = c
flxGrid.Row = r
flxGrid.Text = n
flxGrid.ColWidth(c) = w
End Function

Public Function AddtoGrid(tname As String, flxGrid As MSFlexGrid, c As Single)


Dim i, j As Integer
If rs.State = 1 Then rs.Close
rs.CursorLocation = adUseClient
tname = "ClientInfo"
rs.Open "Select * from " & tname & " ", con, adOpenDynamic, adLockOptimistic
If rs.RecordCount <> 0 Then
rs.MoveFirst
flxGrid.Rows = rs.RecordCount + 1
For i = 1 To rs.RecordCount
For j = 0 To c
flxGrid.Row = i
flxGrid.Col = j
flxGrid.Text = rs.Fields(j).Value
Next j
rs.MoveNext
Next i
Else
flxGrid.Row = 1
End If
rs.Close
End Function

Public Function DelValue(tname As String, tpcol As String, tpcolval As String)


con.Execute "Delete from " & tname & " where " & tpcol & "='" & tpcolval & "'"
MsgBox "Record Deleted"
End Function

Public Function ClearAll(ByVal frm As Variant)


For Each Control In frm
If TypeOf Control Is TextBox Then Control.Text = ""

- 64 -
Name-:Amol B Rukhe RollNo-338

Practical No. 7
Module1

If TypeOf Control Is ComboBox Then


If Control.Style <> 2 Then Control.Text = ""
End If
Next
End Function

Public Function MakeNumeric(txtName As TextBox)


If (KeyAscii >= 48 & KeyAscii <= 56) Then
KeyAscii = 0
End If
End Function

Public Function Disablebutton1(badd As Boolean, bdel As Boolean, bmod As Boolean, bcan As


Boolean)
frmClient.cmdAdd.Enabled = badd
frmClient.cmdDelete.Enabled = bdel
frmClient.cmdModify.Enabled = bmod
frmClient.cmdCancel.Enabled = bcan
End Function

Public Function FillRect(ByVal i As Single, ByVal n As Single, ByVal c As String, flxGrid As


MSFlexGrid)
flxGrid.Row = i
flxGrid.Col = n
flxGrid.Text = c
End Function

- 65 -
Name-:Amol B Rukhe RollNo-338

Practical No. 8
Title: Understanding and using OLE and DLL

Part 1. Object Linking and Embedding:

Write a program to embed Microsoft word into your application. Link any of the other objects
with your application.

On click of start word button start Microsoft Word and on click of stop button end your
Microsoft word.

Part 2. Dynamic Link Libraries

Write a program to create Dynamic Link Libraries (DLL) for finding sum of two numbers.

Create a project, which uses this DLL, which accepts two numbers and returns the answer.

Write the name of the controls, their properties used and the values set for each property in the
application in your answer sheet.

- 66 -
Name-:Amol B Rukhe RollNo-338

Practical No.8
Part I
Form1

- 67 -
Name-:Amol B Rukhe RollNo-338

Practical No.8
Part II
Form2

- 68 -
Name-:Amol B Rukhe RollNo-338

Practical No.8
Part I
Form1

'Here add Reference ->Micrcosoft Word Library

Dim w As New Word.Application

Private Sub cmdexit_Click()


End
End Sub

Private Sub cmdStart_Click()


w.Documents.add
w.Visible = True
cmdStop.Enabled = True
End Sub

Private Sub cmdStop_Click()


w.Documents.Close
w.Visible = False
End Sub

Private Sub Form_Load()


cmdStop.Enabled = False
End Sub

- 69 -
Name-:Amol B Rukhe RollNo-338

Practical No.8
Part II
Form2

Dim obj As New Class1


Dim a As Integer
Dim b As Integer
Private Sub cmdAdd_Click()
a = Val(txtnum1.Text)
b = Val(txtnum2.Text)
Label1.Caption = obj.add(a, b)
End Sub

Private Sub cmdclear_Click()


txtnum1.Text = ""
txtnum2.Text = ""
Label1.Caption = ""
txtnum1.SetFocus
End Sub

Private Sub cmdDiv_Click()


a = Val(txtnum1.Text)
b = Val(txtnum2.Text)
Label1.Caption = obj.division(a, b)
End Sub

Private Sub cmdMul_Click()


a = Val(txtnum1.Text)
b = Val(txtnum2.Text)
Label1.Caption = obj.multiply(a, b)
End Sub

Private Sub cmdSub_Click()


a = Val(txtnum1.Text)
b = Val(txtnum2.Text)
Label1.Caption = obj.subtract(a, b)
End Sub

- 70 -
Name-:Amol B Rukhe RollNo-338

Practical No.8
Part II
Class1

Public Function add(num1 As Integer, num2 As Integer)


add = num1 + num2
End Function

Public Function multiply(num1 As Integer, num2 As Integer)


multiply = num1 * num2
End Function

Public Function division(num1 As Integer, num2 As Integer)


division = num1 / num2
End Function

Public Function subtract(num1 As Integer, num2 As Integer)


subtract = num1 - num2
End Function

- 71 -
Name-:Amol B Rukhe RollNo-338

Practical No. 9
Title: Understanding and using Drag and Drop

Create a project for a card-suit guessing game. The user will drag the images to the boxes along
the lower edge of the form. When the correct image is placed in a box, make the image remain
there.

Then all four images are in the correct location, display a message box congratulating the user.
The reset button should replace the suit images at the top form and clear out the lower boxes.

Write the name of the controls, their properties used and the values set for each property in the
application in your answer sheet.

- 72 -
Name-:Amol B Rukhe RollNo-338

Practical No.9
Form1

- 73 -
Name-:Amol B Rukhe RollNo-338

Practical No.9
Form1

Private Sub cmdExit_Click()


End
End Sub

Private Sub cmdReset_Click()


imgClub.Visible = True
imgDiamond.Visible = True
imgHeart.Visible = True
imgSpade.Visible = True
imgClub1.Picture = LoadPicture("")
imgDiamond1.Picture = LoadPicture("")
imgHeart1.Picture = LoadPicture("")
imgSpade1.Picture = LoadPicture("")
imgClub1.AutoSize = True
imgDiamond1.AutoSize = True
imgHeart1.AutoSize = True
Call Form_Load
End Sub

Private Sub Form_Load()


Dim pos, r As Integer
pos = (Math.Rnd + 1) * 1000
r = pos Mod 4
If r = 0 Then
imgClub1.Left = 480
imgHeart1.Left = 2280
imgSpade1.Left = 4005
imgDiamond1.Left = 5760
End If
If r = 1 Then
imgClub1.Left = 4005
imgHeart1.Left = 5760
imgSpade1.Left = 480
imgDiamond1.Left = 2280
End If

If r = 2 Then
imgClub1.Left = 5760
imgHeart1.Left = 4005
imgSpade1.Left = 2280
imgDiamond1.Left = 480
End If

- 74 -
Name-:Amol B Rukhe RollNo-338

Practical No.9
Form1

If r = 3 Then
imgClub1.Left = 2280
imgHeart1.Left = 480
imgSpade1.Left = 5760
imgDiamond1.Left = 4005
End If

End Sub

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


If Source.Name = "imgClub" Then
imgClub1.Picture = imgClub.Picture
imgClub1.AutoSize = True
imgClub.Visible = False

If imgDiamond1 <> 0 And imgHeart1 <> 0 And imgSpade1 <> 0 Then


MsgBox "CONGRATULATION"
End If
End If
End Sub

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


If Source.Name = "imgDiamond" Then
imgDiamond1.Picture = imgDiamond.Picture
imgDiamond.Visible = False
imgDiamond1.AutoSize = True
If imgClub1 <> 0 And imgHeart1 <> 0 And imgSpade1 <> 0 Then
MsgBox "CONGRATULATION"
End If
End If
End Sub

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


If Source.Name = "imgHeart" Then
imgHeart1.Picture = imgHeart.Picture
imgHeart.Visible = False
imgHeart1.AutoSize = True
If imgClub1 <> 0 And imgDiamond1 <> 0 And imgSpade1 <> 0 Then
MsgBox "CONGRATULATION"
End If
End If

End Sub

- 75 -
Name-:Amol B Rukhe RollNo-338

Practical No.9
Form1

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


If Source.Name = "imgSpade" Then
imgSpade1.Picture = imgSpade.Picture
imgSpade.Visible = False
imgSpade1.AutoSize = True
If imgClub1 <> 0 And imgDiamond1 <> 0 And imgHeart1 <> 0 Then
MsgBox "CONGRATULATION"
End If
End If
End Sub

- 76 -

S-ar putea să vă placă și