PROBLEM SOLVING The first step in writing instructions to carry out a task is to determine what the output should be (What should the task produce?) The second step is to identify the data, or input, necessary to obtain the output The final step is to determine how to process the input to obtain the desired output INPUT OUTPUT PROCESSING
37
Embed
PROBLEM SOLVING The first step in writing instructions to carry out a task is to determine what the output should be (What should the task produce?) The.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
PROBLEM SOLVING
The first step in writing instructions to carry out a task is to determine what the output should be (What should
the task produce?)
The second step is to identify the data, or input, necessary to obtain the output
The final step is to determine how to process the input to obtain the desired output
INPUT OUTPUTPROCESSING
PROGRAM DESIGN TOOLS
Flowcharts: graphically depict the logical steps to carry out a task and show how the steps relate to each other
Pseudocode: uses English-Like phrases with some (Visual Basic) terms to outline the task
Hierarchy Charts: show how the different parts of the program relate to each other (referred to as Structure Charts, HIPO (Hierarchy plus Input-Process-Output) Charts, Top-Down Charts or VTOC (Visual Table of
Contents) Charts.)
RENTING A VIDEO
START
GET CUSTOMER NUMBER
REFUSE RENTAL PROCESS
RENTAL PROCESS
GET VIDEO NUMBER
VALIDATE NUMBER
PROCESS CUSTOMER
NUMBER
END
VALIDATE NUMBER
Valid
Invalid
InvalidValid
Achieve program clarity throughStructured Programming
Command Button ‘Name’ how the computer recognises/identifies the control/object
‘Caption’ relates to the user identification of the control/object
Text Box ‘Text’ property: ‘Blank’‘Name’ property: like command button
Form Window State ‘Maximise’, relates to maximising the form when the project is executed
The Form Layout Window, this indicates the position of the form on the desktop, when the execution of the
project begins
The Toolbox holds the tools that are used to place controls on the form
The tools displayed on the toolbox, may be different, depending on the edition and release of VB being
used
‘Professional Edition’
The Main Visual Basic Window holds the VB menu bar, the toolbar, and the form location and size
information
The Toolbar, the buttons on the toolbar can be used as shortcuts for frequently used operations
Each button represents a command that can be executed by clicking on the button or by choosing a
command from the menu bar
The Form Location and Size Information identifies the size and position of the form on the screen
Help VB has an extensive ‘Help’ facility
VB contains what is called ‘Context-Sensitive’ help
Design Time, Run Time, Break Time
VB has 3 distinct modes:
Design Time: relates to designing the ‘User-Interface’ and writing code
Run Time: relates to testing and running the project
Break Time: if there is a ‘run-time error’ or project execution is paused
VB Project Example
The first ‘Event-Driven’ project will create a form with 3 controls
It will display the message ‘Hello world’ when the user clicks the ‘Push Me’ command button, and will terminate when the user clicks the ‘Exit’ command button
(Tip: If the Project Explorer Window/Properties Window/Toolbox are not displayed, open the View menu and select Project Explorer Window/Properties Window/ Toolbox
Project Tips
Do not confuse the ‘Name’ and ‘Caption’ properties
‘Name’ refers to the control in the VB code‘Caption’ refers to the users view on the form
VB sets both of these properties to the same value by default, and therefore it is easy to confuse them
NB: Always set the ‘Name’ property of controls before writing code
If the ‘Name’ of an object is changed after the code has been written, then the code becomes separated from the
object and the program does not run properly
When a VB project is running, the user can do many things
Each action by the user causes an ‘Event’ to occur in the VB project
If you write VB code for a particular event, the VB will respond to the event and automatically execute your
procedure (eg: clicking on a command button)
VB ignores events for which no procedures are written
(eg: moving the mouseresizing a window
opening another application)
VB code written in proceduresWe deal with writing code in ‘Sub Procedures’ or ‘Sub
Programs’
Begins with: Private SubEnds with: End Sub
VB automatically names the event proceudres
The ‘Name’ consists of the object name, an underscore ( _ ), and the name of the event
(name of the command button is cmdPush and there is a Click event for the command button
Therefore, the name of the Sub Procedure:
cmdPush_Click
VB Code Statements
3 types of VB statement
The Remark statement, known as comments, are used for project documentation only Begin with an
apostropheNot executable
Comments make the project more readable and understandable
The inclusion of comments is seen as good programming practice
It is a good idea to comment within the logic of the project, especially if the purpose of any statement is
unclear
The Assignment statement assigns a value to a property or variable
Assignment statements operate form Right to Left, that is the value appearing on the right hand side of the equal sign (=) is assigned to the property named