Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of visual basic

Similar presentations


Presentation on theme: "Fundamentals of visual basic"— Presentation transcript:

1 Fundamentals of visual basic

2 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.

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

4 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.

5 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.

6 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.

7 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.

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

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

10 PROGRAM CONTROL STRUCTURES

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

12 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.

13 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

14 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

15 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

16 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

17 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

18 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

19 Repetition Structure

20 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.

21 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

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

23 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 .

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

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

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

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

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

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

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

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

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

33 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 .

34 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 .

35 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 .

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

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

38 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


Download ppt "Fundamentals of visual basic"

Similar presentations


Ads by Google