Visual Basic 6 Programming.

Slides:



Advertisements
Similar presentations
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Advertisements

CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
Loops – While, Do, For Repetition Statements Introduction to Arrays
BACS 287 Programming Fundamentals 4. BACS 287 Programming Fundamentals This lecture introduces the following iteration control structure topics: – Do.
Chapter 61 Flags A flag is a variable that keeps track of whether a certain situation has occurred. The data type most suited to flags is Boolean.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
5.05 Apply Looping Structures
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
ENGR 112 Decision Structures.
Arrays and 2D Arrays.  A Variable Array stores a set of variables that each have the same name and are all of the same type.  Member/Element – variable.
# 1# 1 Searching andSorting What is selection sort? What is bubble sort? What is binary search? CS 105 Spring 2010.
Visual Basic CODE. Basics of Code Declaration Declaration Set aside a named place to put things Set aside a named place to put things Assignment Assignment.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
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.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Visual Basic Programming
I Power Higher Computing Software Development High Level Language Constructs.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
CompMathBSc, English 5 October 2006 Programming basics — continued  Arrays  Cycle Statements: Loops  Control Structures vs Conditions  Subs: Procedures.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Higher Computing Software Development -So Far- 5/10/10.
Controlling Program Flow with Looping Structures
BACS 287 Programming Fundamentals 5. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Procedures Built-in Functions User-defined.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
Making Interactive Programs with Visual Basic .NET
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 5 - VB 2008 by Schneider1 Chapter 5 – Repetition 5.1 Do Loops 5.2 Processing Lists of Data with Do Loops 5.3 For...Next Loops.
Arrays 1.
Welcome to Computer Programming II! Computer Programming II Summer 2015.
Visual Basic 6.0 Final Review
UNIT 5 Lesson 15 Looping.
VBA - Excel VBA is Visual Basic for Applications
VBA - Excel VBA is Visual Basic for Applications
VBScript Session 1 IT Professional Academy.
Visual Basic 6 (VB6) Data Types, And Operators
2. Understanding VB Variables
Web Programming– UFCFB Lecture 16
Arrays, For loop While loop Do while loop
Visual Basic 6 Programming.
Department Array in Visual Basic
Outline Altering flow of control Boolean expressions
Don’t Leave Home Without them
Chapter (3) - Looping Questions.
Visual Basic 6 Programming.
Visual Basic 6 Programming.
3.1 Iteration Loops For … To … Next 18/01/2019.
CISC181 Introduction to Computer Science Dr
Lecture 3 : January 2001 Dr. Andrew Paul Myers
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Intro to Programming Concepts
Visual Basic Programming
Conditional Loops Counted Loops
For...Next Statements.
Introduction to Computer Programming IT-104
Presentation transcript:

Visual Basic 6 Programming. Lecture 3 : February 2004 Dr. Andrew Paul Myers 01/12/2018

Scope of Variables. So far variables have been local to procedures (subroutines). Could have the same names, but different values. We can have : Form level variables. Declare in “Declarations – General”, i.e with Option Explicit statement. 01/12/2018

Scope of Variables. Option Explicit Private intValue as Integer Public sngRadius as Single Private Sub Form_Load() ‘ Some VB statements! End Sub ------------------------ Private : Form level variable Public : All forms. 01/12/2018

Doing it again & again. So far… The order VB statements are executed inside a subroutine can be changed using conditional statements. VB statements can be repeated by using loops (there are several types). 01/12/2018

For… Next Loop. General Form: e.g. For <counter> = <start> To <stop> Step <increment> <statement(s)> Next <counter> e.g. For intLoop = 0 To 10 Step 1 MyTextBox.SelText = Str(intLoop) & vbCrLf Next intLoop 01/12/2018

Nested Loops. Dim intLoop As Integer Dim sngX As Single For intLoop = 1 To 10 For sngX = 0# to 10# Step 0.1 <Statement(s)> Next sngX Next intLoop 01/12/2018

Indeterminate Loops. These do not execute a fixed number of times! General Form: Do <statement(s)> Loop Until <condition(s)> 01/12/2018

Do... Until Loop. Dim strPassWord As String Do strPassWord = _ InputBox(“Password?”) Loop Until strPassWord = “123” 01/12/2018

More Error Checking. <statement(s)> Do strX = InputBox(“Enter a +ve no.”) If (IsNumeric(strX) = False) Then strX = “-1” Loop Until ( Val(strX) > 0 ) 01/12/2018

More Loops. e.g. Do <statements(s)> Loop While <condition(s)> e.g. <statement(s)> Loop While ( dblValue < 0# ) 01/12/2018

Yet More Loops… Do While <condition> <statement(s)> Loop e.g. Dim blnProg_Finished As Boolean blnProg_Finished = False Do While (blnProg_Finished = False) 01/12/2018

Arrays. An array is a simple structure, capable of storing many variables of the same type in a single data structure. Declare arrays with other variables. Arrays can be of any data type. Scope can be global to a form or local to a procedure, but not global to all forms! 01/12/2018

Declaring Arrays. Dim sngValue(6) As Single This sets up 7 single precision variables called : sngValue(0) sngValue(1) sngValue(2) sngValue(3) sngValue(4) sngValue(5) sngValue(6) Each identified by a unique subscript in brackets. 01/12/2018

Using Arrays. After declaration, they can be used in the same way as other variables, but remember the subscript!!! e.g. Dim intArray(20) As Integer intArray(1) = 1 intArray(2) = 2 intArray(3) = 3 * 3 + 2 + intX 01/12/2018

Array Storage. intX(0) intX(1) intX(2) intX(3) intX(4) Arrays can be thought of thus: e.g. If we have a 5 element array. Dim intX(4) intX(0) = 21 intX(1) = 22 intX(2) = 23 etc… intX(0) intX(1) intX(2) intX(3) intX(4) 21 22 23 24 25 01/12/2018

Using Arrays. Dim intLoop As Integer Dim intArray(20) As Integer For intLoop = 0 To 20 intArray(intLoop) = 0 Next intLoop 01/12/2018

Using Arrays. Dim intLoop As Integer Dim dblArray(360) As Double, dblPi As Double dblPi = 4# * Atn(1#) For intLoop = 0 To 360 dblArray(intLoop) = Sin(intLoop * dblPi / 180#) Next dblLoop 01/12/2018

More on Arrays. Arrays bounds can be user defined: Dim strName( 5 To 10 ) As String Dim sngX( -25 To 25 ) As Single intValue = LBound(sngX) gives -25 intValue = UBound(sngX) gives 25 01/12/2018

Scope of Arrays. Local : Private Sub Form_Load() Dim strName(20) As String End Sub Global : In “General Declarations”. Option Explicit Private strName(20) As String Note : You can not share arrays across forms! 01/12/2018