FACULTY OF ENGINEERING AND TECHNOLOGY

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

M.Sc (INFORMATION TECHNOLOGY) INTEGRATED SEMESTER – VII IITP 75: VISUAL PROGRAMMING NAME

: ……………………………………………………………………

REG NO : …………………………………………………………………....

1

ANNAMALAI

UNIVERSITY

FACULTY OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

M.Sc (INFORMATION TECHNOLOGY) INTEGRATED SEMESTER – VII

IITP 75: VISUAL PROGRAMMING

CERTIFICATE Certified that this is a Bonafide record of work done

by

Mr./Ms…………………………………………………………………… Reg.No……………………………….…………… of M.Sc (Information Technology)

Integrated

course

in

the

IITP

75:

VISUAL

PROGRAMMING during the year June 2014 to November 2014. Staff in Charge

Internal Examiner

External Examiner

Place: Annamalai Nagar Date: ……………….… 2

Annamalai University Department of Computer Science and Engineering M.Sc (Information Technology) VII Semester IITP 75 – VISUAL PROGRAMMING LAB Lab in - charge:

LIST OF EXPERIMENTS

MR.D.VENKATASEKHAR

VISUAL BASIC 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.

Computation of Simple and Compound Interest. Using Text box, Label and Command buttons String Operations Using String Functions, Input box and Command buttons Designing a Scientific Calculator Using Control array on Command buttons and Math Functions Numerical Operations by creating Menu Interface Using Menu Editor (Arithmetical, Relational & Logical) Working With Different Controls – I a. Radio Button control b. List Box control c. Scroll bars Working With Different Controls – II a. MS Chart control b. List View control c. File System control Working With Different Controls – III a. Animation control b. Image list control c. Common dialog box Simulation of Simple Text Editor Using Combo box, Menu, Common Dialog and Rich text box control Student data base using MS Flex Grid Control Using MS Flex Grid (with sorting and query models) Mouse events a. Free Hand Writing b. Drag and Drop Create a Banner using Timer Control Accessing of Database Using Data Control DAO Accessing of Database Using ADO Creation of an Embedded object Creation of an Active-X Control File maintenance package using MDI Mark Sheet Preparation using Data Report Creation of Chat application using WinSock Control VISUAL C++

19. 20. 21. 22. 23. 24. 25.

Palindrome or not Fibonacci and factorial Using Edit box, Static Text, List box and Radio Buttons Matrix Multiplication Using Edit, Buttons and Member Functions File operations Mouse interface Active X Control Message Box Display 3

CONTENTS VISUAL BASIC S. No. 1. 2. 3. 4.

5.

6.

7.

8.

DATE

TITLE

PAGE No. SIGNATURE

Computation of Simple and Compound Interest. Using Text box, Label and Command buttons String Operations. Using String Functions, Input box and Command buttons Designing a Scientific Calculator. Using Control array on Command buttons and Math functions Numerical Operations by Creating Menu. Using Menu Editor (Arithmetic, Relational & Logical Operations) Working with different Controls – I a. Radio button control b. List box control c. Scroll bars Working with different Controls – II a. MS Chart control b. List View control c. File System control Working with different Controls – III a. Animation control b. Image List control c. Common dialog box Simulation of Simple Text Editor. Using Combo box, Menu, Common dialog and Rich Text box control

9.

Quiz program using MS Flex Grid Control.

10.

Mouse events. a. Free hand writing b. Drag and drop

11.

Create a Banner using Timer Control.

12.

Accessing of Database using Data Control DAO. 4

13.

Accessing of Database using ADO.

14.

Creation of an Embedded object.

15.

Creation of an Active-X Control.

16.

Text files maintenance using MDI.

17.

Student Information using Data Report.

18.

Creation of Chat application using WinSock Control.

VISUAL C++ 19.

Palindrome or not.

20.

Fibonacci and Factorial. Using Edit box, Static Text, List box and Radio buttons

21.

Matrix Multiplication. Using Edit, Buttons

22.

File Operations.

23.

Mouse Interface.

24.

Active - X Control.

25.

Message Box Display.

5

Questions 1. Create four text boxes, to get the inputs for Principal, Rate of Interest, Time Period and Last one to display the Output. Create two command buttons, to calculate and display simple interest and compound interest on pressing them respectively, another one command button to Exit. Write a VB code to calculate the simple and compound interest.

2. Create two text boxes, for getting the input string and another one to display the result. Create command buttons for the String operations (Length, Upper, Lower, Compare, Concatenation, Finding the sub string, First occurrence of a letter, Reversing a String, Replacing a sub string). On clicking the command button the corresponding operation should be performed. While selecting the option get the required secondary strings and characters using “Input box”. Write a VB code to perform string operations. 3. Create two text boxes, one for display the expression and the other to display the current result. Create a control array for the command buttons (0-9). Use the math function for sin, cosine, tangent, square root, and log. And use your own function to calculate x2, x3, xy, 10x and factorial. Write a VB code to create the scientific calculator.

4. Create three text boxes, two for getting inputs and one for displaying outputs. By using menu editor create four menus namely Arithmetic, Logical, Relational and Exit. Perform operations under arithmetic list addition, subtraction, multiplication, division, modulo, under Logical and, or, not, under Relational lesser, equal and greater. Write a VB code for Numerical operations using menu interfacing.

6

5.

1) Create a text box, three option buttons and one command button, write a code to convert the number between three Data types (Decimal, Hex & Octal). On clicking next it will go to another form. 2) Create two text boxes, one for getting principle amount as input and other to display result. By using two H_Scroll bars give the value of time period and rate of interest. For time period the interval is 1 to 10 by incrementing by 1. For rate of interest the interval is 0.25 to 24 by incrementing by 0.25. By varying the value of period and interest produce the result for simple interest. 3) Create a combo box and two list boxes, display the list of few books titles by book wise (subject) and author wise using combo box. List out the subjects or authors in list box1, and by selecting the subject list out the book’s title wrote by the author or related to the subject. 6. Create a drive list box, dir list box, file list box, list view box and three command buttons. The changes made in the dir list box and drive list box should make a change on file list box. On clicking the list button, on the list view box it will display the filenames on the dir with some icons. On clicking the chart button, get three values from user through input box and display a pie chart (replace the list view box). Write a VB Code for the file system control.

7. Create a rich text box, command buttons and toolbar using common controls and image list control. On pressing open and save button if must do the corresponding operations using common dialog box control. Then on saving it must to animate (like on form2) using animation control for few seconds.

7

8. Create a text notepad model using menu (file -> open, save, save as, print, exit; Edit -> cut, copy, paste; Format -> bold, italic, underline, strike through). By using two combo boxes change the size and face of the text. Use common dialog box control for the dialog boxes. Write a VB Code to create a simple notepad.

9.

Create three labels, four option buttons and two command buttons as shown in form1. Create two flex grids, combo box with choices of All, A, B, C, D, All Correct and All Wrong and a command button to exit. On start Load ten questions on grid1 and display it one by one on form1. After getting the answers for ten questions display the form2 with grid and right answers. By using the combo box make query on the answers and filter the results with the help of grid2. Write a VB Code to create a quiz program. 10. Create a frame and picture box and two command buttons as shown in form layout. If we drag on the picture box then draw on the picture box surface and when we click and drag on the frame then the picture box and frame move along the way of dragging. Create a VB Code to working with the mouse events. 11. By using of timers and label, crate a banner which goes to and fro, marquee on both sides (left to right and right to left) randomly. Write a VB Code to display a Banner.

8

12. Create 10 labels, 10 textboxes and 5 command boxes and a data control. Using DAO and command buttons we have to perform add, delete, refresh, update and close operation. Write a VB Code to perform Data Operations using DAO

13. Create 10 labels, 10 textboxes and 5 command boxes and Active-x Data Control. Using ADO and command buttons we have to perform add, delete, refresh, update and close operation. Write a VB Code to perform Data Operations using DAO

14. Create an OLE OBJECTS namely MS-PAINT, MSWORD, MS-EXCEL, MS-POWERPOINT. Create the Menu for the corresponding OLE Objects. On clicking the OLE objects or Menu the application should invoke.

15. Create a user defined USER DEFINED CONTROL by using one label and two timers and make the OCX file. Using the Active-X Object and mouse control make main program. Write a VB Code to create a USER DEFINED ACTIVE–X Control. 16. Create a MDI application for the Text Editor by using the controls Menus, Toolbar, Common Dialog Box, Image List Box, and Status Bar. Write the VB codes for the operations on the on the Editor.

9

17. Create a database for student transferring details (Roll. No., Name, Course, Branch, Semester, Batch, Add/Delete, Date) using DAO and make a Data Report using data environment. Write a VB code to Show the Data Report for Student Details. 18. Create a host form and receiver forms as shown in the figure using a win-sock control connect the two forms. Write a VB Code to Create a Chat Application.

19. Write a MFC Program to create two textboxes, command buttons one for getting inputs and another to display outputs and clicking one command button display whether the string is palindrome or not and another to exit

20. Write a MFC Program to create a textbox, list box and two radio buttons. On clicking one radio button display factorial for the value in textbox, On clicking another radio button display Fibonacci series for the value in textbox.

21. Write a MFC Program to create 27 textboxes, 18 used to get the input of two matrices and excess to display the multiplication of two matrices. On clicking the command button display the output.

22. Write a MFC Program to create two textboxes and command buttons, Get the source and destination file names. On clicking the command button make a copy of the source file to destination.

10

23. Write a MFC Program to create two textboxes for displaying the number of left clicks and number of right clicks. On clicking on the empty space increase the count on the corresponding textboxes.

24. Write a MFC Program to create Active-X control Object.

25. Write a Win32 application to create a Message Box window.

11

Ex. No. 1 Aim:

Computation of Simple and Compound Interest To write a Visual Basic Program to compute simple and compound interest.

Form Design:

Controls Used: Label, Textbox, Command Button Changes in Properties: Control Name Label Label1 Label Label2 Label Label3 Label Label4 Text Box Text1 Text Box Text2 Text Box Text3 Text Box Text4 Command Command1 Command Command2 Command Command3 Events:

Command:

Property Caption Caption Caption Caption Text Text Text Text Caption Caption Caption

Value Principle Rate of interest Time Period Result

Simple Compound Exit

Click.

Procedure: 1. Place the controls as shown in the Form layout. 2. By clicking the simple and compound command buttons, display simple interest and compound interest for the given inputs available in the text boxes respectively.

12

Source Code: Private Sub Command1_Click() Text4.Text = (Val(Text1.Text) * Val(Text2.Text) * Val(Text3.Text)) / 100 End Sub Private Sub Command2_Click() Text4.Text = Val(Text1.Text) * ((1 + (Val(Text2.Text) / 100)) ^ Val(Text3.Text)) End Sub Private Sub Command3_Click() End End Sub Output:

Result:

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

13

Ex. No. 2 Aim:

String Operations

To write a Visual Basic program to perform String Operations.

Form Design:

Controls Used: Label, Textbox, Command Button Changes in Properties: Control Name Label Label1 Label Label1 Text Box Text1 Text Box Text2 Command Command1 Command Command2 Command Command3 Command Command4 Command Command5 Command Command6 Command Command7 Command Command8 Command Command9 Command Command10 Events:

Property Caption Caption Text Text Caption Caption Caption Caption Caption Caption Caption Caption Caption Caption

Value Enter a string Result Length Upper Lower Compare Concat Find Sub Str Occurrence Reverse Replace Exit

Command: Click

Variables Declared: Global declaration: S as String Local declaration: X, I as Integer Procedure: 1. Place the labels, command buttons and text boxes as shown in form layout. 2. On clicking the command buttons, perform the string operations Length, Upper, Lower, Compare, Find Sub-String, Reverse, Replace using the string functions LCase(), Ucase(), strcomp(), Instr(), strreverse(), replace() respectively. 14

3. Get the necessary strings and characters using “Input Box” control. 4. Use the special character ‘&’ to concatenate the two strings and a user defined function to find the number of occurrences of a given character. Source Code: Dim s As String Private Sub Command1_Click() Text2.Text = StrReverse(Text1.Text) End Sub Private Sub Command10_Click() End End Sub Private Sub Command2_Click() Dim x, i As Integer i=0 x=1 s = InputBox("Enter a Char to find No. of Occurences") Do Text2.Text = InStr(x, Text1.Text, s) i=i+1 x = Val(Text2.Text) + 1 Loop While x 1 Text2.Text = i - 1 End Sub Private Sub Command3_Click() s = InputBox("Enter a SubString to Concat") Text2.Text = Text1.Text & " " & s End Sub Private Sub Command4_Click() Text2.Text = UCase(Text1.Text) End Sub Private Sub Command5_Click() Text2.Text = LCase(Text1.Text) End Sub Private Sub Command6_Click() Text2.Text = Len(Text1.Text) End Sub Private Sub Command7_Click() Dim x As Integer s = InputBox("Enter a String to Compare") x = StrComp(Trim(Text1.Text), Trim(s)) If x = 0 Then Text2.Text = "Both are Equivalent" 15

Else Text2.Text = "Both are not Equivalent" End If End Sub Private Sub Command8_Click() s = InputBox("Enter a SubString to Find") Text2.Text = InStr(1, Text1.Text, s) If Val(Text2.Text) 0 Then Text2.Text = "Substring Found." End Sub Private Sub Command9_Click() Dim x As String s = InputBox("Enter a SubString to Search") x = InputBox("Enter a SubString to Replace") Text2.Text = Replace(Text1.Text, s, x) End Sub Output:

Result:

Thus a visual basic program has been written to Perform String operations is implemented and tested with various samples.

16

Ex. No. 3 Aim:

Designing a Scientific Calculator

To create a Scientific Calculator using Control Arrays using Visual Basic Environment.

FormDesign:

Controls Used: Textbox, Command Button Changes in Properties: Control Name Text Box Text1 Text Box Text2 Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command Command 11 Command Command 12 Command Command 13 Command Command 14 Command Command 15 Command Command 16 Command Command 17 Command Command 18 Command Command 19 Command Command 20 Command Command 21 Command Command 22 Command Command 23 Command Command 24

Property Text Text Caption, Index Caption, Index Caption, Index Caption, Index Caption, Index Caption, Index Caption, Index Caption, Index Caption, Index Caption, Index Caption Caption Caption Caption Caption Caption Caption Caption Caption Caption Caption Caption Caption Caption

Value 0, 0 1, 1 2, 2 3, 3 4, 4 5, 5 6, 6 7, 7 8, 8 9, 9 CE = x^2 x^3 x^y N! % OFF + SIN COS * TAN 17

Command Command Command Command

Command 25 Command 26 Command 27 Command 28

Caption Caption Caption Caption

/ SQRT 10^x Log

Event:

Command: Click Variables Used: Global Declaration: Num1, pre, count1, s as long User defined functions: Fact(), Calculate(pre) Procedure: 1. Place the commands and text boxes as shown in the form layout. 2. For creating control array, create a command button named as command then copy the button and then paste it. It will ask a question that “you wish to create a control array” click on yes, then paste no. of buttons you need. 3. Use the predefined function sin(), cos(), tan(), sqr() and log() for the operations sine, cosine, tangent, square root and logarithm. 4. Use the user defined function fact() to calculate the factorial of a number 5. Use the user defined function calculate() to perform all the arithmetic operations depending upon the priority in the variable ‘pre’ (pre is the operation to be performed after entering the second operand). 6. For each click on the command button with caption 0-9, display the content in the textbox2 with the corresponding caption value. 7. For each click on operator button, append the contents of textbox2 to the textbox1 with corresponding operator. 8. After entering the second operand store/display the temporary result in text2. Source Code: 'pre var: 1- add 2-sub, 3-mul 4-div 5-x^y 6- equ 7-mod Dim num1, pre, count1 As Long Dim s As Long Private Sub Command_Click(Index As Integer) Text1.Text = Val(Text1.Text) * 10 + Command(Index).Caption End Sub Private Sub Command11_Click() Text1.Text = "" Text2.Text = "" count1 = pre = 0 End Sub Private Sub Command12_Click() Text2.Text = Text2.Text + Text1.Text calc (pre) pre = 6 Text1.Text = num1 End Sub Private Sub Command13_Click() Text1.Text = Val(Text1.Text) ^ 2 End Sub 18

Private Sub Command14_Click() Text1.Text = Val(Text1.Text) ^ 3 End Sub Private Sub Command15_Click() If pre = 6 Then Text2.Text = "" End If Text2.Text = Text2.Text + Text1.Text + " ^ " If count1 = 0 Then num1 = Val(Text1.Text) Text1.Text = "" pre = 5 count1 = 1 Else calc (pre) Text1.Text = "" pre = 5 End If End Sub Private Sub Command16_Click() Dim a As Integer a = num1 num1 = Val(Text1.Text) fact (num1) Text1.Text = s num1 = a End Sub Private Sub Command17_Click() If pre = 6 Then Text2.Text = "" End If Text2.Text = Text2.Text + Text1.Text + " % " If count1 = 0 Then num1 = Val(Text1.Text) Text1.Text = "" pre = 7 count1 = 1 Else calc (pre) Text1.Text = "" pre = 7 End If End Sub Private Sub Command18_Click() End End Sub Private Sub Command19_Click() If pre = 6 Then Text2.Text = "" End If Text2.Text = Text2.Text + Text1.Text + " + " 19

If count1 = 0 Then num1 = Val(Text1.Text) Text1.Text = "" pre = 1 count1 = 1 Else calc (pre) Text1.Text = "" pre = 1 End If End Sub Private Sub Command20_Click() Dim a As Integer a = num1 num1 = Val(Text1.Text) * 3.14159265358979 / 180 Text1.Text = Sin(num1) num1 = a End Sub Private Sub Command21_Click() If pre = 6 Then Text2.Text = "" End If Text2.Text = Text2.Text + Text1.Text + " - " If count1 = 0 Then num1 = Val(Text1.Text) Text1.Text = "" pre = 2 count1 = 1 Else calc (pre) Text1.Text = "" pre = 2 End If End Sub Private Sub Command22_Click() Dim a As Integer a = num1 num1 = Val(Text1.Text) * 3.14159265358979 / 180 Text1.Text = Cos(num1) num1 = a End Sub Private Sub Command23_Click() If pre = 6 Then Text2.Text = "" End If Text2.Text = Text2.Text + Text1.Text + " * " If count1 = 0 Then num1 = Val(Text1.Text) 20

Text1.Text = "" pre = 3 count1 = 1 Else calc (pre) Text1.Text = "" pre = 3 End If End Sub Private Sub Command24_Click() Dim a As Integer a = num1 num1 = Val(Text1.Text) * 3.14159265358979 / 180 Text1.Text = Tan(num1) num1 = a End Sub Private Sub Command25_Click() If pre = 6 Then Text2.Text = "" End If Text2.Text = Text2.Text + Text1.Text + " / " If count1 = 0 Then num1 = Val(Text1.Text) Text1.Text = "" pre = 4 count1 = 1 Else calc (pre) Text1.Text = "" pre = 4 End If End Sub Private Sub Command26_Click() Dim a As Integer a = num1 num1 = Val(Text1.Text) Text1.Text = Sqr(num1) num1 = a End Sub Private Sub Command27_Click() Text1.Text = 10 ^ Val(Text1.Text) End Sub Private Sub Command28_Click() Dim a As Integer a = num1 num1 = Val(Text1.Text) Text1.Text = Log(num1) 21

num1 = a End Sub

' Public Function Public Sub calc(pre) Select Case pre Case 1 num1 = num1 + Val(Text1.Text) Case 2 num1 = num1 - Val(Text1.Text) Case 3 num1 = num1 * Val(Text1.Text) Case 4 If Val(Text1.Text) = 0 Then MsgBox "Divide by Zero Error" num1 = 0 Else num1 = num1 / Val(Text1.Text) End If Case 5 num1 = num1 ^ Val(Text1.Text) Case 6 num1 = num1 Case 7 num1 = num1 Mod Val(Text1.Text) End Select End Sub Public Sub fact(num1) Dim X As Integer s=1 For X = 1 To num1 s=s*X Next X num1 = s End Sub Output:

Result: 22

Thus a visual basic program has been written to build a Scientific Calculator is implemented and tested with various samples. Ex. No. 4 Arithmetic operations using menu Aim: To create a visual basic program to perform arithmetic operations using menu. Form Design:

Controls Used: Textbox, Menu Changes in Properties: Control Name Text Box Text1 Text Box Text2 Text Box Text3 Label label1 Label label2 Label label3

Property Text Text Text caption caption caption

Value

Enter the first operand Enter the second operand result

Procedure: 1. Place the text boxes and labels 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 four menu items with lists as shown below Menu Sub-Menu Caption Caption Name Arithmetic Add ArithAdd Sub ArithSub Mul Arithmul Div ArithDiv Logical and And Or Or Not Not Relational Lesser Lesser Equal Equal Greater Greater 5. Display the result for the user values in the corresponding text box. Source Code: Private Sub Arithadd_Click() 23

Text3.Text = Val(Text1.Text) + Val(Text2.Text) End Sub Private Sub Arithdiv_Click() If Val(Text2.Text) = 0 Then MsgBox "Divide by zero ERROR" Else Text3.Text = Val(Text1.Text) / Val(Text2.Text) End If End Sub Private Sub Arithmod_Click() If Val(Text2.Text) = 0 Then MsgBox "Divide by zero ERROR" Else Text3.Text = Val(Text1.Text) Mod Val(Text2.Text) End If End Sub Private Sub Arithmul_Click() Text3.Text = Val(Text1.Text) * Val(Text2.Text) End Sub Private Sub Arithsub_Click() Text3.Text = Val(Text1.Text) - Val(Text2.Text) End Sub Private Sub Exit_Click() End End Sub Private Sub not_Click() Text3.Text = Not Val(Text1.Text) End Sub Private Sub or_Click() Text3.Text = Val(Text1.Text) Or Val(Text2.Text) End Sub Private Sub and_Click() Text3.Text = Val(Text1.Text) And Val(Text2.Text) End Sub Private Sub Releq_Click() If Val(Text1.Text) = Val(Text2.Text) Then Text3.Text = True Else Text3.Text = False End If End Sub 24

Private Sub Relgr_Click() If Val(Text1.Text) > Val(Text2.Text) Then Text3.Text = Val(Text1.Text) Else Text3.Text = Val(Text2.Text) End If End Sub Private Sub Relless_Click() If Val(Text1.Text) < Val(Text2.Text) Then Text3.Text = Val(Text1.Text) Else Text3.Text = Val(Text2.Text) End If End Sub Output:

Result:

Thus a visual basic program has been written to perform arithmetic, relational and logical operations using menu is implemented and tested with various samples.

25

Ex. No.5: Aim: I

Working with controls – I [Option buttons, Scroll bar, List box]

To write a Visual basic program to work with option, scroll and list box controls Usage of Option buttons Form Design:

Controls Used: Label, Textbox, Command Button, Option button, Frame Changes in Properties: Control Name Property Option button Option1 Caption Option button Option2 Caption Option button Option3 Caption Command button Command1 Caption

Value Hex Decimal Octal Next

Methods & Events: Option Value Text Text Command Click Procedure: 1. Place a Command button, text box, and three option buttons within a Frame as shown in the form layout. 2. Using the math functions Format(), Hex(), Oct() to convert from one system to another system. 3. By selecting the corresponding option, the respective value should be displayed. II Usage of scroll bar Form Design:

Controls Used: Label, Textbox, Command Button, Scroll bar Changes in Properties: Control Scroll bar Scroll bar Scroll bar Scroll bar

Name Scroll1 Scroll1 Scroll2 Scroll2

Property Min Max Min Max

Value 1 10 1 96 26

Command button

command1

Caption

back

Methods & events : Scroll: value Procedure: 1. Place text boxes, horizontal scroll bars, and a command button as shown in t he form layout. 2. The first scroll bar represents the time period with range from 1-10, increasing by 1 value per scroll 3. The second scroll bar represents the time period with range from 0.25-24, increasing by 0.25 value per scroll 4. The result should be displayed in the text box for the change in the user values. III Usage of Combo box and List box Form Design:

Controls Used: Label, Command Button, List box, Combo box Changes in Properties: Control Name Property List Box list1 Item List Box list2 Item Command button command1 Caption Methods and Events: Combo additem, click List change( ), text, additem, clear

Value back

Procedure: 1. Place a Combo box, list box and command button as shown in the form layout. 2. By selecting the combo box, display the corresponding authors or subjects name, in listbox1. 3. By selecting the authors or subjects available in the listbox1, display the corresponding book titles in listbox2. Main Form 1. To select the required control, click the corresponding command button in the main form. Methods and events Form : load, unload

27

Source Code: Main Form: Private Sub Command1_Click() Form1.Show mainfrm.Hide End Sub Private Sub Command2_Click() Form2.Show mainfrm.Hide End Sub Private Sub Command3_Click() Form3.Show mainfrm.Hide End Sub Private Sub Command4_Click() End End Sub

Form1:

Private Sub Form_Load() Unload Form1 Unload Form2 Unload Form3 End Sub Dim num1 As Integer Private Sub Command1_Click() mainfrm.Show Unload Form1 End Sub Private Sub Form_Load() Option2.Value = True mainfrm.Show End Sub Private Sub Option1_Click() Text1.Text = Hex(num1) End Sub Private Sub Option2_Click() Text1.Text = Format(num1) End Sub Private Sub Option3_Click() Text1.Text = Oct(num1) End Sub Private Sub Text1_Change() If Option3.Value = True Then num1 = Val("&O" & LTrim(Text1.Text) & "&") 28

Form2:

ElseIf Option1.Value = True Then num1 = Val("&H" & LTrim(Text1.Text) & "&") ElseIf Option2.Value = True Then num1 = Val(LTrim(Text1.Text) & "&") End If End Sub Private Sub Command1_Click() mainfrm.Show Unload Form2 End Sub Private Sub Form_Load() Label4.Caption = HScroll1.Value Label5.Caption = HScroll2.Value / 4 End Sub Private Sub HScroll1_Change() Label4.Caption = HScroll1.Value Text2.Text = (Val(Text1.Text) * HScroll1.Value * (HScroll2.Value / 4)) / 100 End Sub Private Sub HScroll2_Change() Label5.Caption = HScroll2.Value / 4 Text2.Text = (Val(Text1.Text) * HScroll1.Value * (HScroll2.Value / 4)) / 100 End Sub

Form3:

Private Sub Text1_Change() Text2.Text = (Val(Text1.Text) * HScroll1.Value * (HScroll2.Value / 4)) / 100 End Sub Private Sub Combo1_Click() If Combo1.Text = "Book Wise" Then List1.Clear List1.AddItem "C", 0 List1.AddItem "C++", 1 List1.AddItem "Java", 2 List1.AddItem "Oracle", 3 List1.AddItem "Visual Basic", 4 ElseIf Combo1.Text = "Author Wise" Then List1.Clear List1.AddItem "Al Stevens" List1.AddItem "Dan Appleman" List1.AddItem "Ivan Bayross" List1.AddItem "Peter H. Salus" List1.AddItem "Robert Lafore" List1.AddItem "Steven Holzner" List1.AddItem "Wayne S Freeze" List1.AddItem "Yashavant Kanetkar" End If End Sub 29

Private Sub Command1_Click() mainfrm.Show Unload Form3 End Sub Private Sub Form_Load() Combo1.AddItem ("Book Wise") Combo1.AddItem ("Author Wise") End Sub Private Sub List1_Click() If List1.Text = "C" Then List2.Clear List2.AddItem "C Column Collection" List2.AddItem "C Pearls" List2.AddItem "C Programming with Example" List2.AddItem "C Projects" List2.AddItem "Data Structures Through C" List2.AddItem "Exploring C" List2.AddItem "Graphics under C" List2.AddItem "Let Us C Solutions" List2.AddItem "Test Your C Skills" List2.AddItem "Understanding Pointers in C" List2.AddItem "Working with C" List2.AddItem "Writing TSRs Through C" List2.AddItem "C with Assembly Language" List2.AddItem "Turbo C Memory-Resident Utilities, Screen I/O and Programming Techniques" List2.AddItem "C Data Base Development" ElseIf List1.Text = "C++" Then List2.Clear List2.AddItem "C++ Database Development" List2.AddItem "Teach Yourself C++" List2.AddItem "C Programming Using Turbo C++" List2.AddItem "C++ Interactive Course" List2.AddItem "Handbook of Programming Languages Vol I: Object-Oriented Languages" List2.AddItem "Visual C++ 6 In Record Time" List2.AddItem "Microsoft Visual C++ 5: No Experience Required" List2.AddItem "Let Us C++" List2.AddItem "C++ Programming With Example" List2.AddItem "Test Your C++ Skills" List2.AddItem "Visual C + Programming" List2.AddItem "Visual C + Projects" ElseIf List1.Text = "Java" Then List2.Clear List2.AddItem "Data Structures and Algorithms in Java" List2.AddItem "Java Workshop Programming" List2.AddItem "Mastering Visual J++" List2.AddItem "Visual J++ 1.1 : No Experience Required" 30

ElseIf List1.Text = "Oracle" Then List2.Clear List2.AddItem "Commercial application development using Oracle Developer 2000" List2.AddItem "Commercial Applications Development Using Oracle Developer 2000 Forms 5.0" ElseIf List1.Text = "Visual Basic" Then List2.Clear List2.AddItem "Developing COM/ActiveX Components with Visual Basic 6" List2.AddItem "Visual Basic 5.0 Programmers Guide To The Win32 API" List2.AddItem "Advanced VB 6 Projects " List2.AddItem "Visual Basic Projects" List2.AddItem "Visual Basic Developer's Guide to COM and COM+" List2.AddItem "Expert Guide to Visual Basic 6" List2.AddItem "VC Gems" ElseIf List1.Text = "Al Stevens" Then List2.Clear List2.AddItem "C Data Base Development" List2.AddItem "C++ Database Development" List2.AddItem "Teach Yourself C++" List2.AddItem "Turbo C Memory-Resident Utilities, Screen I/O and Programming Techniques" ElseIf List1.Text = "Dan Appleman" Then List2.Clear List2.AddItem "Developing COM/ActiveX Components with Visual Basic 6" List2.AddItem "Visual Basic 5.0 Programmers Guide To The Win32 API" ElseIf List1.Text = "Ivan Bayross" Then List2.Clear List2.AddItem "Advanced VB 6 Projects " List2.AddItem "Commercial application development using Oracle Developer 2000" List2.AddItem "Commercial Applications Development Using Oracle Developer 2000 Forms 5.0" ElseIf List1.Text = "Peter H. Salus" Then List2.Clear List2.AddItem "H P L Vol. III Little Languages & Tools" List2.AddItem "Handbook of Programming Languages Vol I: Object-Oriented Languages" List2.AddItem "Handbook of Programming Languages Vol II: Imperative Programming Languages" List2.AddItem "Handbook of Programming Languages Vol IV: Functional and Logic Programming Languages" ElseIf List1.Text = "Robert Lafore" Then List2.Clear List2.AddItem "C Programming Using Turbo C++" List2.AddItem "C++ Interactive Course" List2.AddItem "Data Structures and Algorithms in Java" 31

ElseIf List1.Text = "Steven Holzner" Then List2.Clear List2.AddItem "Visual Basic Projects" List2.AddItem "Java Workshop Programming" List2.AddItem "C with Assembly Language" List2.AddItem "Mastering Visual J++" List2.AddItem "Microsoft Visual C++ 5: No Experience Required" List2.AddItem "Visual C++ 6 In Record Time" List2.AddItem "Visual J++ 1.1 : No Experience Required" ElseIf List1.Text = "Wayne S Freeze" Then List2.Clear List2.AddItem "Visual Basic Developer's Guide to COM and COM+" List2.AddItem "Expert Guide to Visual Basic 6" ElseIf List1.Text = "Yashavant Kanetkar" Then List2.Clear List2.AddItem "C Column Collection" List2.AddItem "C Pearls" List2.AddItem "C Programming with Example" List2.AddItem "C Projects" List2.AddItem "C++ Programming With Example" List2.AddItem "Data Structures Through C" List2.AddItem "Data Structures Through C++" List2.AddItem "Exploring C" List2.AddItem "Graphics under C" List2.AddItem "Introduction to Object Oriented Programming & C++" List2.AddItem "Let Us C Solutions" List2.AddItem "Let Us C++" List2.AddItem "Programming Expertise in Basic" List2.AddItem "Programming Expertise in BASIC" List2.AddItem "Test Your C Skills" List2.AddItem "Test Your C++ Skills" List2.AddItem "Understanding Pointers in C" List2.AddItem "VC Gems" List2.AddItem "Visual C + Programming" List2.AddItem "Visual C + Projects" List2.AddItem "Working with C" List2.AddItem "Writing TSRs Through C" End If End Sub

32

Output:

Result:

Thus a visual basic program has been written to work with controls is implemented and tested with various samples.

33

Ex. No.6: Aim:

Working with Controls-II [ List View, MS Chart, File system Controls]

To write a Visual basic program to work with list view, MS chart and file system controls

Form Design:

Controls used: Drive list box, dir list box, file list box, command button, list view box, MS Chart. Changes in Properties: Control Name Command button Command1 Command button Command2 Command button Command3 MSChart MSChart1

Property Caption Caption Caption Chart Type

Value List Chart Exit 14-vtchcharttype2dPie

Methods and events used: Drive list box: drive, change() Dir list Box: path, change() File list box: file name, read only, hidden archive, listindex List View control: listitems -> add(), clear MS chart: chart data, visible Command: click() Procedure: 1) Place a drive list box, dir list box, file list box, list view box, a chart, and three command buttons as shown the form layout. 2) By selecting a drive, its content folders should be displayed in dir list box and after selecting a folder the contents displayed in the file list box. 3) On clicking the list button, the contents of the file list box should be displayed in the list view box. 4) On clicking the chart button, display a Pie chart for three User defined values. 5) End.

34

Source Code: Dim r, h, a As Integer Private Sub Command1_Click() MSChart1.Visible = False ListView1.Visible = True Dim x As ListItem Dim z As Integer With ListView1.ListItems .Clear z=0 File1.ListIndex = z Do While File1.ListIndex < File1.ListCount - 1 Set x = .Add(1, , File1.FileName, 1) z=z+1 File1.ListIndex = z Loop Set x = .Add(1, , File1.FileName, 1) End With End Sub Private Sub Command2_Click() MSChart1.Visible = True r = InputBox("Enter a value") h = InputBox("Enter a value") a = InputBox("Enter a value") Dim x(0, 2) As Integer x(0, 0) = r x(0, 1) = h x(0, 2) = a MSChart1.ChartData = x End Sub Private Sub Command3_Click() End End Sub Private Sub Dir1_Change() File1.Path = Dir1.Path End Sub Private Sub Drive1_Change() Dir1.Path = Drive1.Drive End Sub Private Sub Form_Load() ListView1.Visible = False MSChart1.Visible = False End Sub

35

Output:

Result:

Thus a visual basic program has been written to work with controls is implemented and tested with various samples.

36

Ex No. 7 Aim:

Working With Different Controls – III [animation, image list, common dialog control]

To write a Visual basic program to work with animation, image list and common dialog controls Form Design:

Controls Used: Animation Control, imagelist control, timer, common dialog box, toolbar, command button, rich text box. Changes in Properties: Control Name Command button Command1 Command button Command2 Command button Command3 Rich text box rich textbox1 Imagelist imagelist1 Toolbar toolbar1 Timer timer1

Property Caption Caption Caption scrollbar name image list intreval

Value Open Save Exit 3 - rthorizontal imltoolbaricons imltoolbaricons 9900

Methods and Events: Animation: visible, open, play, stop, Common Dialog: filter, action, filename. Command: click() Rich text box: file name, save file, visible, selbold, selitalic, selunderline, SelAlignment. Toolbar: buttonclick(), button.key. Timer: enabled, timer(). Procedure: 1. Place the toolbar, rich text box, command buttons, animation control as shown in form layout. 2. To invoke components, click project -> components then select Microsoft rich text box control, Microsoft windows common controls, Microsoft common dialog box control from components window. 3. For creating buttons on toolbar, go to property window by right click on toolbar. Then specify image list and key, image number on button tab for each button.

37

Button Leftalign Center Rightalign Bold Italic Underline

Key leftalign center rightalign bold italic underline

Image No. 11 12 13 8 9 10

4. By clicking the buttons on toolbar the corresponding changes will be done on rich text box. 5. Using common dialog box control, open a text file in rich text box and also to save the text in rich textbox with the help of command buttons. 6. On saving display an animation of “copying a file” animation control for an interval by using timer.(location of avi : C:\Program Files\Microsoft Visual Studio\Common\Graphics\Videos\ FILECOPY.avi) 7. Display a message box after the delay. Source Code: Dim filter As String Private Sub Command1_Click() filter = "Text files(*.txt)|*.txt" CommonDialog1.filter = filter CommonDialog1.Action = 1 RichTextBox1.FileName = CommonDialog1.FileName End Sub Private Sub Command2_Click() CommonDialog1.Action = 2 RichTextBox1.SaveFile (CommonDialog1.FileName) RichTextBox1.Visible = False Animation1.Visible = True Animation1.Play Timer1.Enabled = True End Sub Private Sub Command3_Click() End End Sub Private Sub Form_Load() Animation1.Open "E:\Program Files\Microsoft VisualStudio\Common\Graphics\Videos \FILECOPY.avi" Animation1.Visible = False Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Animation1.Stop Animation1.Visible = False MsgBox ("File Saved") 38

End Sub Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button) Select Case Button.Key Case "Bold" RichTextBox1.SelBold = Not RichTextBox1.SelBold Button.Value = IIf(RichTextBox1.SelBold, tbrPressed, tbrUnpressed) RichTextBox1.Font.Bold = Button.Value Case "Italic" RichTextBox1.SelItalic = Not RichTextBox1.SelItalic Button.Value = IIf(RichTextBox1.SelItalic, tbrPressed, tbrUnpressed) RichTextBox1.Font.Italic = Button.Value Case "Underline" RichTextBox1.SelUnderline = Not RichTextBox1.SelUnderline Button.Value = IIf(RichTextBox1.SelUnderline, tbrPressed, tbrUnpressed) RichTextBox1.Font.Underline = Button.Value Case "Align Left" RichTextBox1.SelAlignment = rtfLeft Case "Center" RichTextBox1.SelAlignment = rtfCenter Case "Align Right" RichTextBox1.SelAlignment = rtfRight End Select End Sub Output:

Result:

Thus a visual basic program has been written to work with controls is implemented and tested with various samples.

39

Ex No. 8 Aim:

Simulation of Simple Text Editor

To write a Visual Basic Program to create a simple Text Notepad.

Form Design:

Controls Used: Menu, command box, combo box, common dialog Changes in Properties: Control Name Label Label1 Label Label2 Combo box combo1 Combo box combo2

Property Caption Caption list list

Value Font Face Font Size

Methods and Events: Common dialog box: file name, action, filter Rich text box: file name, save file, visible, selRTF. Rich text box.font : bold,italic, underline, strikethrough, name, size. Combo box: additem, click() Menu items: click() Clipboard : set text, get text Procedure: 1. Place the label, rich 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 Sub-Menu Caption Caption Name File open open Save save Save as saveas Print print Exit exit 40

Edit

Cut cut Copy copy Paste paste Format Bold bold Italic italic Underline underline Strikethrough Strikethrough 5. To invoke components, click project -> components then select Microsoft rich text box control, Microsoft common dialog box control from components window. 6. Load the combo boxes with some font names and size, By selecting the combo boxes the face and size of the text altered respectively. 7. By selecting the operations on menus the corresponding tasks should be performed using common dialog box and clipboard events. Source Code: Dim filter As String Private Sub bold_Click() RichTextBox1.Font.bold = Not RichTextBox1.Font.bold End Sub Private Sub Combo1_Click() RichTextBox1.Font.Name = Combo1.Text End Sub Private Sub Combo2_Click() RichTextBox1.Font.Size = Combo2.Text End Sub Private Sub copy_Click() On Error Resume Next Clipboard.SetText RichTextBox1.SelRTF End Sub Private Sub cut_Click() On Error Resume Next Clipboard.SetText RichTextBox1.SelRTF RichTextBox1.SelText = vbNullString End Sub Private Sub Exit_Click() Unload Form1 End Sub Private Sub Form_Load() Combo1.AddItem "arial" Combo1.AddItem "arial bold" Combo1.AddItem "impact" Combo1.AddItem "lucida calligraphy" Combo1.AddItem "lucida handwriting" Combo1.AddItem "monotype corsiva" Combo1.AddItem "times new roman" Combo1.AddItem "wingdings" 41

For i = 8 To 48 Combo2.AddItem i Next End Sub Private Sub italic_Click() RichTextBox1.Font.italic = Not RichTextBox1.Font.italic End Sub Private Sub open_Click() filter = "Text files(*.txt)|*.txt" CommonDialog1.filter = filter CommonDialog1.Action = 1 RichTextBox1.FileName = CommonDialog1.FileName End Sub Private Sub paste_Click() On Error Resume Next RichTextBox1.SelRTF = Clipboard.GetText End Sub Private Sub print_Click() CommonDialog1.Action = 5 End Sub Private Sub Save_Click() filter = "Text files(*.txt)|*.txt" CommonDialog1.filter = filter CommonDialog1.Action = 2 RichTextBox1.SaveFile (CommonDialog1.FileName) End Sub Private Sub Saveas_Click() filter = "Text files(*.txt)|*.txt" CommonDialog1.filter = filter CommonDialog1.Action = 2 RichTextBox1.SaveFile (CommonDialog1.FileName) End Sub Private Sub Strikethrough_Click() RichTextBox1.Font.Strikethrough = Not RichTextBox1.Font.Strikethrough End Sub Private Sub underline_Click() RichTextBox1.Font.underline = Not RichTextBox1.Font.underline End Sub

42

Output:

Result:

Thus a visual basic program has been written to create a simple text editor is implemented.

43

Ex No. 9 Aim:

MS Flex Grid Control

To write a Visual Basic program to create a Quiz using MSFlex Grid.

Form Design:

Controls Used: Label, Option button, Frame, Command button, MSFlex grid, Combo box. Changes in Properties: Control Name Form1: Label label1 Label label2 Label label3 Option Button Option1 Option Button Option2 Option Button Option3 Option Button Option4 Command button command1 Command button command2 Form2: Form Form1 Label label1 Label label2 Label label3 MSFlexGrid MSFlexGrid1 MSFlexGrid MSFlexGrid1 Combo box combo1

Property

Value

Caption fore color fore color Caption Caption Caption Caption Caption Caption

Tech Quiz Red Blue

Name font Caption fore color Row Col list

frmDataEnv Times new roman Correct Answers are List out answers by 20 7

Next Quit

Methods and Events: Form: hide, show. Option: value Command: click(). Msflexgrid: colwidth, colheadercaption, textmatrix(), visible Combo: additem

44

Variables Used: Global: i , answer as integer User Defined function: Display(), ans(). Procedure: 1. Place the option buttons, labels, command buttons, flex grid as shown in the form layout. 2. Load the form2 first, on loading the second form load all the data (questions, options and answers) in the flex grid, then hide form2 and show form1. 3. Use a user defined function to display the questions and options loaded in flex grid of form2, on the label and options in form1. 4. By using loops, call display function and get the answers form user by clicking the Next button. 5. After getting all the answers display the flex grid with correct answers. 6. By using the combo box make query on the results such as (a only correct, b only correct, c only correct, d only correct, All correct, All wrong) with the help of another MSFlexgrid. Source Code: Form1: Dim i As Integer Dim answer As Integer Private Sub Command2_Click() Form1.Hide frmDataEnv.Show ans (answer) End Sub Private Sub Form_Load() i=1 display (i) End Sub Private Sub Command1_Click() If Option1.Value = True Then frmDataEnv.MSHFlexGrid1.TextMatrix(i, 6) = "a" ElseIf Option2 = True Then frmDataEnv.MSHFlexGrid1.TextMatrix(i, 6) = "b" ElseIf Option3.Value = True Then frmDataEnv.MSHFlexGrid1.TextMatrix(i, 6) = "c" ElseIf Option4.Value = True Then frmDataEnv.MSHFlexGrid1.TextMatrix(i, 6) = "d" End If If StrComp(frmDataEnv.MSHFlexGrid1.TextMatrix(i, 6), frmDataEnv.MSHFlexGrid1.TextMa rix(i, 5)) = 0 Then answer = answer + 1 End If i=i+1 display (i) If i = 10 Then Command1.Caption = "End" ElseIf i = 11 Then 45

Form1.Hide ans (answer) frmDataEnv.Show End If End Sub Public Sub display(s As Integer) Label3.Caption = "Question No. " & s Label2.Caption = frmDataEnv.MSHFlexGrid1.TextMatrix(s, 0) Option1.Caption = frmDataEnv.MSHFlexGrid1.TextMatrix(s, 1) Option2.Caption = frmDataEnv.MSHFlexGrid1.TextMatrix(s, 2) Option3.Caption = frmDataEnv.MSHFlexGrid1.TextMatrix(s, 3) Option4.Caption = frmDataEnv.MSHFlexGrid1.TextMatrix(s, 4) Option1.Value = False Option2.Value = False Option3.Value = False Option4.Value = False End Sub

Form2:

Public Sub ans(s As Integer) frmDataEnv.Label1.Caption = "Your Answered " & s & " Questions Correctly Out of " & i - 1 End Sub Private Sub Combo1_Click() Dim j, k As Integer j=1 MSHFlexGrid2.Clear MSHFlexGrid1.Visible = False MSHFlexGrid2.Visible = True MSHFlexGrid2.ColHeaderCaption(0, 0) = "Question" MSHFlexGrid2.ColHeaderCaption(0, 1) = "Option 1" MSHFlexGrid2.ColHeaderCaption(0, 2) = "Option 2" MSHFlexGrid2.ColHeaderCaption(0, 3) = "Option 3" MSHFlexGrid2.ColHeaderCaption(0, 4) = "Option 4" MSHFlexGrid2.ColHeaderCaption(0, 5) = "Correct Ans" MSHFlexGrid2.ColHeaderCaption(0, 6) = "Your Ans" MSHFlexGrid2.ColWidth(0, 0) = 5000 MSHFlexGrid2.ColWidth(1, 0) = 1500 MSHFlexGrid2.ColWidth(2, 0) = 1500 MSHFlexGrid2.ColWidth(3, 0) = 1500 MSHFlexGrid2.ColWidth(4, 0) = 1500 For i = 1 To 10 If MSHFlexGrid1.TextMatrix(i, 5) = Combo1.Text Then For k = 0 To 6 MSHFlexGrid2.TextMatrix(j, k) = MSHFlexGrid1.TextMatrix(i, k) Next j=j+1 End If Next If Combo1.Text = "All Correct" Then 46

For i = 1 To 10 If MSHFlexGrid1.TextMatrix(i, 5) = MSHFlexGrid1.TextMatrix(i, 6) Then For k = 0 To 6 MSHFlexGrid2.TextMatrix(j, k) = MSHFlexGrid1.TextMatrix(i, k) Next j=j+1 End If Next ElseIf Combo1.Text = "All Wrong" Then For i = 1 To 10 If MSHFlexGrid1.TextMatrix(i, 5) MSHFlexGrid1.TextMatrix(i, 6) Then For k = 0 To 6 MSHFlexGrid2.TextMatrix(j, k) = MSHFlexGrid1.TextMatrix(i, k) Next j=j+1 End If Next ElseIf Combo1.Text = "All" Then MSHFlexGrid1.Visible = True MSHFlexGrid2.Visible = False End If End Sub Private Sub Command1_Click() End End Sub Private Sub Form_Load() MSHFlexGrid1.ColHeaderCaption(0, 0) = "Question" MSHFlexGrid1.ColHeaderCaption(0, 1) = "Option 1" MSHFlexGrid1.ColHeaderCaption(0, 2) = "Option 2" MSHFlexGrid1.ColHeaderCaption(0, 3) = "Option 3" MSHFlexGrid1.ColHeaderCaption(0, 4) = "Option 4" MSHFlexGrid1.ColHeaderCaption(0, 5) = "Correct Ans" MSHFlexGrid1.ColHeaderCaption(0, 6) = "Your Ans" MSHFlexGrid1.ColWidth(0, 0) = 5000 MSHFlexGrid1.ColWidth(1, 0) = 1500 MSHFlexGrid1.ColWidth(2, 0) = 1500 MSHFlexGrid1.ColWidth(3, 0) = 1500 MSHFlexGrid1.ColWidth(4, 0) = 1500 MSHFlexGrid1.TextMatrix(1, 0) = "Who Invented C?" MSHFlexGrid1.TextMatrix(1, 1) = "Dennis Ritche" MSHFlexGrid1.TextMatrix(1, 2) = "Charles Babbage" MSHFlexGrid1.TextMatrix(1, 3) = "Alan Cooper" MSHFlexGrid1.TextMatrix(1, 4) = "John Backus" MSHFlexGrid1.TextMatrix(1, 5) = "a" MSHFlexGrid1.TextMatrix(2, 0) = "Who Invented Visual Basic?" MSHFlexGrid1.TextMatrix(2, 1) = "Dennis Ritche" 47

MSHFlexGrid1.TextMatrix(2, 2) = "Charles Babbage" MSHFlexGrid1.TextMatrix(2, 3) = "Alan Cooper" MSHFlexGrid1.TextMatrix(2, 4) = "John Backus" MSHFlexGrid1.TextMatrix(2, 5) = "c" MSHFlexGrid1.TextMatrix(3, 0) = "Who was the Founder of Wikipedia?" MSHFlexGrid1.TextMatrix(3, 1) = "Sergey Brin" MSHFlexGrid1.TextMatrix(3, 2) = "Larry Page" MSHFlexGrid1.TextMatrix(3, 3) = "Jimmy Donal Wales" MSHFlexGrid1.TextMatrix(3, 4) = "Kevin Rose" MSHFlexGrid1.TextMatrix(3, 5) = "c" MSHFlexGrid1.TextMatrix(4, 0) = "Charles Babage Invented which One?" MSHFlexGrid1.TextMatrix(4, 1) = "Analytic Engine" MSHFlexGrid1.TextMatrix(4, 2) = "Difference Engine" MSHFlexGrid1.TextMatrix(4, 3) = "Computer" MSHFlexGrid1.TextMatrix(4, 4) = "Both A & B" MSHFlexGrid1.TextMatrix(4, 5) = "d" MSHFlexGrid1.TextMatrix(5, 0) = "Which is the First Popular High Level Language?" MSHFlexGrid1.TextMatrix(5, 1) = "COBAL" MSHFlexGrid1.TextMatrix(5, 2) = "FORTRAN" MSHFlexGrid1.TextMatrix(5, 3) = "BASIC" MSHFlexGrid1.TextMatrix(5, 4) = "ALGOL" MSHFlexGrid1.TextMatrix(5, 5) = "b" MSHFlexGrid1.TextMatrix(6, 0) = "Who was the Founder of Linux?" MSHFlexGrid1.TextMatrix(6, 1) = "Mark Shuttleworth" MSHFlexGrid1.TextMatrix(6, 2) = "Linus Torvalds" MSHFlexGrid1.TextMatrix(6, 3) = "Daniel Robbins" MSHFlexGrid1.TextMatrix(6, 4) = "Miguel de Icaza" MSHFlexGrid1.TextMatrix(6, 5) = "b" MSHFlexGrid1.TextMatrix(7, 0) = "Which was the First Computer used to Play Music?" MSHFlexGrid1.TextMatrix(7, 1) = "UNIVAC 1" MSHFlexGrid1.TextMatrix(7, 2) = "EDVAC 1" MSHFlexGrid1.TextMatrix(7, 3) = "CSIRAC" MSHFlexGrid1.TextMatrix(7, 4) = "LEO 1" MSHFlexGrid1.TextMatrix(7, 5) = "c" MSHFlexGrid1.TextMatrix(8, 0) = "Which is the First Object Based Language?" MSHFlexGrid1.TextMatrix(8, 1) = "Simula 1" MSHFlexGrid1.TextMatrix(8, 2) = "Ada" MSHFlexGrid1.TextMatrix(8, 3) = "COBAL" MSHFlexGrid1.TextMatrix(8, 4) = "Simula 67" MSHFlexGrid1.TextMatrix(8, 5) = "a" MSHFlexGrid1.TextMatrix(9, 0) = "Who is the Indian Teenager wrote a book on Ethical Hacking?" MSHFlexGrid1.TextMatrix(9, 1) = "Jon Erickson" MSHFlexGrid1.TextMatrix(9, 2) = "Kevin Beaver" 48

MSHFlexGrid1.TextMatrix(9, 3) = "Ankit Faida" MSHFlexGrid1.TextMatrix(9, 4) = "Joel Scambray" MSHFlexGrid1.TextMatrix(9, 5) = "c" MSHFlexGrid1.TextMatrix(10, 0) = "Who was the First Hacker in Top Rank of FBI Most Wanted List?" MSHFlexGrid1.TextMatrix(10, 1) = "John Daper" MSHFlexGrid1.TextMatrix(10, 2) = "William Gibson" MSHFlexGrid1.TextMatrix(10, 3) = "Kevin Lee Poulsen" MSHFlexGrid1.TextMatrix(10, 4) = "Kevin Mitnick" MSHFlexGrid1.TextMatrix(10, 5) = "d" Combo1.AddItem "All" Combo1.AddItem "a" Combo1.AddItem "b" Combo1.AddItem "c" Combo1.AddItem "d" Combo1.AddItem "All Correct" Combo1.AddItem "All Wrong" frmDataEnv.Hide Form1.Show End Sub Output:

Result:

Thus a visual basic program has been written for quiz program using MSFlexgrid is implemented and tested with various samples.

49

Ex No. 10 Aim:

Mouse events

To write a visual Basic program for free hand drawing and drag and drop events.

Form Design:

Controls Used: Frame, picture box, command button. Changes in Properties: Control Name Command box command1 Command box command2 Frame frame1

Property caption caption caption

Value Exit Clear

Methods and Events: Picture box: cls, top, left, current, currenty, mouse down(), mouse move(), Line() Frame: top, left, current, currenty, mouse down(), mouse move() Command button: click() Variable Used: Global S as integer Procedure: 1. Place the frame, picture box, command buttons as shown in the form layout. 2. While click and drag on the picture box line should be drawn by following mouse pointer. 3. While click and drag on the frame both (picture box and frame) should be move to the mouse pointer direction. 4. On clicking clear the contents of picture box should be cleared. Source Code: Dim s As Integer Private Sub Command1_Click() End End Sub Private Sub Command2_Click() Picture1.Cls End Sub 50

Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) s=1 End Sub Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 And s = 1 Then Frame1.Left = X Frame1.Top = Y Picture1.Top = Y + 240 Picture1.Left = X + 240 End If End Sub Private Sub Frame1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) s=0 End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Picture1.CurrentX = X Picture1.CurrentY = Y End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 1 Then Picture1.Line (Picture1.CurrentX, Picture1.CurrentY)-(X, Y) End If End Sub Output:

Result:

Thus a visual basic program has been written for free hand drawing and drag and drop is implemented and tested with various samples.

51

Ex No. 11 Aim:

Create a Banner using Timer Control

To write a Visual Basic Program to create a banner using timer control. Form Design:

Controls Used: Label, Timer Changes in Properties: Control Name Form form1 Form form1 Form form1 Label label1 Label label1 Label label1 Timer Timer1 Timer Timer2

Property Height Width Maxbutton Caption Font Fore Color Interval Interval

Value 3600 4800 False Banner times new roman red 5 15000

Methods and Events: Timer: timer() Variables used: Global: S,x as integer. Procedure: 1. Place the label and timers as shown in the form layout. 2. Depending upon timer1 move the label1 in any one direction. 3. Change the direction depending upon the tiner2. Source Code: Dim s, x As Integer Private Sub Timer1_Timer() If x = 1 Then If s = 0 Then Label1.Left = Label1.Left + 10 If Label1.Left > 3000 Then s = 1 ElseIf s = 1 Then Label1.Left = Label1.Left - 10 If Label1.Left < 1 Then s = 0 End If Else 52

If s = 0 Then Label1.Left = (Label1.Left + 10) If Label1.Left > 4679 Then Label1.Left = -1800 ElseIf s = 1 Then Label1.Left = (Label1.Left - 10) If Label1.Left < -1799 Then Label1.Left = 4680 End If End If End Sub Private Sub Timer2_Timer() x = (x + 1) Mod 2 End Sub Output:

Result:

Thus a visual basic program has been written to create a banner using timer is implemented and tested with various samples.

53

Ex No. 12 Aim:

Accessing of Database Using Data Control DAO

To write a Visual Basic program to create a address book database and access through DAO.

Form Design:

Controls Used: Command buttons, data, labels and textboxes. Changes in Properties: Control Name Label label1 Label label1 Label label1 Label label1 Label label1 Label label1 Label label1 Label label1 Label label1 Label label1 Text box text1 Text box text1 Text box text1 Text box text1 Text box text1 Text box text1 Text box text1 Text box text1 Text box text1 Text box text1 Text box txtFields(0-9) Command button Command1 Command button Command2 Command button Command3 Command button Command4

Property Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, caption Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield Name, index, text, datafield data source Name, caption Name, caption Name, caption Name, caption

Value lblLabels,0, AddressID lblLabels,1, Name lblLabels,2, Initial lblLabels,3, Address lblLabels,4, City lblLabels,5, State lblLabels,6, Postal Code lblLabels,7, Phone lblLabels,8, Mobile lblLabels,9, E-Mail txtFields,0,” ”, AddressID txtFields,1,” ”, name txtFields,2,” ”, initial txtFields,3,” ”, address txtFields,4,” ”, city txtFields,5,” ”, state txtFields,6,” ”, postal code txtFields,7,” ”, phone txtFields,8,” ”, mobile txtFields,9,” ”, E-Mail data1 cmdAdd, Add cmdDelete,Delete cmdUpdate,Update cmdRefresh, Refresh 54

Command button Data Data

Command5 Data1 Data1

Name, caption databasename Recordsource

cmdClose, Close d:\dao.mdb AddreessBook

Methods and Events: Data: recordset, refresh, Validate(), Reposition(),Error() Recordset: movenext, delete, addnew, bookmark, lastmodified, absoluteposition Command: click() Procedure: 1. Place the textboxes, command buttons, data field and labels as shown in the form layout. 2. To create a mdb (Access) data base, go to add-ins -> visual data manager. Then select file -> new -> Microsoft access -> version 7.0 mdb and save using a file name dao on drive d. 3. Right click on database window and select new table. 4. In table structure window give the table name as “AddressBook” and enter the required fields (AddressID, name, initial, address, city, state, postal code, phone, mobile, E-Mail) then close. 5. Make change in the properties of data1, txtfields.datafield as mentioned above. 6. Write addition, deletion, updating commands to the command buttons. Source Code: Private Sub cmdAdd_Click() Data1.Recordset.AddNew End Sub Private Sub cmdDelete_Click() Data1.Recordset.Delete Data1.Recordset.MoveNext End Sub Private Sub cmdRefresh_Click() Data1.Refresh End Sub Private Sub cmdUpdate_Click() Data1.UpdateRecord Data1.Recordset.Bookmark = Data1.Recordset.LastModified End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub Data1_Error(DataErr As Integer, Response As Integer) MsgBox "Data error event hit err:" & Error$(DataErr) Response = 0 End Sub Private Sub Data1_Reposition() Screen.MousePointer = vbDefault On Error Resume Next Data1.Caption = "Record: " & (Data1.Recordset.AbsolutePosition + 1) 55

End Sub Private Sub Data1_Validate(Action As Integer, Save As Integer) 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 Screen.MousePointer = vbHourglass End Sub Output:

Result:

Thus a visual basic program has been written to access a database using DAO is implemented and tested with various samples.

56

Ex No. 13 Aim:

Accessing of Database Using ADO

To write a Visual Basic program to create a address book database and access through ADO. Form Design:

Controls Used: Text boxes, labels, Command buttons, ado control Changes in Properties: Control Name Property Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box txtFields(0-9) data source Command button Command1 Name, caption Command button Command2 Name, caption Command button Command3 Name, caption Command button Command4 Name, caption Command button Command5 Name, caption Ado Adodc databasename Ado Adodc Recordsource

Value lblLabels,0, AddressID lblLabels,1, Name lblLabels,2, Initial lblLabels,3, Address lblLabels,4, City lblLabels,5, State lblLabels,6, Postal Code lblLabels,7, Phone lblLabels,8, Mobile lblLabels,9, E-Mail txtFields,0,” ”, AddressID txtFields,1,” ”, name txtFields,2,” ”, initial txtFields,3,” ”, address txtFields,4,” ”, city txtFields,5,” ”, state txtFields,6,” ”, postal code txtFields,7,” ”, phone txtFields,8,” ”, mobile txtFields,9,” ”, E-Mail data1 cmdAdd, Add cmdDelete,Delete cmdUpdate,Update cmdRefresh, Refresh cmdClose, Close d:\ado.mdb AddreessBook 57

Methods and Events: Data: recordset, refresh, Validate(), Reposition(),Error() Recordset: movenext, delete, addnew, bookmark, lastmodified, absoluteposition Command: click() Procedure: 1. Place the textboxes, command buttons, data field and labels as shown in the form layout. 2. To create a mdb (Access) data base, go to add-ins -> visual data manager. Then select file -> new -> Microsoft access -> version 7.0 mdb and save using a file name ado on drive d. 3. Right click on database window and select new table. 4. In table structure window give the table name as “AddressBook” and enter the required fields (AddressID, name, initial, address, city, state, postal code, phone, mobile, E-Mail) then close. 5. Make change in the properties of data1, txtfields.datafield as mentioned above. 6. Write addition, deletion, updating commands to the command buttons. Output:

Result:

Thus a visual basic program has been written to access a database using ADO is implemented and tested with various samples.

58

Ex No. 14 Aim:

Creation of an Embedded object

To write a Visual Basic program to work with embed objects. Form Design:

Controls Used: Menu, OLE Methods and Events: OLE: Do verb Procedure: 1. Create a menu with the listing of OLE_APP -> Paint, MS_Word, MS_Excel, MS_Pow. 2. To create OLE objects click OLE icon on toolbox, then select the object type as follows a. Bitmap image for OLE1 b. Microsoft Word Document for OLE2 c. Microsoft Excel Document for OLE3 d. Microsoft PowerPoint Document for OLE4 3. By clicking the menu items the corresponding object should be open. Source Code: Private Sub MS_EXCEL_Click() OLE3.DoVerb (2) End Sub Private Sub MS_POW_Click() OLE4.DoVerb (2) End Sub Private Sub MS_WORD_Click() OLE2.DoVerb (2) End Sub Private Sub PAINT_Click() OLE1.DoVerb (2) End Sub 59

Output:

Result:

Thus a visual basic program has been written to embed object is implemented and tested with various samples.

60

Ex No. 15 Aim:

Creation of an Active-X Control

To write a Visual Basic program to use a user defined active-X control.

Form Design:

Controls Used:

User control, timer,label Changes in Properties: Control Name Usercontrol: Label label1 Label label1 Timer timer1 Timer timer2

Property

Value

caption font interval interval

Times new roman 10 500

Methods and Events: Timer: timer() Form: mousemove() Procedure: User Control: 1. By using timer1 get the current time and display in label1. 2. By using timer2 change the back color of the user control. 3. Save project and make into ocx file by selecting file -> make active.ocx. Main Form: 1. Add active-X components from components window, by Browse and select active.ocx. 2. Put the User Control from tool box to main form. 3. On mouse move change the back color of main form. Source Code: User Control: Private Sub Timer1_Timer() Label1.Caption = Format(Now, "long Date") & " " & Format(Now, "long Time") End Sub Private Sub Timer2_Timer() UserControl.BackColor = RGB(Rnd * 300, Rnd * 500, Rnd * 100) Label1.BackColor = UserControl.BackColor 61

Form1:

End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Form1.BackColor = RGB(Rnd * 300, Rnd * 300, Rnd * 300) End Sub

Output:

Result:

Thus a visual basic program has been written to use a user defined active-X object is implemented and tested with various samples.

62

Ex No. 16 Aim:

File maintenance package using MDI

To write a Visual Basic Program to implement multiple Document interface using a simple WordPad. Form Design:

Controls Used: Image list box, common dialog box, menu, common controls, rich text box, toolbar Changes in Properties: Control Name MDIForm Form1 Form form1 Form frmDocument

Property Name name mdi child

Value frmMain frmDocument true

Methods and Events: Form: arrange() Menu Item: click() Clip Board: Common dialog: Rich text box : savefile, loadfile, Procedure: Main Form 63

1. Place the menu, toolbar, status bar as shown in the 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. To invoke components, click project -> components then select Microsoft rich text box control, Microsoft windows common controls, Microsoft common dialog box control from components window. 5. For creating buttons on toolbar, go to property window by right click on toolbar. Then specify image list and key, image number on button tab for each button. MDI Child 1. Place the rich text box and form named as frmDocument. Module: 1. By the module, we can set the main form as frmmain, and load the frmmain. Source Code: Main Form: Private Sub MDIForm_Load() Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000) Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000) Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500) Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500) LoadNewDoc End Sub Private Sub LoadNewDoc() Static lDocumentCount As Long Dim frmD As frmDocument lDocumentCount = lDocumentCount + 1 Set frmD = New frmDocument frmD.Caption = "Document " & lDocumentCount frmD.Show End Sub Private Sub MDIForm_Unload(Cancel As Integer) If Me.WindowState vbMinimized Then SaveSetting App.Title, "Settings", "MainLeft", Me.Left SaveSetting App.Title, "Settings", "MainTop", Me.Top SaveSetting App.Title, "Settings", "MainWidth", Me.Width SaveSetting App.Title, "Settings", "MainHeight", Me.Height End If End Sub Private Sub tbToolBar_ButtonClick(ByVal Button As ComctlLib.Button) On Error Resume Next Select Case Button.Key Case "New" LoadNewDoc Case "Open" 64

mnuFileOpen_Click Case "Save" mnuFileSave_Click Case "Print" mnuFilePrint_Click Case "Cut" mnuEditCut_Click Case "Copy" mnuEditCopy_Click Case "Paste" mnuEditPaste_Click Case "Bold" ActiveForm.rtfText.SelBold = Not ActiveForm.rtfText.SelBold Button.Value = IIf(ActiveForm.rtfText.SelBold, tbrPressed, tbrUnpressed) Case "Italic" ActiveForm.rtfText.SelItalic = Not ActiveForm.rtfText.SelItalic Button.Value = IIf(ActiveForm.rtfText.SelItalic, tbrPressed, tbrUnpressed) Case "Underline" ActiveForm.rtfText.SelUnderline = Not ActiveForm.rtfText.SelUnderline Button.Value = IIf(ActiveForm.rtfText.SelUnderline, tbrPressed, tbrUnpressed) Case "Align Left" ActiveForm.rtfText.SelAlignment = rtfLeft Case "Center" ActiveForm.rtfText.SelAlignment = rtfCenter Case "Align Right" ActiveForm.rtfText.SelAlignment = rtfRight End Select End Sub Private Sub mnuHelpAbout_Click() MsgBox "Version " & App.Major & "." & App.Minor & "." & App.Revision End Sub Private Sub mnuWindowArrangeIcons_Click() Me.Arrange vbArrangeIcons End Sub Private Sub mnuWindowTileVertical_Click() Me.Arrange vbTileVertical End Sub Private Sub mnuWindowTileHorizontal_Click() Me.Arrange vbTileHorizontal End Sub Private Sub mnuWindowCascade_Click() Me.Arrange vbCascade End Sub Private Sub mnuWindowNewWindow_Click() LoadNewDoc 65

End Sub Private Sub mnuViewStatusBar_Click() mnuViewStatusBar.Checked = Not mnuViewStatusBar.Checked sbStatusBar.Visible = mnuViewStatusBar.Checked End Sub Private Sub mnuViewToolbar_Click() mnuViewToolbar.Checked = Not mnuViewToolbar.Checked tbToolBar.Visible = mnuViewToolbar.Checked End Sub Private Sub mnuEditPaste_Click() On Error Resume Next ActiveForm.rtfText.SelRTF = Clipboard.GetText End Sub Private Sub mnuEditCopy_Click() On Error Resume Next Clipboard.SetText ActiveForm.rtfText.SelRTF End Sub Private Sub mnuEditCut_Click() On Error Resume Next Clipboard.SetText ActiveForm.rtfText.SelRTF ActiveForm.rtfText.SelText = vbNullString End Sub Private Sub mnuFileExit_Click() Unload Me End Sub Private Sub mnuFilePrint_Click() On Error Resume Next If ActiveForm Is Nothing Then Exit Sub With dlgCommonDialog .DialogTitle = "Print" .CancelError = True .Flags = cdlPDReturnDC + cdlPDNoPageNums If ActiveForm.rtfText.SelLength = 0 Then .Flags = .Flags + cdlPDAllPages Else .Flags = .Flags + cdlPDSelection End If .ShowPrinter If Err MSComDlg.cdlCancel Then ActiveForm.rtfText.SelPrint .hDC End If End With 66

End Sub Private Sub mnuFileSave_Click() Dim sFile As String If Left$(ActiveForm.Caption, 8) = "Document" Then With dlgCommonDialog .CancelError = False .Filter = "All Files (*.*)|*.*" .ShowSave If Len(.FileName) = 0 Then Exit Sub End If sFile = .FileName End With ActiveForm.rtfText.SaveFile sFile Else sFile = ActiveForm.Caption ActiveForm.rtfText.SaveFile sFile End If End Sub Private Sub mnuFileClose_Click() Screen.ActiveForm.Hide End Sub Private Sub mnuFileOpen_Click() Dim sFile As String If ActiveForm Is Nothing Then LoadNewDoc With dlgCommonDialog .CancelError = False .Filter = "All Files (*.*)|*.*" .ShowOpen If Len(.FileName) = 0 Then Exit Sub End If sFile = .FileName End With ActiveForm.rtfText.LoadFile sFile ActiveForm.Caption = sFile End Sub Private Sub mnuFileNew_Click() LoadNewDoc End Sub FrmDocument: Private Sub rtfText_SelChange() fMainForm.tbToolBar.Buttons("Bold").Value = IIf(rtfText.SelBold, tbrPressed, tbrUnpressed) fMainForm.tbToolBar.Buttons("Italic").Value = IIf(rtfText.SelItalic, tbrPressed, tbrUnpressed) fMainForm.tbToolBar.Buttons("Underline").Value = IIf(rtfText.SelUnderline, tbrPressed, tbrUnpressed) 67

fMainForm.tbToolBar.Buttons("Align Left").Value = IIf(rtfText.SelAlignment = rtfLeft, tbrPressed, tbrUnpressed) fMainForm.tbToolBar.Buttons("Center").Value = IIf(rtfText.SelAlignment = rtfCenter, tbrPressed, tbrUnpressed) fMainForm.tbToolBar.Buttons("Align Right").Value = IIf(rtfText.SelAlignment = rtfRight, tbrPressed, tbrUnpressed) End Sub Private Sub Form_Load() Form_Resize End Sub Private Sub Form_Resize() On Error Resume Next rtfText.Move 100, 100, Me.ScaleWidth - 200, Me.ScaleHeight - 200 rtfText.RightMargin = rtfText.Width - 400 End Sub Module1: Public fMainForm As frmMain Sub Main() frmSplash.Show frmSplash.Refresh Set fMainForm = New frmMain Load fMainForm Unload frmSplash fMainForm.Show End Sub Output:

68

Result:

Thus a visual basic program has been written to implement multiple document interface using a simple WordPad and tested with various samples.

69

Ex.No. 17 Aim:

Student Circular using Data Report

To write a Visual Basic Program to implement student transfer circular using data report. Form Design:

Form Controls Used: Label, Command Button, Text Box, Data Control. Changes in Properties: Control Name Property Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Label label1 Name, index, caption Text box txtFields(0-9) data source Data Data1 databasename Data Data1 Recordsource Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Text box text1 Name, index, text, datafield Command button Command1 Name, caption Command button Command2 Name, caption Command button Command3 Name, caption Command button Command4 Name, caption Command button Command5 Name, caption Command button Command6 Name, caption

Data report

Value lblLabels,0, Roll No lblLabels,1, Name lblLabels,2, Course lblLabels,3, Branch lblLabels,4, Semester lblLabels,5, Batch lblLabels,6, Add / Delete lblLabels,7, Date lblLabels,8, Staff Name data1 d:\Students.mdb Transfers txtFields,0,” ”, Roll No txtFields,1,” ”, Name txtFields,2,” ”, Course txtFields,3,” ”, Branch txtFields,4,” ”, Semester txtFields,5,” ”, Batch txtFields,6,” ”, Add / Delete txtFields,7,” ”, Date txtFields,8,” ”, Staff Name cmdAdd, Add cmdDelete,Delete cmdUpdate,Update cmdRefresh, Refresh cmdRefresh, Print cmdClose, Close 70

Methods and Events: Command : Click Data report : show Data: recordset, refresh, Validate(), Reposition(),Error() Recordset: movenext, delete, addnew, bookmark, lastmodified, absoluteposition Procedure: Main Form 1. Open a Data Report Project. 2. Place the textboxes, command buttons, data field and labels as shown in the form layout. 3. To create a mdb (Access) data base, go to add-ins -> visual data manager. Then select file -> new -> Microsoft access -> version 7.0 mdb and save using a file name ado on drive d. 4. Right click on database window and select new table. 5. In table structure window give the table name as “Transfers” and enter the required fields (Roll. No., Name, Course, Branch, Semester, Batch, Add/Delete, Date) then close. 6. Make change in the properties of data1, txtfields, datafield as mentioned above. Data Environment Form 1. Go to properties of connection by select and clicking the “Properties” icon on toolbar, then select “Microsoft jet 4.0 OLE Db Provider”, and then click on Next. 2. Select the Database Name as your File Name, check whether the Connection works properly by “Test Connection” and click on ok. 3. Add a Command on Connection by clicking the “Add Command” icon on toolbar. 4. Go to properties of Command by select and clicking the “Properties” icon on toolbar change the Command name as “Student”, Datebase object as “Table”, Object Name as “Transfers” and then click on Ok. Data Report 1. Changes in the properties of Data report from DataSource DataEnvironment1 DataMember Student 2. Remove the header and footer section in Report page. 3. Design a transfer circular by using the labels and textboxes as shown form layout. 4. Use label for Static text and text box for varying fields, Set the corresponding value to the properties DataMember and DataField. Source Code: Private Sub cmdAdd_Click() Data1.Recordset.AddNew End Sub Private Sub cmdDelete_Click() Data1.Recordset.Delete Data1.Recordset.MoveNext End Sub Private Sub CmdPrint_Click() DataReport1.Show End Sub Private Sub cmdRefresh_Click() Data1.Refresh End Sub

Data Environment

71

Private Sub cmdUpdate_Click() Data1.UpdateRecord Data1.Recordset.Bookmark = Data1.Recordset.LastModified End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub Data1_Error(DataErr As Integer, Response As Integer) MsgBox "Data error event hit err:" & Error$(DataErr) Response = 0 End Sub Private Sub Data1_Reposition() Screen.MousePointer = vbDefault On Error Resume Next Data1.Caption = "Record: " & (Data1.Recordset.AbsolutePosition + 1) End Sub Private Sub Data1_Validate(Action As Integer, Save As Integer) 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 Screen.MousePointer = vbHourglass End Sub Output:

Result:

Thus a visual basic program has been written for the student transfer circular using data report is implemented and tested. 72

Ex.No. 18 Aim:

Creation of Chat application using WinSock Control

To write a Visual Basic program to create a chat application using Winsock control. Form Design:

Controls Used: Winsock control, text box, command button. Changes in Properties: Control Name Form1: Text box text1 Text box text1 Text box text1 Text box text1 Command button command1 Command button command1 Winsock winsock1 Form2: Text box text1 Text box text1 Text box text1 Command button command1 Command button command1 Winsock winsock1

Property

Value

name name name name name, caption name, caption name

txtstatus txthost txtsend txtport cmdconnect, connect cmdsend, send sockmain

name name name name. caption name, caption name

txtstatus txtport txtsend cmdconnect, connect cmdsend, send sockmain

Methods and Events: Socket: sendData, GetData, DataArrival(), ConnectionRequest(), accept requestID, listen, connect Command : Click() Procedure: 1. To invoke components, click project -> components then select Microsoft win sock control from components window. 2. Place the textboxes and command buttons as shown in the form layout. 3. On clicking the connect and listen buttons then the connection is established through TCP/IP. 4. On clicking send button the message on textsend box will be send to other vice versa. Source Code: 73

Form1:

Option Explicit Private Sub cmdConnect_Click() sockMain.RemoteHost = txtHost.Text sockMain.RemotePort = txtPort.Text sockMain.Connect End Sub Private Sub cmdSend_Click() sockMain.SendData txtSend.Text End Sub Private Sub Form_Load() Form2.Show txtStatus.Text = "" End Sub

Form2:

Private Sub sockMain_DataArrival(ByVal bytesTotal As Long) Dim strData As String sockMain.GetData strData, vbString txtStatus.Text = txtStatus.Text & _ strData & vbCrLf End Sub Private Sub Form_Load() txtStatus.Text = "" End Sub Private Sub cmdListen_Click() sockMain.LocalPort = txtPort.Text sockMain.Listen End Sub Private Sub sockMain_ConnectionRequest(ByVal requestID As Long) If sockMain.State sckClosed Then sockMain.Close End If sockMain.Accept requestID txtStatus.Text = txtStatus.Text & _ "Accepted connection from: " & _ sockMain.RemoteHostIP & vbCrLf End Sub Private Sub cmdSend_Click() sockMain.SendData txtSend.Text End Sub 74

Private Sub sockMain_DataArrival(ByVal bytesTotal As Long) Dim strData As String sockMain.GetData strData, vbString txtStatus.Text = txtStatus.Text & _ strData & vbCrLf End Sub Output:

Result:

Thus a visual basic program has been written to chat application using Winsock control is implemented and tested with various samples.

75

Ex. No. 19

Palindrome or Not

Aim:

To write a MFC program to find a given string is palindrome or not using Visual C++. Form Design:

Controls used: Edit Box, Static Text, Button. Changes in Properties: Control Name Button button1 Button button2 Member Variables: Control Name IDC_EDIT1

Property caption caption Category VALUE

Type int

Value Is Palindrome Exit Variable Name m_edit1

Methods and Events: Edit: MakeReverse(). Button: OnButton() Function: SetDlgItemInt() Procedure: 1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish. 2. Place the Static texts, edit boxes, Buttons as shown in the form Layout. 3. On clicking the Button1, display the given string in edit1 is whether palindrome or not in edit2. Source Code: void CPalindromeDlg::OnButton1() { CString S; UpdateData(true); S = m_edit1; m_edit1.MakeReverse (); if (S == m_edit1) SetDlgItemText(IDC_EDIT2,m_edit1 + " is Palindrome"); else SetDlgItemText(IDC_EDIT2,S + " is not Palindrome"); } 76

void CPalindromeDlg::OnButton2() { exit(0); } Output:

Result:

Thus a MFC Application has been created to find palindrome String Using Visual C++ is implemented and tested.

77

Ex. No. 20 Aim:

Fibonacci and Factorial

To write a MFC program to find Factorial and Fibonacci series using Visual C++.

Form Design:

Controls used: Edit Box, List Box, Radio Button, Button. Changes in Properties: Control Name Radio Button Radio1 Radio Button Radio1 List Box List1 Member Variables: Control Name IDC_EDIT1

Property Caption Caption Sort Category VALUE

Type int

Value Factorial Fibonacci False Variable Name m_edit1

Methods and Events: List: AddString(), ResteContrnt(), Radio: onRadio(). Button: onButton(). UpdateData(), itoa(). Procedure: 1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish. 2. Place the edit box, list box, radio buttons and button as shown in the form layout. 3. On clicking the radio button, the corresponding result will be displayed on the list box. Source Code: void CFactDlg::OnRadio1() { int S,a=1,i; char c[10]; UpdateData(true); m_list1.ResetContent(); S = m_edit1; for(i=1;i MFC .exe -> Dialog Based -> Finish. 80

2. Place the edit box and button as shown in the form layout. 3. On clicking the button1, Multiply the matrix values by using member variables and display. Source Code: void CMatrixDlg::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))); } Output:

Result:

Thus a MFC Application has been created to perform Multiplication of two Matrices Using Visual C++ is implemented and tested.

81

Ex. No. 22 Aim:

File Operation

To write a MFC Program to perform File operation using Visual C++.

Form Design:

Controls used: Edit Box, Button, Static Text. Changes in Properties: Control Name Button Button1 Button Button2 Member Variables: Control Name IDC_EDIT1 IDC_EDIT2

Category VALUE VALUE

Property Caption Caption Type CString CString

Value Copy Exit Variable Name m_edit1 m_edit2

Methods and Events: Button: OnButton(). Functions: CFile: Seek(), Read(), Write(),Open(). Procedure: 1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish. 2. Place the Edit box and button as shown in the form layout. 3. On clicking the button1, copy the contents of Source file to Destination file name. 4. For copying a file, Use the Class CFile Read the Source File and Write to the Destination File. 5. Display a Message Box after file has been copied. Source Code: void CFileDlg::OnButton1() { char szBuffer[1]; UINT nActual = 0,pos = 0; CFile myFile, myFile1; UpdateData(true); myFile.Open(m_edit1,CFile:: modeReadWrite); myFile1.Open(m_edit2,CFile::modeCreate|CFile:: modeReadWrite); while(1) { myFile.Seek( pos , CFile::begin ); nActual = myFile.Read( szBuffer, 1 ); myFile1.Write( szBuffer, 1 ); pos = pos + nActual; if (nActual == 0) 82

{

} }

}

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

Output:

Result:

Thus a MFC Application has been created to perform File Operation Using Visual C++ is implemented and tested.

83

Ex. No. 23 Aim:

Mouse Interface

To write a MFC program to find Factorial and Fibonacci series using Visual C++.

Form Design:

Controls used: Edit Box, Static Text, Boutton. Changes in Properties: Control Name Button button1

Property Caption

Value Exit

Events:

OnRButtonDown(), OnLButtonDown, OnLButtonDblClk(), OnRButtonDblClk(), SetDlgItemInt(). Procedure: 1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish. 2. Place the edit box, Static Text and button as shown in the form layout. 3. By using the mouse events increment a counter display the value on Edit Box. Source Code: int Count1,Count2; void CMouseDlg::OnRButtonDown(UINT nFlags, CPoint point) { Count2++; SetDlgItemInt(IDC_EDIT2,Count2); } void CMouseDlg::OnLButtonDown(UINT nFlags, CPoint point) { Count1++; SetDlgItemInt(IDC_EDIT1,Count1); } void CMouseDlg::OnButton1() { 84

}

exit(0);

void CMouseDlg::OnLButtonDblClk(UINT nFlags, CPoint point) { Count1++; SetDlgItemInt(IDC_EDIT1,Count1); } void CMouseDlg::OnRButtonDblClk(UINT nFlags, CPoint point) { Count2++; SetDlgItemInt(IDC_EDIT2,Count2); } Output:

Result:

Thus a MFC Application has been created for the Mouse Interface Using Visual C++ is implemented and tested.

85

Ex. No. 24 Aim:

Active – X Control

To write a MFC program to insert an Active X control using Visual C++.

Form Design:

Controls used: Active - X object, button. Changes in Properties: Control Name Button Button1 Button Button2

Property Caption Caption

Value OK Exit

Events:

Button: OnButton(). Procedure: 1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish. 2. Place the Active X object and button as shown in the form layout. 3. To insert the Active X Calendar, right Click on the form -> Insert Active X Control -> Calendar Control 12.0. 4. On clicking the OK button, display a Message box. Source Code: void CAxDlg::OnOK() { MessageBox("ActiveX Calendar"); } Output:

Result:

Thus a MFC Application has been created to Insert a Active X Control Using Visual C++ is implemented and tested.

86

Ex. No. 25 Aim:

Message Box Creation

To write a Win32 program to create a Message Box using Visual C++. Procedure: 1. Create a WIN32 application by selecting, File -> New -> Win32 .exe -> Finish. 2. To include a new C File, file -> New -> C Source File. 3. Read the free Memory Available in the system. 4. Store it in a buffer. 5. Display the Message box. 6. End. Source Code: #include int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { DWORD dwMemAvail; char szBuffer[80]; dwMemAvail=GetFreeSpace(0); wsprintf(szBuffer,"Memory Available: %lu",dwMemAvail); MessageBox(NULL,szBuffer,"GLOBELMEM",MB_OK); return 0; } Output:

Result:

Thus a Win32 Application has been created to display a Message box Using Visual C++ is implemented and tested.

87