106
ANNAMALAI UNIVERSITY Department of Computer Science and Engineering LAB MANUAL for 86708 – VISUAL PROGRAMMING, C# and .NET LAB November 2010 – April 2011 Lab In-charges A1 – Batch - Ms. A. Suhasini A2 – Batch - Ms. T.S. Subashini B – Batch - Mr. G. Ramachandran C - Batch - Ms. N. J. Nalini D - Batch - Mr. P. Sudhakar E1 - Batch - Mr. R. Saminathan

Visual Basic Labmanual

Embed Size (px)

Citation preview

Page 1: Visual Basic Labmanual

ANNAMALAI UNIVERSITYDepartment of Computer Science and

Engineering

LAB MANUAL

for

86708 – VISUAL PROGRAMMING, C# and .NET LAB

November 2010 – April 2011

Lab In-charges

A1 – Batch - Ms. A. Suhasini

A2 – Batch - Ms. T.S. Subashini

B – Batch - Mr. G. Ramachandran

C - Batch - Ms. N. J. Nalini

D - Batch - Mr. P. Sudhakar

E1 - Batch - Mr. R. Saminathan

E2 - Batch - Mr. N.Kumaran

F - Batch - Ms. G. Indirani

G - Batch - Ms. L. R. Sudha

Page 2: Visual Basic Labmanual

ANNAMALAI UNIVERSITYDepartment of Computer Science and Engineering

List of Experiments86708 – VISUAL PROGRAMMING, C# and .NET LAB

PROGRAMME: B.E. (CSE) SEMESTER: VIYEAR: Third Year BATCH: A, B, C, D, E, F & G

Visual Basic

1. Program to calculate the simple interest and compound interest.2. Program to generate Fibonacci series.3. Program to design a Scientific Calculator.4. Program to perform various string operations.5. Program to perform various matrix operations.6. Program to create a simple text editor.7. Program to perform free hand drawing.8. Program to create simple MDI text editor.9. Program to create a database.

Visual C ++

10. Program to find whether a string is palindrome or not.11. Program to generate the Fibonacci and factorial series.12. Program to perform matrix multiplication.13. Program for coping a file.14. Program to count the number of mouse clicks.15. Program to insert an ActiveX Control.16. Program to create a message box.

C #

17. Program to prepare a mark sheet with details.18. Program to deposit and withdraw money from an account.19. Program to perform basic arithmetic operations.20. Program to find the area of square and rectangle.21. Program to display employee details.22. Program to enter and display book details in a library.23. Program to assign priority to thread and check whether they are alive.

. NET

24. Program to read the password and display it.

Page 3: Visual Basic Labmanual

25. Program to show which button has been clicked by user.

Visual Basic

Ex No.1 Interest Calculation

Aim:

To write a visual basic program to calculate the simple interest and compound interest.

Algorithm:

1. Start2. Design the form with five-text box and one command button and appropriate

message is displayed in label box3. Declare variable as general4. Write the script in the click event on the command button5. set p=Text1.Text6. set n=Text2.Text7. set r=Text3.Text8. si=(p*n*r)/1009. Ci=p*(1+r/100)^n10. Text4.Text=si11. Text5.Text=Ci12. Stop

Property Setting:

Property of principle label box Name=label1 Caption=Principle

Property of rate of interest label box Name=label2 Caption=Rate of interest

Property of Time label box Name=label3 Caption=Time

Property of interest label box Name=label4 Caption=Result

Page 4: Visual Basic Labmanual

Property of Text box Name=Text1 Caption=""

Property of Text box Name=Text2 Caption=""

Property of Text box Name=Text3 Caption=""

Property of Text box Name=Text4 Caption=""

Property of simple interest command button Name=Command1 Caption=Simple interest

Property of compound interest command button Name=Command2 Caption=Compound interest

Property of clear command button Name=Command3 Caption=clear

Property of Exit command button Name=command4 Caption=Exit

Form:

Page 5: Visual Basic Labmanual

Source Code:Dim p, r As DoubleDim n As IntegerPrivate Sub Command1_Click()p = Val(Text1.Text)r = Val(Text2.Text)n = Val(Text3.Text)Text4.Text = ""Text4.Text = (p * n * r) / 100End Sub

Private Sub Command2_Click()p = Val(Text1.Text)r = Val(Text2.Text)n = Val(Text3.Text)Text4.Text = ""Text4.Text = p * (1 + r / 100) ^ nEnd Sub

Private Sub Command3_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""End Sub

Private Sub Command4_Click()EndEnd Sub

Output:

Page 6: Visual Basic Labmanual

Result:

Thus a visual basic program has been written to calculate the simple and compound interest and verified with various samples.

Page 7: Visual Basic Labmanual

Ex No.2 Fibonacci Series

Aim:

To write a visual basic program to create a Fibonacci series.

Algorithm:

1. Start.2. Create a form & replace all the controls that are needed.3. Under the click event of the command button result, write the appropriate

codes.4. Initialize last val,tot and cur val to l . 5. Display the tot and curval in the textbox and initialize l to 1.6. Do the steps untill i<=n-2

a) Put tot=lastval+curval.b) Equate lastval &curval.c) Equate curval&tot.d) Display the tot in the textbox.

7. End the loop.8. Stop.

Property Setting:

Property of label box Name=label1 Caption=Enter the value Property of compute command box Name=command1 Caption=Compute Property of exit command box Name=command2 Caption=Exit

Property of list box Name=listbox1 Caption=""

Page 8: Visual Basic Labmanual

Form:

Source Code:Private Sub Command1_Click()Dim f1, f2, f3, i As Integerf1 = -1f2 = 1n = Val(Text1.Text)For i = 1 To nf3 = f1 + f2List1.AddItem (f3)f1 = f2f2 = f3Next iEnd Sub

Private Sub Command2_Click()EndEnd Sub

Page 9: Visual Basic Labmanual

Output:

Result:

Thus a visual basic program has been written to calculate the Fibonacci series and verified with various samples.

Page 10: Visual Basic Labmanual

Ex No.3 Design a Scientific calculator

Aim:To create a scientific calculator using control arrays using visual basic

environment.

Algorithm:

1. Start.2. Add the controls according to the below table.3. Stop.

Property Setting: Control Name Property Value

Text Box Text1 Text Text2 Text Command Command1 Caption, Index 1, 1

Command2 Caption, Index 2, 2Command3 Caption, Index 3, 3

Command4 Caption, Index 4, 4Command5 Caption, Index 5, 5Command6 Caption, Index 6, 6Command7 Caption, Index 7, 7Command8 Caption, Index 8, 8Command9 Caption, Index 9, 9Command10 Caption .Command 11 Caption 0Command 12 Caption =Command 13 Caption +Command 14 Caption -Command 15 Caption *Command 16 Caption /Command 17 Caption x^2Command 18 Caption x^3Command 19 Caption x^4Command 20 Caption SqrtCommand 21 Caption modCommand 22 Caption sinCommand 23 Caption cosCommand 24 Caption tanCommand 25 Caption 10^xCommand 26 Caption 1/xCommand 27 Caption x! Command 28 Caption Pi

Command 29 Caption C Command 30 Caption Exit

Page 11: Visual Basic Labmanual

Form:

Source Code:

Dim a, b, c, d As Variant

Private Sub Command1_Click() Text1.Text = Text1.Text & 1 End Sub

Private Sub Command10_Click()

Page 12: Visual Basic Labmanual

Text1.Text = Text1.Text & "." End Sub Private Sub Command11_Click() Text1.Text = Text1.Text & 0 End Sub

Private Sub Command12_Click() b = Val(Text1.Text) Text1.Text = " " If c = "+" Then d = a + b Text1.Text = d ElseIf c = "-" Then d = a - b Text1.Text = d ElseIf c = "*" Then d = a * b Text1.Text = d ElseIf c = "/" Then d = a / b Text1.Text = d ElseIf c = "mod" Then d = a Mod b Text1.Text = d End If End Sub

Private Sub Command13_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = " " c = "+" End If End Sub

Private Sub Command14_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = " " c = "-" End If End Sub

Private Sub Command15_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = " " c = "*"

Page 13: Visual Basic Labmanual

End If End Sub

Private Sub Command16_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = " " c = "/" End If End Sub

Private Sub Command17_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = a * a End If End Sub

Private Sub Command18_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = a * a * a End If End Sub

Private Sub Command19_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = a * a * a * a End If End Sub

Private Sub Command2_Click() Text1.Text = Text1.Text & 2 End Sub

Private Sub Command20_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = " " Text1.Text = (a) ^ 0.5 End If End Sub

Private Sub Command21_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = " " c = "mod"

Page 14: Visual Basic Labmanual

End If End Sub

Private Sub Command22_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) + (3.14 / 180) Text1.Text = " " Text1.Text = Sin(a) End If End Sub

Private Sub Command23_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) + (3.14 / 180) Text1.Text = " " Text1.Text = Cos(a) End If End Sub

Private Sub Command24_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) + (3.14 / 180) Text1.Text = " " Text1.Text = Tan(a) End If End Sub

Private Sub Command25_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = 10 ^ a End If End Sub

Private Sub Command26_Click() If Trim(Text1.Text) <> " " Then a = Val(Text1.Text) Text1.Text = 1 / a End If End Sub

Private Sub Command27_Click() Dim s, n, i As Integer If Trim(Text1.Text) <> " " Then n = Val(Text1.Text) Text1.Text = " " s = 1 For i = 1 To n s = s * i

Page 15: Visual Basic Labmanual

Next i Text1.Text = s End If End Sub

Private Sub Command28_Click() Text1.Text = Val(Text1.Text) * 3.14 End Sub

Private Sub Command29_Click() Text1.Text = " " End Sub

Private Sub Command3_Click() Text1.Text = Text1.Text & 3 End Sub

Private Sub Command30_Click() End End Sub

Private Sub Command4_Click() Text1.Text = Text1.Text & 4 End Sub

Private Sub Command5_Click() Text1.Text = Text1.Text & 5 End Sub

Private Sub Command6_Click() Text1.Text = Text1.Text & 6 End Sub

Private Sub Command7_Click() Text1.Text = Text1.Text & 7 End Sub

Private Sub Command8_Click() Text1.Text = Text1.Text & 8 End Sub

Private Sub Command9_Click() Text1.Text = Text1.Text & 9 End Sub

Page 16: Visual Basic Labmanual

Output:

Result:

Thus a visual basic program has been written to design a scientific calculator and verified with various samples.

Page 17: Visual Basic Labmanual

Ex No.4 String Operation

Aim:To write a visual basic program to performing string operations based on the user

choice.

Algorithm:

1. Start2. read the string 1 & string 23. get the choice from the user4. if choice=compare then5. strcomp(string1,string2)6. Else if choice=concat,then7. print the concatenated string in textbox8. Else if choice=replace,then9. Exchange the string10. Else if choice=length,then11. Find the length 12. Else if choice=trim,then13. remove space14. Else if choice=reverse,then15. strreverse(string 1)16. Else if choice=space,then17. add space18. Else if choice=conversion,then19. convert the cases20. stop

Property Setting:

Property of String1 label box Name=label1 Caption=String1

Property of String2 label box Name=String2 Caption=String2

Property of result label box Name=label3 Caption=result

Property of Text box 1 Name=Text1 Caption=""

Property of Text box 2

Page 18: Visual Basic Labmanual

Name=Text2 Caption=""

Property of Text box 3 Name=Text3 Caption=""

Property for stringlen command box Name=Command2 Caption=length

Property for stringcat command box Name=Command5 Caption=concat Property for stringreplace command box Name=Command1 Caption=replace

Property for stringcomp command box Name=Command7 Caption=compare

Property for stringspace command box Name=Command3 Caption=space

Property for stringrev command box Name=Command6 Caption=reverse

Property for exit command box Name=Command10 Caption=exit

Property for clear command button Name=Command9 Caption=clear

Property for option button Name=opt1 Caption=option1

Page 19: Visual Basic Labmanual

Form:

Source Code:

Private Sub Command1_Click()Dim a, b As Stringa = Text1.Textb = Text2.TextText3.Text = Replace(a, "a", b, 1, 1)End Sub

Private Sub Command10_Click()EndEnd Sub

Private Sub Command2_Click()Text3.Text = Len(Text1)End Sub

Private Sub Command3_Click()Dim a As Stringa = Text1.TextText3.Text = Space(5) + aEnd Sub

Private Sub Command4_Click()Dim a As Stringa = Text1.TextText3.Text = StrConv(a, 1)End Sub

Page 20: Visual Basic Labmanual

Private Sub Command5_Click()Dim a As Stringa = Text1.Textb = Text2.TextText3.Text = a + bEnd Sub

Private Sub Command7_Click()Dim a, b As Stringa = Text1.Textb = Text2.TextText3.Text = StrReverse(a)End Sub

Private Sub Command6_Click()Dim a As Stringa = Text1.TextText3.Text = StrComp(a, b)End Sub

Private Sub Command8_Click()Dim a As Stringa = Text1.TextText3.Text = Trim(a)End Sub

Private Sub Command9_Click()Text1.Text = " "Text2.Text = " "Text3.Text = " "End Sub

Page 21: Visual Basic Labmanual

Output:

Result:

Thus a visual basic program has been written to do string operations and verified with various samples.

Page 22: Visual Basic Labmanual

Ex No.5 Matrix Operation

Aim:

To write a visual basic performing matrix operations.

Algorithm:

1. Start2. design the form with 3 list boxes and six command buttons3. write the script in the click events of the command button4. write the script in the addition command button for matrix 5. addition and the appropriate in the command button6. stop

Property Setting:

CONTROL PROPERTY VALUE Label1 caption 1st matrix Label2 caption 2nd matrix Command1 caption add Command2 caption sub Command3 caption multiply Command4 caption inverse Command5 caption clear Command6 caption exit List box 1 caption listbox1 List box 2 caption listbox2 List box 3 caption listbox3 Text1 text multiline true

Form:

Page 23: Visual Basic Labmanual

Source Code:

Option Explicit Dim a(10, 10) As Integer Dim b(10, 10) As Integer Dim c(10, 10) As Integer Dim m, n, p, q, i, j, k As Integer Dim str As String Private Sub Command1_Click() List1.Clear List2.Clear List3.Clearl1: m = InputBox("Enter m value") n = InputBox("Enter n value") p = InputBox("Enter p value") q = InputBox("Enter q value") If m <> p Or n <> q Then MsgBox ("Operation not possible") GoTo l1 End If inputa inpub For i = 1 To m str = " " For j = 1 To n c(i, j) = a(i, j) + b(i, j) str = str & c(i, j) & " " Next j List3.AddItem (str) Next i End Sub Private Sub inputa() For i = 1 To m str = " " For j = 1 To n a(i, j) = InputBox("Enter A matrix row wise") str = str & a(i, j) & " " Next j List1.AddItem (str) Next i End Sub Private Sub inpub() For i = 1 To p str = " " For j = 1 To q b(i, j) = InputBox("Enter B matrix row wise") str = str & b(i, j) & " "

Page 24: Visual Basic Labmanual

Next j List2.AddItem (str) Next i End Sub

Private Sub Command2_Click() List1.Clear List2.Clear List3.Clearl1: m = InputBox("Enter m value") n = InputBox("Enter n value") p = InputBox("Enter p value") q = InputBox("Enter q value") If m <> p Or n <> q Then MsgBox ("Operation not possible") GoTo l1 End If inputa inpub For i = 1 To m str = " " For j = 1 To n c(i, j) = a(i, j) - b(i, j) str = str & c(i, j) & " " Next j List3.AddItem (str) Next i End Sub

Private Sub Command3_Click() List1.Clear List2.Clear List3.Clearl1: m = InputBox("Enter m value") n = InputBox("Enter n value") p = InputBox("Enter p value") q = InputBox("Enter q value") If n <> p Then MsgBox ("Operation not possible") GoTo l1 End If inputa inpub For i = 1 To m str = " " For j = 1 To q c(i, j) = 0

Page 25: Visual Basic Labmanual

For k = 1 To p c(i, j) = c(i, j) + a(i, k) * b(k, j) Next k str = str & c(i, j) & " " Next j List3.AddItem (str) Next i End Sub

Private Sub Command4_Click() List1.Clear List2.Clear List3.Clear Label2.Visible = False List2.Visible = False m = InputBox("Enter m value") n = InputBox("Enter n value") inputa For i = 1 To n str = " " For j = 1 To m c(i, j) = a(j, i) str = str & c(i, j) & " " Next j List3.AddItem (str) Next i End Sub

Private Sub Command5_Click() List1.Clear List2.Clear List3.Clear End Sub

Private Sub Command6_Click() End End Sub

Page 26: Visual Basic Labmanual

Output:

Result:

Thus a visual basic program has been written to develop a matrix operation and tested with various samples.

Page 27: Visual Basic Labmanual

Ex No.6 Simulation of text editor

Aim: To write a Visual Basic Program to create a simple Text Editor.

Algorithm:

1. Place the label, text box, and combo box as shown in form layout.2. Click tools -> menu editor to open the menu editor .3. Give the required caption, name in the menu editor window and use left and right

arrow buttons to place the menu item as sub menu and use up and down arrows to arrange it in a sequence.

4. Create three menu with lists as shown below

Menu Caption Sub-Menu Caption Name File New mnunew

Open mnuopenSave mnusavePrint mnuprintExit mnuexit

Edit Cut mnucutCopy mnucopyPaste mnupasteFind mnufindReplace mnureplace

Format Font mnufont--Bold mnubold--Italic mnuitalic--Underline mnuunderline--StrikeThrough mnustrikethruAlignment mnualign--Right mnuright--Left mnuleft--Center mnucenterColor mnucolor--Bgcolor mnubgcolor--Forecolor mnuforecolor

5. To invoke components, click project -> components then select Microsoft common dialog box control from components window .

6. By selecting the operations on menus the corresponding tasks should be performed using common dialog box and clipboard events.

Property Setting:

Property of Textbox Name=text1 Text=" "

Page 28: Visual Basic Labmanual

Property of CommonDialogBox Name=cdm1Menu Editor:

Form:

Page 29: Visual Basic Labmanual

Source Code:Private Sub mnubgcolor_Click()cdm1.ShowColorText1.BackColor = cdm1.ColorEnd Sub

Private Sub mnubold_Click()Text1.FontBold = Not (Text1.BorderStyle)End Sub

Private Sub mnucenter_Click()Text1.Alignment = vbCenterEnd Sub

Private Sub mnucopy_Click()Clipboard.SetText (Text1.Text)End Sub

Private Sub mnucut_Click()Clipboard.SetText (Text1.Text)Text1.Text = ""End Sub

Private Sub mnuexit_Click()EndEnd Sub

Private Sub mnuforecolor_Click()cdm1.ShowColorText1.ForeColor = cdm1.ColorEnd Sub

Private Sub mnuitalic_Click()Text1.FontItalic = Not (Text1.FontItalic)End Sub

Private Sub mnuleft_Click()Text1.Alignment = vbLeftJustifyEnd Sub

Private Sub mnunew_Click()Text1.Text = ""End Sub

Private Sub mnuopen_Click()cdm1.InitDir = "vb98"cdm1.DialogTitle = "file open"cdm1.Filter = "allfiles(*.*)|textfiles(*.txt)|*.txt"cdm1.DefaultExt = "*.*"

Page 30: Visual Basic Labmanual

cdm1.ShowOpenEnd Sub

Private Sub mnupaste_Click()Text1.SelText = Clipboard.GetTextEnd Sub

Private Sub mnuprint_Click()cdm1.ShowPrinterEnd Sub

Private Sub mnuright_Click()Text1.Alignment = vbRightJustifyEnd Sub

Private Sub mnusave_Click()cdm1.InitDir = "vb98"cdm1.DialogTitle = "file save"cdm1.Filter = "allfiles(*.*)|*.*"cdm1.DefaultExt = "txt"cdm1.ShowSaveEnd Sub

Private Sub mnustrike_Click()Text1.FontStrikethru = Not (Text1.FontStrikethru)End Sub

Private Sub mnuunder_Click()Text1.FontUnderline = Not (Text1.FontUnderline)End Sub

Page 31: Visual Basic Labmanual

Output:

Result:

Thus a visual basic program has been written to design a simple text editor and tested with various samples.

Page 32: Visual Basic Labmanual

Ex No.7 Freehand Drawing

Aim:To write a visual basic program to create a free hand drawing.

Algorithm:

1. Start2. Design the form by adding 4 command button and 1 combo box3. Write the script in the appropriate events.4. Stop

Property Setting:

Property of command box Name=command1 caption=size Property of command box Name=command2 caption=color

Property of command box Name=command3 caption=clear

Property of command box Name=command4 caption=exit

Property of Picture box Name=Picture1

Property of Common Dialog Box Name=cd1 Property of combo box Name=combo1 caption=""

Page 33: Visual Basic Labmanual

Form:

Source Code:

Dim clr As OLE_COLOR, drw As IntegerPrivate Sub Command1_Click()Combo1.Visible = TrueEnd Sub

Private Sub Command2_Click()cd1.ShowColorclr = cd1.ColorEnd Sub

Private Sub Command3_Click()Picture1.ClsEnd Sub

Private Sub Command4_Click()EndEnd Sub

Private Sub Form_Load()clr = vbBlackFor i = 1 To 15Combo1.AddItem (i)Next iEnd SubPrivate Sub Picture1_MouseDown(button As Integer, shift As Integer, x As Single, y As Single)Combo1.Visible = FalseIf button = vbLeftButton Then

Page 34: Visual Basic Labmanual

Picture1.PSet (x, y), clrPicture1.DrawWidth = Combo1.TextElseIf button = vbRightButton ThenPicture1.DrawWidth = 1Picture1.PSet (x, y), Combo1.Text * 10End IfEnd Sub

Private Sub Picture1_MouseMove(button As Integer, shift As Integer, x As Single, y As Single)If button = vbLeftButton ThenPicture1.PSet (x, y), clrPicture1.DrawWidth = Combo1.TextElseIf button = vbRightButton ThenPicture1.DrawWidth = 1Picture1.Circle (x, y), Combo1.Text * 10End IfEnd SubOutput:

Result:

Thus a visual basic program has been written to design a free hand drawing and tested with various samples.

Page 35: Visual Basic Labmanual

Ex No.8 Simple MDI text editor

Aim:To create a visual basic application with MDI features and text editing capabilities

and also explaining the tool bar, menu bar, status bar, image list box controls.

Algorithm:

In MDI Form

---Select Microsoft windows common control and Microsoft common dialog control from Project->Components

Create the menu bar as follows

1.Add this image box from the left panel

2.Create 6 images using paint for new, open, save, cut, copy and paste respectively3.Select the image box and double-click the custom from the properties present in the right pane.4.Select images tab5.Click Insert Pictures command button6.Select the 6 pictures from the desired location(which u created in step 2)

Page 36: Visual Basic Labmanual

7.Click OK.8.Double click Toolbar icon from left pane

9.Select toolbar on form (below the menu bar of your form)10.Double click custom from properties(on right pane)11.Select Button tab12.Click insert button (6 times) and also number the image text field with corresponding number of index

13.Select General tab14.Select Imagelist list box15.Select the Imagelist1 that u created before.

Page 37: Visual Basic Labmanual

16.Add a Common dialog box and name it as comdg.

The resulting form will be something like this

In Form1

1.Add a rich text box name it as rt2.Rich text box is available in Project->components->Microsoft Rich Text Box

Page 38: Visual Basic Labmanual

3.In form1 in properties select MDIChild=True

Source Code:

Private Sub MDIForm_Load() Static n As Integer End Sub Private Sub mnucopy_Click() Clipboard.SetText (MDIForm1.ActiveForm.ActiveControl.SelText) End Sub

Private Sub mnucut_Click() Clipboard.SetText (MDIForm1.ActiveForm.ActiveControl.SelText) MDIForm1.ActiveForm.ActiveControl.SelText = " " End Sub Private Sub mnunew_Click() Static n1 As Integer filenam = " " n1 = n1 + 1 Dim nf As New Form1 nf.Show MDIForm1.ActiveForm.Caption = "untitled" + Str(n1) End Sub

Private Sub mnuopen_Click() comdg.ShowOpen filenam = " " n1 = n1 + 1 Dim nf As New Form1 nf.Show nf.rt.FileName = comdg.FileName filenam = comdg.FileName

Page 39: Visual Basic Labmanual

End Sub

Private Sub mnupaste_Click() MDIForm1.ActiveForm.ActiveControl.SelText = Clipboard.GetText() End Sub

Private Sub mnusave_Click() If Len(filenam) <> 0 Then MDIForm1.ActiveForm.activeobject.SaveFile (filenam) Else Call mnusaveas_Click End If End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button) If (Button.Index = 1) Then Call mnunew_Click ElseIf (Button.Index = 2) Then Call mnuopen_Click ElseIf (Button.Index = 3) Then Call mnusave_Click ElseIf (Button.Index = 4) Then Call mnucut_Click ElseIf (Button.Index = 5) Then Call mnucopy_Click ElseIf (Button.Index = 6) Then Call mnupaste_Click End If End Sub Private Sub mnusaveas_Click() comdg.ShowSave MDIForm1.ActiveForm.ActiveControl.SaveFile (comdg.FileName) filenam = comdg.FileName End Sub Private Sub rt_MouseDown(Button As Integer, shift As Integer, x As Single, y As Single) If Button = 2 Then PopupMenu mnuedit End If End Sub

Page 40: Visual Basic Labmanual

Output:

Result:

Thus a visual basic program has been written to design a simple text MDI text editor and tested with various samples.

Page 41: Visual Basic Labmanual

Ex No.10 Database

Aim:

To create a visual basic application for doing basic functions in an database.

Algorithm:

1.Start2.Create a table as followsAdd-Ins->Visual DataManager

File->New->Microsoft Access->Version 7.0 MDBSave file.

Right click on properties(in Database Window)

Page 42: Visual Basic Labmanual

Select New Table

Enter table nameClick Add Field buttonEnter the Name and select the desired type in Type combo box.

Page 43: Visual Basic Labmanual

Click ok.Similarly enter all the field names and its corresponding type.When finished click close.

Click Build the table

Page 44: Visual Basic Labmanual

Double click the table name.Click Add and enter the corresponding field details and update it.Similarly enter all the records.3.Click Utility->Data form designer

4.Enter the form name as Form25.Select Record in RecordSource listbox.

Page 45: Visual Basic Labmanual

6.Click the >> button in the middle and then click Build The Form7.Stop.

Form:You will get something like this with in built code as given below.

Source code:

Private Sub cmdAdd_Click() Data1.Recordset.AddNewEnd Sub

Private Sub cmdDelete_Click() 'this may produce an error if you delete the last 'record or the only record in the recordset Data1.Recordset.Delete Data1.Recordset.MoveNextEnd Sub

Page 46: Visual Basic Labmanual

Private Sub cmdRefresh_Click() 'this is really only needed for multi user apps Data1.RefreshEnd Sub

Private Sub cmdUpdate_Click() Data1.UpdateRecord Data1.Recordset.Bookmark = Data1.Recordset.LastModifiedEnd Sub

Private Sub cmdClose_Click() Unload MeEnd Sub

Private Sub Data1_Error(DataErr As Integer, Response As Integer) 'This is where you would put error handling code 'If you want to ignore errors, comment out the next line 'If you want to trap them, add code here to handle them MsgBox "Data error event hit err:" & Error$(DataErr) Response = 0 'throw away the errorEnd Sub

Private Sub Data1_Reposition() Screen.MousePointer = vbDefault On Error Resume Next 'This will display the current record position 'for dynasets and snapshots Data1.Caption = "Record: " & (Data1.Recordset.AbsolutePosition + 1) 'for the table object you must set the index property when 'the recordset gets created and use the following line 'Data1.Caption = "Record: " & (Data1.Recordset.RecordCount * (Data1.Recordset.PercentPosition * 0.01)) + 1End Sub

Private Sub Data1_Validate(Action As Integer, Save As Integer) 'This is where you put validation code 'This event gets called when the following actions occur Select Case Action Case vbDataActionMoveFirst Case vbDataActionMovePrevious Case vbDataActionMoveNext Case vbDataActionMoveLast Case vbDataActionAddNew Case vbDataActionUpdate Case vbDataActionDelete Case vbDataActionFind Case vbDataActionBookmark Case vbDataActionClose End Select

Page 47: Visual Basic Labmanual

Screen.MousePointer = vbHourglassEnd Sub

Output:

Result:

Thus a visual basic program has been written to design a database and tested with various samples.

Page 48: Visual Basic Labmanual

VISUAL C++

Open a new file

1.File->New2.Select MFC App (10 to 15)WizardWin32Application (16)3.Enter Project name4.Select desired Location5.Click ok6.Select “Dialog based”(10 to 15)“A simple Win32 Application”(16)7.Click Finish

To create member variables

1.Select control2.Right click and select class wizard3.Select Member variables tab4.Click Add Variable button5.Enter variable name and select variable category and type6.Click OK

Note:

As soon as the form opens up for the first time, delete whatever is in the form (buttons and text box)Here label is Static text box and text box is edit box.Drag and drop controls.To change controls properties->right click on control and select properties.To enter code, double click the button.

Press to execute

Page 49: Visual Basic Labmanual

Ex. No 11 Palindrome or Not

Aim:To write a MFC program to find whether a given string is palindrome or not using

Visual C++

Algorithm:

1. Start2. Create form as required3. Enter source code4. Stop

Controls used:Control Name Property ValueButton button1 Caption Is PalindromeButton button2 Caption Exit

Member variables:Control name Category Type Variable nameIDC_EDIT1 Value CString m_edit1

Form design:

Source code:

void CMy2Dlg::OnButton1() {CString s;UpdateData(true);s=m_edit1;s.MakeReverse();

Page 50: Visual Basic Labmanual

if(s==m_edit1)SetDlgItemText(IDC_EDIT2,m_edit1 +" is palindrome");elseSetDlgItemText(IDC_EDIT2,m_edit1 +" is not palindrome");}

void CMy2Dlg::OnButton2() {exit(0);}

Output:

Result:

Thus a win32 application has been created to display a whether a given string is palindrome or not using VC++.

Page 51: Visual Basic Labmanual

Ex. No 12 Fibonacci and Factorial

Aim:To write a MFC program to find the Fibonacci and factorial of a number using

Visual C++.

Algorithm:

1. Start2. Create form as required3. Enter source code4. Stop

Controls used:Radio Button Radio1 Caption FactorialRadio Button Radio2 Caption FibonacciList Box List1 Sort FalseButton Button1 Caption Exit

Member variables:IDC_EDIT1 Value long m_edit1IDC_LIST1 Control Clistbox m_list1

Form design:

Source code:

void CMy3Dlg::OnRadio1() {int s,a=1,i;

Page 52: Visual Basic Labmanual

char c[10];UpdateData(true);m_list1.ResetContent();s=m_edit1;for(i=1;i<=s;i++){

a=a*i;}itoa(a,c,10);m_list1.AddString(c);}

void CMy3Dlg::OnRadio2() {long s,a,b,c,i;char z[100];UpdateData(true);m_list1.ResetContent();a=-1;b=1;s=m_edit1;for(i=0;i<s;i++){

c=a+b;a=b;b=c;itoa(c,z,10);m_list1.AddString(z);

}}

void CMy3Dlg::OnButton1() {exit(0);}

Page 53: Visual Basic Labmanual

Output:

Result:

Thus a win32 application has been created to display a whether a given string is palindrome or not using VC++ .

Page 54: Visual Basic Labmanual

Ex. No 13 Matrix Multiplication

Aim:

To write a MFC program to find the multiplication of 2 matrices using Visual C++

Algorithm:

1. Start2. Create form as required3. Enter source code4. Stop

Controls used:

Button button1 Caption MultiplyButton button2 Caption Exit

Member variables:

IDC_EDIT1 Value int A1IDC_EDIT2 Value int A2IDC_EDIT3 Value int A3IDC_EDIT4 Value int A4IDC_EDIT5 Value int A5IDC_EDIT6 Value int A6IDC_EDIT7 Value int A7IDC_EDIT8 Value int A8IDC_EDIT9 Value int A9IDC_EDIT10 Value int B1IDC_EDIT11 Value int B2IDC_EDIT12 Value int B3IDC_EDIT13 Value int B4IDC_EDIT14 Value int B5IDC_EDIT15 Value int B6IDC_EDIT16 Value int B7IDC_EDIT17 Value int B8IDC_EDIT18 Value int B9

Page 55: Visual Basic Labmanual

Form design:

Source code:

void CMy4Dlg::OnButton1() {UpdateData(true);SetDlgItemInt(IDC_EDIT19,((A1*B1)+(A2*B4)+(A3*B7)));SetDlgItemInt(IDC_EDIT20,((A1*B2)+(A2*B5)+(A3*B8)));SetDlgItemInt(IDC_EDIT21,((A1*B3)+(A2*B6)+(A3*B9)));SetDlgItemInt(IDC_EDIT22,((A4*B1)+(A5*B4)+(A6*B7)));SetDlgItemInt(IDC_EDIT23,((A4*B2)+(A5*B5)+(A6*B8)));SetDlgItemInt(IDC_EDIT24,((A4*B3)+(A5*B6)+(A6*B9)));SetDlgItemInt(IDC_EDIT25,((A7*B1)+(A8*B4)+(A9*B7)));SetDlgItemInt(IDC_EDIT26,((A7*B2)+(A8*B5)+(A9*B8)));SetDlgItemInt(IDC_EDIT27,((A7*B3)+(A8*B6)+(A9*B9)));}

void CMy4Dlg::OnButton2() {exit(0);}

Page 56: Visual Basic Labmanual

Output:

Result:

Thus a win32 application has been created to perform multiplication of 2 matrices using VC++.

Ex. No 14 File Operations

Aim:To write a MFC program to copy a file using Visual C++

Algorithm:1. Start2. Create form as required3. Enter source code4. Stop

Page 57: Visual Basic Labmanual

Controls used:Button button1 caption CopyButton buttton2 caption Exit

Member variables:IDC_EDIT1 Value Cstring m_edit1IDC_EDIT2 Value Cstring m_edit2

Form design:

Source code:

void CMy5Dlg::OnButton1() {

char szbuffer[100];UINT nACTUAL=0,pos=0;CFile myfile,myfile1;UpdateData(true);myfile.Open(m_edit1,CFile::modeReadWrite);myfile.Open(m_edit2,CFile::modeCreate|CFile::modeReadWrite);while(1){

myfile.Seek(pos,CFile::begin);nACTUAL=myfile.Read(szbuffer,100);myfile.Write(szbuffer,100);pos=pos+nACTUAL;if(nACTUAL==0){

MessageBox("File Copied");exit(0);

Page 58: Visual Basic Labmanual

}}

}

void CMy5Dlg::OnButton2() {exit(0);}

Output:

Result:Thus a win32 application has been created to perform file operation using VC++.

Page 59: Visual Basic Labmanual

Ex. No 14 Mouse Interface

Aim:To write a MFC program to find the number of left and right mouse clicks using

Visual C++.

Algorithm:

1. Start2. Create form as required3. Enter source code4. StopNote:Right click on form and select eventsDouble click the followingWM_LBUTTONDBCLKWM_LBUTTONDOWNWM_RBUTTONDBLCLKWM_RBUTTONDOWN

Page 60: Visual Basic Labmanual

Controls used:Button button1 Caption Exit

Form design:

Source code:

void CMy6Dlg::OnButton1() {

exit(0);}int count1,count2;

void CMy6Dlg::OnLButtonDown(UINT nFlags, CPoint point) {

count1++;SetDlgItemInt(IDC_EDIT1,count1);

CDialog::OnLButtonDown(nFlags, point);}

void CMy6Dlg::OnLButtonDblClk(UINT nFlags, CPoint point) {

count1++;SetDlgItemInt(IDC_EDIT1,count1);

CDialog::OnLButtonDblClk(nFlags, point);}

void CMy6Dlg::OnRButtonDblClk(UINT nFlags, CPoint point) {

Page 61: Visual Basic Labmanual

count2++;SetDlgItemInt(IDC_EDIT2,count2);

CDialog::OnRButtonDblClk(nFlags, point);}

void CMy6Dlg::OnRButtonDown(UINT nFlags, CPoint point) { count2++;

SetDlgItemInt(IDC_EDIT2,count2);

CDialog::OnRButtonDown(nFlags, point);}

Output:

Result:Thus a win32 application has been created for the mouse interface using VC++.

Page 62: Visual Basic Labmanual

Ex. No 15 Active-X Controls

Aim:To write a MFC program to insert an ActvieX control using Visual C++.

Algorithm:

1. Start2. Create form as required3. Enter source code4. Stop

Note:

To insert ActiveX controlRight-click on form->Insert ActiveX Control->Calendar Control 8.0

Controls used:Button button1 caption MessageButton button2 caption Exit

Form design:

Page 63: Visual Basic Labmanual

Source code:

void CMy7Dlg::OnButton1() {

MessageBox("ActiveX Control");

}

void CMy7Dlg::OnButton2() {exit(0);}

Output:

Result:

Thus a win32 application has been created to insert a ActiveX control using VC++.

Page 64: Visual Basic Labmanual

Ex. No 16 Message Box display

Aim:To write a Win32 program to create a Message Box using Visual C++.

Algorithm:

1. Type the code in the class file(present in Globals).2. End

Source code:

#include "stdafx.h"

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ DWORD dwmemavail;

char szbuffer[80];dwmemavail=GetFreeSpace(0);wsprintf(szbuffer,"Memory aailabale: %lu",dwmemavail);MessageBox(NULL,szbuffer,"GLOBEL MEM", MB_OK);

return 0;}

Output:

Result:

Thus a win32 application has been created to display a Message-box using VC++.

Page 65: Visual Basic Labmanual

C Sharp

Ex.No. 17 PREPARE A MARKSHEET

Aim:To prepare a Mark sheet for ‘n’ students using arrays and structures in c#.

Algorithm (a):1. Declare the required fields with required size2. To get the data, create a method getdata() and get the data3. To manipulate the data, create a method putdata() and print the result4. To print the data, create a method putdata() and print the result

Algorithm (b):1. Define a structure named student2. To get the data, create a method getdata() and get the data3. To manipulate the data, create a method putdata() and print the result4. To print the data, create a method putdata() and print the result

Source code:using System;struct student{ public String name; public int rollno; public int mark1; public int mark2;}class marksheet{public static void Main(){student[] s=new student[10];int I;Console.Write(“Enter the number of students:”);string no=Console.ReadLine();int n=Convert.ToInt32(no);for(i=1;i<=n;i++){Console.Write(“Enter student{0}’s name:”,i);s[i].name=Console.ReadLine();Console.Write(“Enter student{0}’s roll no:”,i);String roll=Console.ReadLine();s[i].rollno=Convert.ToInt32(roll);Console.Write(“Enter student{0}’s 1st mark:”,i);String m1=Console.ReadLine();

Page 66: Visual Basic Labmanual

s[i].mark1=Convert.ToInt32(m1);Console.Write(“Enter student{0}’s 2nd mark:”,i);String m2=Console.ReadLine();s[i].mark2=Convert.ToInt32(m2);}for(i=1;i<=n;i++){Console.WriteLine(“\n Studentd {0}’s Marksheet”,i);Console.WriteLine(“Name:{0}”,s[i].name);Console.WriteLine(“Roll No:{0}”,s[i].rollno);Console.WriteLine(“Mark 1:{0}”,s[i].mark1);Console.WriteLine(“Mark 2:{0}”,s[i].mark2);float avg=(float)((s[i].mark1+s[i].mark2)/2);Console.WriteLine(“Average:{0}”,s[i].avg);Console.ReadLine();}}}

Output:Enter the no.of students:2Enter Student1’sname=AAAEnter student1’s roll no=111Enter student1’s mark1=80Enter student1’s mark2=70Enter Student2’sname=BBBEnter student2’s roll no=112Enter student2’s mark1=70Enter student2’s mark2=60Student1’s MarksheetName: AAARoll No: 111Mark1: 80Mark2: 70Average: 75Student2’s MarksheetName: BBBRoll No: 112Mark1: 70Mark2: 60Average: 65

ResultThus the mark sheet has been created and successfully executed using arrays and

structures in C#.

Page 67: Visual Basic Labmanual

Ex.No. 18 BANKING TRANSACTIONS

Aim:To develop a C # program to check the account balance for some ‘n’ persons

using namespace concepts.

Algorithm(a):

1. Create a namespace named compbalance 2. Under that create a class named balance, declare the variable names for balance amount and personality name and create one more method show () within the same class to the balance manipulation.3. Save the file as dllone.cs4. compile it 5. After compilation, with a new window open another file named dlltwo.cs6. Include the namespace compbalance within the dlltwo.cs using “using compbalance;”7. Within that create instance for the class addclass and given the data8. Using the method show () which is in addclass under the namespace compbalabce9. Print the result

Source Code:using System;using System.Collections.Generic;using System.Linq;using System.Text;using mymeth;

class Banking { public static void Main(string[] args) { Console.WriteLine("Banking"); Console.WriteLine("Enter the balance amount:"); String bal = Console.ReadLine(); int balance = Convert.ToInt32(bal); Console.WriteLine("Deposit or Withdraw?(1.Deposit,2.Withdraw)"); String ch = Console.ReadLine(); int choice = Convert.ToInt32(ch); switch (choice) { case 1: { deposit d = new deposit(); Console.WriteLine("enter amount to be dposited"); String dep = Console.ReadLine(); int depos = Convert.ToInt32(dep); d.depositamt(balance, depos); break;

Page 68: Visual Basic Labmanual

} case 2: { withdraw w = new withdraw(); Console.WriteLine("enter amount to be withdrawed"); String wd = Console.ReadLine(); int withd = Convert.ToInt32(wd); w.withdrawamt(balance, withd); break; } } Console.ReadLine(); } }

namespace mymeth { public class deposit { public void depositamt(int balance, int depos) { balance += depos; Console.WriteLine("Deposititamt is rs{0}", depos); Console.WriteLine("New balance is rs{0}", balance); } } }namespace mymeth{ public class withdraw { public void withdrawamt(int balance, int withd) { balance -= withd; Console.WriteLine("Withdrawnamt is rs{0}", withd); Console.WriteLine("New balance is rs{0}", balance); } } }

Output:BankingEnter the balance amount500Deposit or withdraw? <1.deposit, 2.withdraw>1Enter the amount to be deposited

Page 69: Visual Basic Labmanual

100deposit amt is Rs.100new balance is Rs.600press any key to continue……

BankingEnter the balance amount500Deposit or Withdraw? <1.deposit, 2.withdraw>2Enter the amount to be withdrawn100withdraw amt is Rs.100new balance is Rs.400press any key to continue…..

Result:Thus a account balance for some ‘n’ persons using namespace concepts has been

created and successfully executed using C#.

Page 70: Visual Basic Labmanual

Ex.No. 19 A Simple calculator using inheritance

AIM:To write a c# program to generate the operation of a simple calculator (Add, Sub,

Multiple, Divide)

ALGORITHM:

step 1:create a class for add.step 2:under that create a method to add the two no.step 3:By inheriting the class add,create a class sub.step 4:under that create a method to subtract the two no.step 5:Again by inheriting the class sub,create a class mul.step 6:create a method to multiply two no.step 7:At last,By inheriting the class mul,create a class divstep 8:create a method to divide two no.step 9:using a mainclass and main method manipulate the inherited classes.

SOURCE:

using System;using System.Collections.Generic;using System.Text;class add{ public int compute(int a, int b) { return (a + b); }}

class sub : add{ new public int compute(int a, int b) { return (a - b); }}class mul : sub{ new public int compute(int a, int b) { return (a * b); }}class div : mul{

Page 71: Visual Basic Labmanual

new public int compute(int a, int b) { return (a / b); }}class mainclass{ public static void main() { div d = new div(); Console.WriteLine("Enter 2 values for a and b"); String s = Console.ReadLine(); String t = Console.ReadLine(); int a = Convert.ToInt32(s); int b = Convert.ToInt32(t); int x = d.compute(a, b); int y = ((mul)d).compute(a, b); int z = ((sub)d).compute(a, b); int p = ((div)d).compute(a, b); Console.WriteLine("Sum:{0}", p); Console.WriteLine("Difference:{0}", z); Console.WriteLine("Product:{0}", y); Console.WriteLine("Quotient:{0}", x); Console.ReadLine(); }}

OUTPUT:

Enter 2 values for a and b:10050Sum: 150Difference: 50Product: 5000Quotient: 2

RESULT:Thus the simple calculator has been created and operations are verified using C #

program.

Page 72: Visual Basic Labmanual

Ex.No 20 Inheritance and Property

AIM:To find the area of the square, rectangle and circle using abstract classes,

inheritance and property.

ALGORITHM:

step 1:create an abstract class shape.step 2:within the class,create an abstract property area.step 3:create a class square with the inherited class shape.step 4:override the abstract property area using the keyword "override".step 5:create a class cube with the inherited class shape.step 6:override the abstract property area using the keyword "override".step 7:create a class rectangle with the inherited class shape.step 8:override the abstract property area using the keyword "override"step 9:create a mainclass and main method and manipulate the classes.

SOURCE CODE:

using System;using System.Collections.Generic;using System.Text;abstract class shape{ public string myid; public shape(string s) { myid = s; } abstract public double area { get; } public override string ToString() { return "\n The area of the " + myid + "is" + area + "sq.units"; } }class square : shape{ public int side; public square(int i, string s) : base(s) { side = i;

Page 73: Visual Basic Labmanual

} public override double area { get { return side * side; } }}class rect : shape{ public int lt, bt; public rect(int l, int b, string s) : base(s) { lt = l; bt = b; } public override double area { get { return lt * bt; } }}class mainclass{ public static void Main() { Console.WriteLine("Enter side of the square:"); string sq = Console.ReadLine(); int a = Convert.ToInt32(sq); Console.WriteLine("\n enter the length of the rectangle:"); string l1 = Console.ReadLine(); Console.WriteLine("\n enter the breadth of the rectangle:"); string b1 = Console.ReadLine(); int l = Convert.ToInt32(l1); int b = Convert.ToInt32(b1); shape[] shapes = { new square(a, "Square"), new rect(l, b, "Rectangle") }; foreach (shape s in shapes) { Console.WriteLine(s); } Console.ReadLine(); }}

Page 74: Visual Basic Labmanual

OUTPUT:Enter side of the square: 4Enter the length of the rectangle: 30Enter the breadth of the rectangle: 15The area of the square is: 16 sq.unitsThe area of the rectangle is: 450 sq.units

RESULT:

Thus the area of the square, rectangle and circle has been found using abstract classes, inheritance and Property in C#

Page 75: Visual Basic Labmanual

Ex.No 21 Interface and properties

AIM:To develop the c#program for employee details using the concept of interface and

properties.

ALGORITHM:

step 1:create an interace named Iemployee.step 2:under the interface declare the properties for an employee(for eg,name,

eno,bp,da...).step 3:create a class employee with the implementation of an interface Iemployee.step 4:Define the properties.step 5:with mainclass and method manipulate it.

SOURCE CODE:

using System;public interface details{ string name { get; set; } string no {

get;set;

}}

public interface emp{

string gross{

get;set;

}string net{

get;set;

}}

Page 76: Visual Basic Labmanual

class employ:details,emp{

private string ename;private string eno;public string name{

get{ return ename; }set{ ename=value;}

}public string name{

get{ return eno; }set{ eno=value;}

}

private string gpay; private string npay;

public string gross {

get{

return gpay;}set{

gpay=value;}

} public string net {

get{

return npay;}set{

Page 77: Visual Basic Labmanual

npay=value;}

}}

class main{

public static void Main(){

employ e=new employ();e.name="aaa";e.no="111";e.gross="5000";e.net="10000";Console.WriteLine(e.name);Console.WriteLine(e.no);Console.WriteLine(e.gross);Console.WriteLine(e.net);

}}

OUTPUT:

aaa111500010000

RESULT:Thus the employee detail has been found using the concept of interface and

properties of C#.

Page 78: Visual Basic Labmanual

Ex.No 22 Book store processing using Delegates

AIM:To write a c# program to find the damaged books in book store processing using

delegates.

ALGORITHM:step 1:create a namespace named Bookspace.step 2:within the namespace create a structure Book for the bookdetails.step 3:create a delegate for the process for book store.step 4:crfeate an array for storing the book details.step 5:create an another class within that find the total no of books and price of those books.step 6:create one more class to test wheather the book is damaged or not.step 7:print the result.

SOURCE CODE:

using System;using System.collections;namespace bookstore{

public struct book{

public string title;public string author;public string qlty;public string price;

}public delegate void bookdelegate(book b);public class bookbd{

public ArrayList a;public bookbd(){

a=new ArrayList(100);}public void addBook(){book b;Console.WriteLine("Enter book title");b.title=Console.ReadLine();Console.WriteLine("Enter the book author");b.author=Console.ReadLine();Console.WriteLine("Enter the quality of the book.(true-High qlty,false-

Low qlty)");

Page 79: Visual Basic Labmanual

b.qlty=Console.ReadLine();Console.WriteLine("Enter the price of the book");b.price=Convert.ToDouble(Console.ReadLine());Console.WriteLine("__________");a.Add(b);}public void qltycheck(bookdelegate process){

foreach(book b in a){

if(b.qlty=="true"){process(b);}}

}}

}

namespace bookprocess{

using bookstore;public class bookp{

public int count=0;public double totprice=0;public void print(book b){Console.WriteLine("The title is {0} by {1}",b.title,b.author);}public void calc(book b){ count++; totprice=totprice + b.price;}public double avg(){ return totprice/count;}

}class mainclass{ static void main() { bookdb bd=new bookbd(); do {

bd.addBook();Console.WriteLine("Do u wish to continue?(y-yes,n-no)");

Page 80: Visual Basic Labmanual

}while(Console.ReadLine()=="y" || Console.ReadLine()=="Y"); book p=new bookp(); bd.qltycheck(new bookdelegate(p.print)); bd.qltycheck(new bookdelegate(p.calc)); Console.WriteLine(" The avg price is:Rs{0:#.##}",p.avg()); }}

}

OUTPUT:

Enter the book titleC languageEnter the authorBalagurusamyEnter the quality of the book,<true-high qlty,false-Low qlty>TrueEnter the price of the book200

Do u wish to continue?<y-yes,n-no>N

The title is C language by BalagurusamyThe avg price is :Rs200Press any key to continue……..

RESULT:Thus the C # program for book store processing using Delegates has been created

and verified.

Page 81: Visual Basic Labmanual

Ex.No 23 Thread with priority using isAlive concept.

AIM:To develop a c# program for creating the threads with priority using isAlive

concept.

ALGORITHM:

step 1:create a class with constructor and pass the thread name as constructor's argument.step 2:create run function.step 3:In main method,create some threads, with priority highest.step 4:Manipulate it.

SOURCE CODE:

using System;using System.Threading;public class threads{

string name;Thread t1;public thread(string tname,int p){

name=tname;t1=new Thread(new Threadstart(run1));t1.Name=name;switch(p){case 0:{t1.Priority=ThreadPriority.Lowest;break;}case 1:{t1.Priority=ThreadPriority.BelowNormal;break;}case 2:{t1.Priority=ThreadPriority.Normal;break;}case 3:{

Page 82: Visual Basic Labmanual

t1.Priority=ThreadPriority.AboveNormal;break;}case 4:{t1.Priority=ThreadPriority.Highest;break;}}

t1.Start();}

public void run1(){try{

for(int i=1;i<=5;i++){ Console.WriteLine(name+"Priority:"+t1.Priority+"Iteration:"+i); Thread.Sleep(1000);}

}finally{

Console.WriteLine(name+" is exiting");}}

public static void Main(string[] args){

threads one=new threads("Thread 1",0);threads one=new threads("Thread 2",1);threads one=new threads("Thread 3",2);threads one=new threads("Thread 4",3);Thread t=Thread.CurrentThread;t.Priority=ThreadPriority.Highest;try{for(int i=1;i<=5;i++){

Console.WriteLine("\nMain Thread"+i);Thread.Sleep(2000);Console.WriteLine("\n Checking if thread 1 ia alive");if(one.t1.IsAlive){Console.WriteLine("Thread 1 is alive");}else{

Page 83: Visual Basic Labmanual

Console.WriteLine("Thread 1 is dead");}Console.WriteLine("\n");

}}finally{ Console.WriteLine("Main Thread Exiting");}}

}

OUTPUT:

Main Thread1Thread 4 Priority:AboveNormalIteration:1Thread 2 Priority:BelowNormalIteration:1Thread 3 Priority:NormalIteration:1Thread 1 Priority:LowestIteration:1Thread 2 Priority:BelowNormalIteration:2Thread 4 Priority:AboveNormalIteration:2Thread 3 Priority:LowestIteration:2Thread 1 Priority:NormalIteration:2

Checking if thread 1 is alive…Thread 1 is alive

Main Thread2Thread 4 Priority:AboveNormalIteration:3Thread 2 Priority:BelowNormalIteration:3Thread 3 Priority:NormalIteration:3Thread 1 Priority:LowestIteration:3Thread 2 Priority:BelowNormalIteration:4Thread 4 Priority:AboveNormalIteration:4Thread 3 Priority:LowestIteration:4Thread 1 Priority:NormalIteration:4

Checking if thread 1 is alive…Thread 1 is alive

Main Thread3Thread 4 Priority:AboveNormalIteration:5Thread 2 Priority:BelowNormalIteration:5Thread 3 Priority:NormalIteration:5Thread 1 Priority:LowestIteration:5Thread 4 is exitingThread 2 is exitingThread 3 is exiting

Page 84: Visual Basic Labmanual

Thread 1 is exiting

Checking if thread 1 is alive…Thread 1 is alive

Main Thread4

Checking if thread 1 is alive…Thread 1 is alive

Main Thread5

Checking if thread 1 is alive…Thread 1 is dead

Main Thread is exiting

RESULT:

Thus the C# program has been to developed and found the threads with priority using is Alive concept.

Page 85: Visual Basic Labmanual

. NET

Ex.No.24 To read the password and display

Aim:To develop a win form for manipulation of the text.

Procedure:

1. Type the required program first in c# and save it.2. Compile it to create the dll file.3. start->programs->Microsoft VisualStudio.Net7.0->Microsoft VisualStudio.Net7.0(2).4. In the screen,click File->New->project.5. In the screen,select windows application.6. Design the form depend on your need.7. Set the properties.8. Add the dll to the project.9. Now, write the coding for the corresponding control to activate the form.

SOURCE CODE:

using System;using System.Windows.Forms;public class WinForm:Form{TextBox t1,t2,t3;Button b1;Public WinForm(){t1=new TextBox();t1.Size=new System.Drawing.Size(150,40);t1.Location=new System.Drawing.Point(100,50);t1.AcceptsTab=true;t1.Multline=true;t1.ScrollBars=ScrollBars.Vertical;t2=new TextBox();t2.Size=new System.Drawing.Size(150,40);t2.Location=new System.Drawing.Point(100,120);t2.CharacterCasing=System.Windows.Forms.CharacterCasing.Upper;t3=new TextBox();t3.Size=new System.Drawing.Size(150,40);t3.Location=new System.Drawing.Point(100,200);t3.PASSWORDchar=’$’;b1=new Button();b1.Size=new System.Drawing.Size(50,20);b1.Location=new System.Drawing.Point(100,200);

Page 86: Visual Basic Labmanual

b1.Text=”click me”;this.Controls.Add(t1);this.Controls.Add(t2);this.Controls.Add(t3);this.Controls.Add(b1);b1.Click+=new EventHandler(OnClick);}public void OnClick(Object o,EventArgs e){MessageBox.Show(“Your password is:”+t3.Text);}}class MainClass{public static void Main(){Applicaton.Run(new WinForm());}}

OUTPUT:

RESULT:

Thus the c# program for the manipulation of the text has been created and verified.

Page 87: Visual Basic Labmanual

Ex.No 25 To show which button has been clicked

AIM:To develop a winform for manipulation of the toolbar.

PROCEDURE:

1.Type the required program first in c# and save it.2.compile it to create the dll file.3.start->programs->Microsoft VisualStudio.Net7.0->Microsoft VisualStudio.Net7.0(2).4.In the screen,click File->New->project.5.In the screen,select windows application.6.Design the form depend on your need.7.Set the properties.8.Add the dll to the project.9.Now,write the coding for the corresponding control to activate the form.

SOURCE CODE:

using System;using System.Windows.Forms;class Winform:Form{Winform(){ToolBar tb=new ToolBar();ToolBarButton cut=new ToolBarButton();ToolBarButton copy=new ToolBarButton();ToolBarButton paste=new ToolBarButton();

cut.Text="cut";copy.Text="copy";paste.Text="paste";tb.Buttons.Add(cut);tb.Buttons.Add(copy);tb.Buttons.Add(paste);this.Controls.Add(tb);this.Text="ToolBar Example";tb.ButtonClick +=new ToolBarButtonClickEventHandler(OnClick);}public void OnClick(Object o,ToolBarButtonClickEventArgs e){if(e.Button.Text=="cut")MessageBox.Show("Cut is Clicked");elseif(e.Button.Text=="copy")

Page 88: Visual Basic Labmanual

MessageBox.Show("Copy is Clicked");elseif(e.Button.Text=="paste")MessageBox.Show("Paste is Clicked");elseMessageBox.Show("No Button are clicked");}

public static void Main(){ Application.Run(new Winform());}}

OUTPUT:

RESULT:

Thus the C# program for manipulation of the toolbar has been created and verified.