Fundamentals of visual basic

Slides:



Advertisements
Similar presentations
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
Advertisements

Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 04 (Part III) Control Statements: Part I.
Introduction to C Programming
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
Introduction to C Programming
VB .NET Programming Fundamentals
Adding Automated Functionality to Office Applications.
Basic Elements of C++ Chapter 2.
5.05 Apply Looping Structures
Lecture Set 5 Control Structures Part D - Repetition with Loops.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
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.
Chapter 2: Using Data.
Flow of Control Part 1: Selection
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Visual Basic Programming
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Controlling Program Flow with Decision Structures.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Chapter 7 JavaScript: Control Statements, Part 1
Chapter 1.2 Introduction to C++ Programming
Chapter 10 Programming Fundamentals with JavaScript
Chapter 4 – C Program Control
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Visual Basic 6 (VB6) Data Types, And Operators
Basic Elements of C++.
Problem Solving and Control Statements: Part 2
Revision Lecture
The Selection Structure
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Ch 7: JavaScript Control Statements I.
Basic Elements of C++ Chapter 2.
Arrays, For loop While loop Do while loop
Chapter 10 Programming Fundamentals with JavaScript
Data Types, Identifiers, and Expressions
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Chapter (3) - Looping Questions.
T. Jumana Abu Shmais – AOU - Riyadh
3 Control Statements:.
3.1 Iteration Loops For … To … Next 18/01/2019.
ICT Programming Lesson 3:
Chapter 2: Introduction to C++.
Fundamental Programming
Chapter 4 - Program Control
Variables and Constants
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

Fundamentals of visual basic

Comments 1. are inserted to document programs and to improve readability. 2. help other people to read and understand your program code. 3. do not cause the computer to perform any action when a program is running as the compiler ignore it. 4. can begin with either ‘ or Rem (short for Remark) and is a single line-comment that terminated at the end of the current line. 5. colored green.

Comments..cont Example: ‘ Code for the single selection Rem Code for the single selection

Keywords 1. reserved words that cannot be used for anything other than for the features they represents. (e.g. Private, Sub, End, Print, etc.) 2. colored blue. 3. Visual Basic sets to uppercase the first letter of keywords, so typing dim would be changed to Dim.

Variable 1. location in the computer memory where a value can be stored for use by a program. 2. A variable name is any valid identifier. 3. A variable name should not be any of the Visual Basic keywords and must begin with a letter. 5. It must not contain a space or any of the special characters. Underscore (_) is the only special character accepted. 6. The maximum length of a variable name is 255 characters containing only letters, numbers, and underscores.

Constant Example: Dim Var_name As Type Dim Input1 As Integer Has a fixed value and may not be changed by the program as it run.

Data Types describe the information that a variable may store or hold. 2. describe how many bytes of memory are required to represent a type. 3. the number of bytes determined the range of values that can be stored. 4. Byte sizes and range values are fixed. 5. assigning any value outside a data type’s range is a run-time error.

Operators Expressions - are symbols that trigger computations, comparisons, and decisions. - Are combinations of operators and operands Expressions

Operators Expressions - are symbols that trigger computations, comparisons, and decisions. - Are combinations of operators and operands Expressions

PROGRAM CONTROL STRUCTURES

PROGRAM CONTROL STRUCTURES Refers to the order of program execution whether statements are executed sequentially, repeatedly, or conditionally or selectively

Ten (10) Program Control Structures 1. Sequence Control Structure - Statements are executed one after the other in the order in which they are written (called as Sequential Execution) - Considered as the simplest form of a program control structure where the statements are executed from top to bottom.

Sequence Control Structure Sequence Control Structure..cont Example: Dim x As Integer, y As Integer, sum As Integer X=3 Y=4 Sum = x+y Label1.caption = “The sum is:” & sum

If <condition> Then Statements End if 2. Selection Structure 2.1. Single Selection - performs or selects an action if a condition is True and skips the action if the condition is False. Syntax: If <condition> Then Statements End if

2.2 Double Selection - performs an action if the condition is True and performs a different action if the condition is False. Syntax: If<condition>Then Statement1 Else Statement2 End if

If<condition1> Then Statement1 ElseIf<condition2> 3. Multiple Selection Syntax: (A) If<condition1> Then Statement1 ElseIf<condition2> Statement2 ElseIf<condition3> Statement3 ElseIf<condition4> Statement4 End If

Select Case Multiple Structure Select Case <var_name> Syntax(B): Select Case <var_name> Case Is <range_of_values> Statement Case <value> Case<value1> To <value2> Case <value1>,<value2>,<value3> To <value4> Statement Case Else End Select

Example: Dim nGrade As Integer nGrade = Val(Text1.Text) Select Case ngrade Case Is >= 90 Text2.Text = “A” Case 80 To 89 Text2.Text = “B” Case 70 To 79 Text2.Text = “C” Case 60 To 69 Text2.Text = “D” Case Is < 60 Text2.Text = “F” End Select

Repetition Structure

Looping Statements - Is a program instruction that repeats some statement or sequence of statements in a specified number of times. - Allows a set of instructions to be performed all over and over again until a certain condition is reached, met, proven or tested as false or true. - Allows us to execute one or more lines of code repetitively.

6 Types of Repetition Control Structures 1. While/Wend 2. Do 2 6 Types of Repetition Control Structures 1. While/Wend 2. Do 2.1Do While/Loop 2.2 Do/ While Loop 2.3 Do Until/Loop 2.4 Do/ Until Loop 3. For / Next

1. While/Wend Syntax: Index While [condition] Statement/s Wend

Parts Index – a user defined numeric variable that the loop uses as a counter . Condition- Optional. Boolean expression. If condition is Nothing, Visual Basic treats it as False. Statement- Optional. One or more statements that are repeated while, or until, condition is True. Step - is an optional keyword indicating the loop should step .

Example: Cnt = 1 While cnt<11 Print cnt; Cnt = cnt + 1 Wend

[Step: Increment or Decrement] Loop 2. Do 2.1Do While/Loop Syntax: Index Do While [Condition] Statement/s [Step: Increment or Decrement] Loop

Example: cnt = 1 Do While cnt <11 Print cnt cnt = cnt +1 Loop

[Step: Increment or Decrement] Loop While [Condition] 2.2 Do/ While Loop Syntax: Index Do Statement [Step: Increment or Decrement] Loop While [Condition]

Example: cnt = 1 Do Print cnt; cnt = cnt +1 Loop While cnt<1

[Step: Increment or Decrement] Loop 2.3 Do Until/Loop Syntax: Index Do Until [condition] Statement [Step: Increment or Decrement] Loop

Example: cnt = 1 Do Until cnt = 11 Print cnt; cnt = cnt +1 Loop

2.4 Do/ Until Loop Syntax: Index Do Statement [Step: Increment or Decrement] Loop Until [Condition]

Example: cnt=1 Do Print cnt; cnt = cnt + 1 Loop Until cnt = 11

3. For / Next Parts: The For is the keyword you use to start the loop. Index1 - is a user defined numeric variable that the loop uses as a counter . start -is the number from which the loop starts from .

To - is the keyword which separates the start and end numbers To - is the keyword which separates the start and end numbers . end - is the number at which the loop stops. Step(Keyword) - is an optional keyword indicating the loop should step .

step - is the size of increment / decrement the step should have (this can be a negative number) Next - is the keyword that completes the loop . index2 - is used to identify which index is updated by the Next keyword .

Syntax: For index1 = start To end [Step step] [ Statements ] Next [index2] Sample: For cnt=1 To 10 Print cnt; Next cnt

End of the slides “Your value is not who you are and what you have, but how other people have become because of you” - 

End of the slides “Heaven is not for people who are better than the rest, but for people who sincerely try to become better than who they are..” - John 3:3