260 likes | 407 Views
VISUAL BASIC. Lecture #3 PROBLEM SOLVING METHOD. By Shahid Naseem (Lecturer). LECTURE OUTLINES. LECTURE OUTLINES. Problem Solving Method / SDLC Algorithm Pseudocode Sequence Logic Selection Logic Iteration Logic Visual Basic IDE and its Elements
E N D
VISUAL BASIC Lecture #3 PROBLEM SOLVING METHOD By ShahidNaseem (Lecturer)
LECTURE OUTLINES • Problem Solving Method / SDLC • Algorithm • Pseudocode • Sequence Logic • Selection Logic • Iteration Logic • Visual Basic IDE and its Elements • Project Explorer window and its properties • Tool Box • Set Focus Method • Focus Event • Get Focus • Lost Focus Introduction of Computer (Civil Engineering Department)
LECTURE OUTLINES • Visual Basic Project • Naming a project • Saving a project • Running a project • Executing a project • Stopping a project • Pausing a running project • Working with Form • Basic components of a form • Events of a form Introduction of Computer (Civil Engineering Department)
BOOKS RECOMMENDED • Programming with Structured Basics Schaum Series/Mc Graw Hill • Visual C++ (6) Deitel & Deitel/ T.R. Nieto • Black Book of C++ Steven Holzner • Mastering Visual Basic 6, Sybex Computer Book EvangelosPetroutsos Introduction of Computer (Civil Engineering Department)
PROBLEM SOLVING TECHNIQUE • Problem Solving is a creative process. The programmer must understand the problem completely and then should prepare a plan. • The phases or steps in program development are listed here. • Planning • Analysis • Design • Coding • Testing & Debugging • Implementation • Maintenance Introduction of Computer (Civil Engineering Department)
ALGORITHM • The method or the steps to solve a problem is called an algorithm. e.g. • Write an algorithm to get three numbers. Compute the sum and average of these numbers. • INPUT first number into L • INPUT second number into M • INPUT third number into N • SUM = L+M+N • AVERAGE = SUM/3 • PRINT SUM • PRINT AVERAGE • END Introduction of Computer (Civil Engineering Department)
PSEUDOCODE • Pseudocode is a problem solving tool. In pseudocode, the steps of the algorithm are number in such a way that action is executed or performed per line. • Pseudocode is also called “Program Design Language (PDL)”. • Pseudocode is developed by using the following basic structures. • Sequence Logic • Selection Logic • Iteration Logic Continue-- Introduction of Computer (Civil Engineering Department)
PSEUDOCODE Sequence Logic The sequence logic is used for performing instructions or steps one after the other in an order or sequence. Instruction – 1 Instruction – 2 ----------------- ----------------- ---------------- Instruction – n Continue-- Introduction of Computer (Civil Engineering Department)
PSEUDOCODE Selection Logic • The selection logic used for making decisions. Selection logic is also known as “Decision Logic”. • In pseudocode, IF-THEN-ELSE structure is used for selection logic. IF condition Then Instruction – 1 Else Instruction -2 End IF Continue-- Introduction of Computer (Civil Engineering Department)
PSEUDOCODE Iteration Logic • The Iteration logic is also known as repetition or looping structure. • This structure or logic is used to execute a set of information repeatedly. While condition Do condition For loop Introduction of Computer (Civil Engineering Department)
GRAPHIC USER INTERFACE (GUI) Visual Basic • Visual Basic is an integrated application development environment in which computer programs are written, compiled, debugged, test and run and also provides various tools which help the programmers to create window-based application programs. Graphic User Interface (GUI) • It provides a way for users to interact with the program’s components to perform different operations like INPUT, Processing and Output. Introduction of Computer (Civil Engineering Department)
GRAPHIC USER INTERFACE (GUI) Introduction of Computer (Civil Engineering Department)
VISUAL BASIC STATEMENT Visual Basic Statements • The VB statements are attached with each GUI component and they tell the computer what to do when users interact with the components. Program#1 Develop an application in VB to change the caption of form with the caption of button when any one of the buttons of the form is clicked. The form contains two buttons. Object Property Property Value Form1 Name Form1 Command1 Name Command1 Caption First Button Command2 Name Command2 Caption Second Button Introduction of Computer (Civil Engineering Department)
PROGRAM#1 Private Sub Command1_Click() Form1.Caption = Command1.Caption End Sub Private Sub Command2_Click() Form1.Caption = Command2.Caption End Sub Introduction of Computer (Civil Engineering Department)
FOCUS METHOD • VB also provides the set focus method used to set the focus to a specific object. • Focus Events Got Focus: This event of the control triggered when it gets the focus Lost Focus: This event of the control triggered when it loses the focus. Introduction of Computer (Civil Engineering Department)
PROGRAM#2 • Write a program to implement the Got Focus and lost focus using the command buttons. Introduction of Computer (Civil Engineering Department)
PROGRAM#2 • Write a program to implement the Got Focus and lost focus using the command buttons. Private Sub Command1_GotFocus() Command1.Caption = "got focus" End Sub Private Sub Command2_LostFocus() Command2.Caption = "lost focus" End Sub Introduction of Computer (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 Computer (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 Computer (Civil Engineering Department)
PROGRAM#3 • Develop an application program to divide first number by second number & display an error message if division error occurs. Introduction of Computer (Civil Engineering Department)
PROGRAM#3 • Develop an application program to divide first number by second number & display an error message if division error occurs. Private Sub Command3_Click() Dim x As Integer, y As Integer On Error GoTo xyz x = Text1.Text y = Text2.Text z = x / y MsgBox "Division Result=" & z Exit Sub xyz: MsgBox "Divide by zero error is occurred" End Sub Introduction of Computer (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 Computer (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 Computer (Civil Engineering Department)
PROGRAM#4 Private Sub Form_Click() Form1.BackColor = vbRed End Sub Introduction of Computer (Civil Engineering Department)
PROGRAM#4 • Private Sub Form_DblClick() • Form1.BackColor = vbGreen • End Sub Introduction of Computer (Civil Engineering Department)