190 likes | 358 Views
VISUAL BASIC. Lecture #4 WORKING WITH FRAMES. By Shahid Naseem (Lecturer). LECTURE OUTLINES. LECTURE OUTLINES. Event of command buttons Uses of Command buttons List box controls Programs. BOOKS AVAILABLE IN MARKET. C Programming using Turbo C++ Schaum Series
E N D
VISUAL BASIC Lecture #4 WORKING WITH FRAMES By ShahidNaseem (Lecturer)
LECTURE OUTLINES • Event of command buttons • Uses of Command buttons • List box controls • Programs Introduction of Visual Basic (Civil Engineering Department)
BOOKS AVAILABLE IN MARKET • C Programming using Turbo C++ Schaum Series • Introduction to Computer 7thedition Peter Norton • How to Programming with C++ 8th Edition Deitel & Deitel • Visual Basic 2005 EvangelosPetroutsos Introduction of Visual Basic (Civil Engineering Department)
DEBUGGING • The errors in the program are called bugs. The process to detect and to remove errors in the program is called debugging. • Syntax errors • Run time errors • Logical errors Syntax errors • The rules for writing the computer programs in a programming language is known as syntax of the language. • The syntax errors occurred when the syntax of the programming language are not followed. • The syntax errors are easy to locate and remove. Introduction of Visual Basic (Civil Engineering Department)
DEBUGGING e.g. Private sub command1 _click (() For 1,10 End sub Message Compile error Expected: to Run time errors • The errors that are occur during the execution of program are called the run time errors. • If input data given to the program is not correct. • If hardware problem occurs such as hard disk error. Introduction of Visual Basic (Civil Engineering Department)
WORKING WITH FORM • Event of Form • Load: when form is loaded in the memory • Unload: when form is unloaded from the memory. • Activate: When form is on the screen • Deactivate: When form is Off from the screen • Resize: When form is resized. • Methods of form: • The show method • The hide method • The print form method • The unload statement. Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#4 • Develop an application program having form with no GUI control. It should perform the following actions when user interacts with form. • The form appears maximized when program is run. • Set background color appears as “red” when mouse is single clicked on the form and background color is changed to “green” when mouse is double clicked on the form. Form1CaptionForm testing program Window state 2-maximized Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#4 Private Sub Form_Click() Form1.BackColor = vbRed End Sub Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#4 • Private Sub Form_DblClick() • Form1.BackColor = vbGreen • End Sub Introduction of Visual Basic (Civil Engineering Department)
EVENT OF COMMAND BUTTONS Click: • The click event is the primary and commonly used event of command button. • It is triggered when: • Command button is singled clicked. • Command button has the focus and the enter key or spacebar key is pressed. • Command button access key is pressed. Dbl Click: • This event of command button is triggered when mouse is double clicked on button. Mouse Click: • This event of command button is triggered when mouse pointer is moved over the button. Got Focus: • This event of command button is triggered when it gets focus. Lost Focus: • This event of command button is triggered when it loses focus. Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#5 Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#5 Form1 Caption Command Button Application Command1 Caption First Button Style Graphical Command2 Caption Second Button Style Graphical Command3 Caption Third Button Style Graphical Private Sub Command1_Click() Form1.BackColor = vbRed Command1.BackColor = vbGreen Command2.BackColor = vbYellow Command3.BackColor = vbBlue End Sub Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#6 Develop an application program to perform simple arithmetic operations by two numbers. Form1 Caption Arithmetic Operations Label1 Caption Enter First Number Label2 Caption Enter Second Number Label3 blank Text1 blank Text2 blank Command1 Caption Operation Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#6 Private Sub Command1_Click() Label3.Caption = Val(Text1.Text) + Val(Text2.Text) End Sub Introduction of Visual Basic (Civil Engineering Department)
LIST BOX CONTROL The list box control is used to display a long list of items. Properties Events List List count List Index Click Mouse Select Dbl Click Style Selected Select Count Sorted Index Text Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#7 Develop an application program to add and delete items to and from the list at runtime as • Type the text box and click add button to add the item to list box. • Select the item from list and click delete button to delete the selected item. Introduction of Visual Basic (Civil Engineering Department)
PROGRAM#7 Private Sub Command1_Click() List1.AddItem Text1.Text Text1.Text = "" End Sub Private Sub Command2_Click() List1.RemoveItem (List1.ListIndex) End Sub Introduction of Visual Basic (Civil Engineering Department)