Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.

Slides:



Advertisements
Similar presentations
Chapter 6: The Repetition Structure
Advertisements

Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
CS0004: Introduction to Programming Repetition – Do Loops.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Repeating Actions While and For Loops
Excel and VBA Creating an Excel Application
String Variables Visual Basic for Applications 4.
CSC110 Fall Chapter 5: Decision Visual Basic.NET.
Using the Visual Basic Editor Visual Basic for Applications 1.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
MsgBox Function Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon After displaying.
5.05 Apply Looping Structures
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic Chapter 1 Mr. Wangler.
© 1999, by Que Education and Training, Chapter 5, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Working with option button, check box, and list box controls Visual Basic for Applications 13.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Chapter 6: The Repetition Structure
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Visual Basic Programming
Programming with Microsoft Visual Basic th Edition
Introduction to Problem Solving and Control Statements.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Computer-made Decisions Chapter 3 & 4. Overview u Variable Scope u Conditionals  Relational Operators  AND, OR, NOT u If Statements u MsgBox function.
Chapter 7 - Lists, loops and printing w List boxes and combo boxes several types can add items at design time or during run time user select from predefined.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Controlling Program Flow with Looping Structures
Unit 6 Repetition Processing Instructor: Brent Presley.
Controlling Program Flow with Decision Structures.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Tutorial 81 Field, Record, Data File Field - a single item of information about a person, place, or thing Record - a group of related fields that contain.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 9: Chapter 5: Slide 1 Unit 9 Do Until and For… Next Loops Chapter 5 Lists,
Custom Dialog Box Alternatives And Dealing with FileNames Joanna Wyrobek.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
Visual Basic.NET Windows Programming
Microsoft Visual Basic 2008: Reloaded Third Edition
3rd prep. – 2nd Term MOE Book Questions.
Repeating Program Instructions
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Presentation transcript:

Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection - allows the program to make a decision/comparison and then select the appropriate action to take based on that decision/comparison Repetition - (looping or iteration) tells the computer to repeat one or more instructions either a specified number of times or until some condition is met

Tutorial 52 Forms of the Repetition Structure For Next Do While Do Until

Tutorial 53 For Next Loop Tells the computer to repeat one or more statements a specified number of times. Called a pretest loop because the loop is evaluated before the instructions are processed Syntax: For counter = startvalue To endvalue [Step stepvalue] [instructions you want repeated] Next counter counter is the name of a numeric variable and it keeps track of how many times the loop instructions are repeated startvalue, endvalue, and stepvalue must be numeric and they can be either positive or negative, integer or non-integer (default stepvalue is 1)

Tutorial 54 For Next Loop Tasks The loop initializes the counter to the startvalue (done only once, at the beginning of the loop) If the stepvalue is positive (negative), the loop checks if the value in counter is greater than (less than) the endvalue. If it is, the loop stops; otherwise the instructions within the loop are processed and the next task is performed The loop adds the stepvalue to the counter. It then repeats the prior two steps

Tutorial 55 Flowchart and Pseudocode Hexagon Repeat for intCount = 1 to 3 by 1 Print intCount Next intCount intCount 1 > 3 1 Print intCount

Tutorial 56 Do While and Do Until Loops Do While loop repeats a block of instructions while a condition is true You also can use a Do While loop to repeat a block of instructions a specified number of times Do Until loop repeats a block of instructions until a condition becomes true You also can use a Do Until loop to repeat a block of instructions a specified number of times

Tutorial 57 Syntax of the Do While and Do Until Loops Do While condition [loop instructions] Loop Do [loop instructions] Loop Until condition condition must evaluate to true or false condition can contain variables, constants, properties, functions, mathematical operators, relational operators, and logical operators

Tutorial 58 Do While and Do Until Loops In the Do While loop, the instructions are processed only when the condition evaluates to true; the loop stops when the condition evaluates to false Called a pretest loop In the Do Until loop, the instructions are processed only when the condition evaluates to false; the loop stops when the condition evaluates to true Called a posttest loop

Tutorial 59 Do While Loop intCount = 1 Repeat while intCount <= 3 Display intCount Add 1 to intCount End Repeat while intCount <= 3 intCount = 1 intCount <= 3 Display intCount intCount = intCount + 1 F T

Tutorial 510 Do Until Loop intCount = 1 Repeat Display intCount Add 1 to intCount End Repeat until intCount > 3 intCount = 1 intCount > 3 Display intCount intCount = intCount + 1 F T

Tutorial 511 Counters and Accumulators Used within a repetition structure to calculate subtotals, totals, and averages Initialized (usually to 0 or 1) outside the loop and updated within the loop A counter is a numeric variable used for counting something and is typically updated by 1 An accumulator is a numeric variable used for accumulating (adding together) and is updated by an amount that varies

Tutorial 512 Calculating an Average Average = accumulator / counter Be sure to verify that counter is greater than 0 before calculating the average Use the If…Then…Else selection structure

Tutorial 513 Control Arrays Group of controls of the same type that have the same name and share the same set of event procedures Each control in the array is identified by the array’s name and a unique index The first control in the array has an index of 0

Tutorial 514 Creating a Control Array To make existing controls into an array, simply assign the same name to each control. When you are asked if you want to create a control array, click the Yes button If the controls are not already on the form, place the first control on the form and set its name and other properties Copy the control to the clipboard, then paste the appropriate number of controls on the form When you are asked if you want to create a control array, click the Yes button

Tutorial 515 Control Array Code Window Index As Integer appears in the Code windows for a control array All controls in the array share the same set of Code windows Index contains an integer that represents the value stored in the Index property of the control receiving the event

Tutorial 516 Index Property vs Index Argument The Index property stores a number that identifies each control in the array Each control in the array has a value in its Index property The Index property is like an address The Index argument found in the Code window is a local variable created by Visual Basic The Index argument contains the address of the control receiving the event

Tutorial 517 Parallel Arrays Arrays whose contents are related by their position in the arrays--in other words, by their index chkDone(0)txtScore(0) chkDone(1)txtScore(1)

Tutorial 518 Enabled Property An object’s Enabled property determines whether the object can respond to user- generated events, such as clicking or entering information Can be set to True (default) or False It is customary in Windows applications to disable objects that don’t apply to the current state of the application

Tutorial 519 GotFocus Event Occurs when a control receives the focus It is customary in Windows applications to highlight a text box’s existing text when the text box receives the focus. You do so by setting the text box’s SelStart and SelLength properties

Tutorial 520 Change Event Occurs when the contents of an object are changed You can use this event to clear the results of calculations from label controls when the contents of a text box has changed

Tutorial 521 Alignment Property You can use the Alignment property to align the contents of a label control You also can use the Alignment property to align the contents of a text box, but you must be sure to set the text box’s MultiLine property to True and also code its KeyPress event to prevent the text box from recognizing the Enter key

Tutorial 522 MsgBox Function Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon After displaying the dialog box, the MsgBox function waits for the user to choose a button, then returns a value that indicates which button the user selected

Tutorial 523 MsgBox Function Syntax: MsgBox(prompt[, buttons][, title][,helpfile, context]) prompt is the message you want displayed buttons is a numeric expression that specifies the number and type of buttons, the icon, the default button, and the modality title is a string expression displayed in the title bar

Tutorial 524 Modality Application modal Default modality; user must respond to the dialog box’s message before he or she can continue working in the current application; the user still can access other applications System modal All applications are suspended until the user responds to the dialog box’s message

Tutorial 525 buttons Argument ConstantValueDescription vbOKOnly0Display OK button only. vbOKCancel1Display OK and Cancel buttons. vbAbortRetryIgnore2Display Abort, Retry, and Ignore buttons. vbYesNoCancel3Display Yes, No, and Cancel buttons. vbYesNo4Display Yes and No buttons. vbRetryCancel5Display Retry and Cancel buttons. vbCritical16Display Critical Message icon. vbQuestion32Display Warning Query icon. vbExclamation48Display Warning Message icon. vbInformation64Display Information Message icon. vbDefaultButton10First button is default. vbDefaultButton2256Second button is default. vbDefaultButton3512Third button is default. vbDefaultButton4768Fourth button is default. vbApplicationModal0Application modal; the user must respond to the message box before continuing work in the current application. vbSystemModal4096System modal; all applications are suspended until the user responds to the message box.

Tutorial 526 Return Values ConstantValueDescription vbOK1OK vbCancel2Cancel vbAbort3Abort vbRetry4Retry vbIgnore5Ignore vbYes6Yes vbNo7No

Tutorial 527 Unload Event Occurs when a form is about to be removed from the screen and memory Triggered when you use the Unload statement in code or when you click the Close button to close the form Use the Unload event to verify that the user wants to exit an application and also for code that saves and closes files

Tutorial 528 Unload Statement vs Unload Event The Unload statement tells Visual Basic to unload the form The Unload event is the procedure that occurs before the form is unloaded

Tutorial 529 Unload Event Code Window The Cancel argument is a local variable created by Visual Basic and it contains the value 0 To prevent the form from being unloaded, set Cancel to a value other than 0

Tutorial 530 Debugging Technique You can use the KeyPress event to control what the user can enter into a text box