VISUAL BASIC
description
Transcript of VISUAL BASIC
VISUAL BASIC
Lecture #3 PROBLEM SOLVING METHOD
ByShahid Naseem
(Lecturer)
LECTURE OUTLINES
LECTURE OUTLINESProblem Solving Method / SDLCAlgorithmPseudocode
Sequence LogicSelection LogicIteration Logic
Visual Basic IDE and its ElementsProject Explorer window and its propertiesTool BoxSet Focus MethodFocus Event
Get FocusLost Focus
Introduction of Computer (Civil Engineering Department)
LECTURE OUTLINESVisual Basic ProjectNaming a projectSaving a projectRunning a projectExecuting a projectStopping a projectPausing a running projectWorking with Form
Basic components of a form Events of a form
Introduction of Computer (Civil Engineering Department)
BOOKS RECOMMENDEDProgramming 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 Evangelos Petroutsos
Introduction of Computer (Civil Engineering Department)
PROBLEM SOLVING TECHNIQUEProblem 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.1. Planning2. Analysis3. Design4. Coding5. Testing & Debugging6. Implementation7. Maintenance
Introduction of Computer (Civil Engineering Department)
ALGORITHMThe 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.
1. INPUT first number into L2. INPUT second number into M3. INPUT third number into N4. SUM = L+M+N5. AVERAGE = SUM/36. PRINT SUM7. PRINT AVERAGE8. END
Introduction of Computer (Civil Engineering Department)
PSEUDOCODEPseudocode 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.1. Sequence Logic2. Selection Logic3. Iteration Logic
Introduction of Computer (Civil Engineering Department)
Continue--
PSEUDOCODESequence Logic
The sequence logic is used for performing instructions or steps one after the other in an order or sequence.
Instruction – 1Instruction – 2--------------------------------------------------Instruction – n
Introduction of Computer (Civil Engineering Department)
Continue--
PSEUDOCODESelection LogicThe 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 ThenInstruction – 1ElseInstruction -2End IF
Introduction of Computer (Civil Engineering Department)
Continue--
PSEUDOCODEIteration LogicThe Iteration logic is also known as
repetition or looping structure.This structure or logic is used to execute a
set of information repeatedly.
While conditionDo conditionFor loop
Introduction of Computer (Civil Engineering Department)
GRAPHIC USER INTERFACE (GUI)Visual BasicVisual 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 STATEMENTVisual 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#1Develop 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 ValueForm1 Name Form1Command1 Name Command1CaptionFirst ButtonCommand2 Name Command2CaptionSecond Button
Introduction of Computer (Civil Engineering Department)
PROGRAM#1
Introduction of Computer (Civil Engineering Department)
Private Sub Command1_Click()Form1.Caption = Command1.CaptionEnd SubPrivate Sub Command2_Click()Form1.Caption = Command2.CaptionEnd Sub
FOCUS METHODVB also provides the set focus method used
to set the focus to a specific object.
Focus EventsGot 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#2Write a program to implement the Got
Focus and lost focus using the command buttons.
Introduction of Computer (Civil Engineering Department)
PROGRAM#2Write a program to implement the Got Focus
and lost focus using the command buttons.
Introduction of Computer (Civil Engineering Department)
Private Sub Command1_GotFocus()Command1.Caption = "got focus"End SubPrivate Sub Command2_LostFocus()Command2.Caption = "lost focus"End Sub
DEBUGGINGThe 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 errorsThe 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)
DEBUGGINGe.g.
Private sub command1 _click (()For 1,10End sub
MessageCompile errorExpected: to
Run time errorsThe 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 IntegerOn Error GoTo xyzx = Text1.Texty = Text2.Textz = x / yMsgBox "Division Result=" & zExit Subxyz:MsgBox "Divide by zero error is occurred"End Sub
Introduction of Computer (Civil Engineering Department)
WORKING WITH FORMEvent 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#4Develop 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.
Form1 Caption Form testing program
Window state 2-maximized
Introduction of Computer (Civil Engineering Department)
PROGRAM#4
Private Sub Form_Click()Form1.BackColor = vbRedEnd Sub
Introduction of Computer (Civil Engineering Department)
PROGRAM#4
Private Sub Form_DblClick()Form1.BackColor = vbGreenEnd Sub
Introduction of Computer (Civil Engineering Department)