1 / 26

VISUAL BASIC

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

ketan
Download Presentation

VISUAL BASIC

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VISUAL BASIC Lecture #3 PROBLEM SOLVING METHOD By ShahidNaseem (Lecturer)

  2. LECTURE OUTLINES

  3. 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)

  4. 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)

  5. 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)

  6. 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)

  7. 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)

  8. 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)

  9. 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)

  10. 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)

  11. 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)

  12. 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)

  13. GRAPHIC USER INTERFACE (GUI) Introduction of Computer (Civil Engineering Department)

  14. 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)

  15. 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)

  16. 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)

  17. PROGRAM#2 • Write a program to implement the Got Focus and lost focus using the command buttons. Introduction of Computer (Civil Engineering Department)

  18. 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)

  19. 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)

  20. 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)

  21. 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)

  22. 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)

  23. 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)

  24. 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)

  25. PROGRAM#4 Private Sub Form_Click() Form1.BackColor = vbRed End Sub Introduction of Computer (Civil Engineering Department)

  26. PROGRAM#4 • Private Sub Form_DblClick() • Form1.BackColor = vbGreen • End Sub Introduction of Computer (Civil Engineering Department)

More Related