0% found this document useful (0 votes)
28 views

Using Logic of Programs With Conditions

From these documents you will able to learn step by step, and you will be able to create projects as well as you can be good programmer or a good teacher or trainer on your filed

Uploaded by

eshamu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Using Logic of Programs With Conditions

From these documents you will able to learn step by step, and you will be able to create projects as well as you can be good programmer or a good teacher or trainer on your filed

Uploaded by

eshamu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Using Logic Of Programs With Conditions

Variables and Constants


Computers internal memory consists of different locations in which data is stored, its to identify the memory locations to be able to retrieve values from or store values in them. We use variable to define and store the values in internal memory. The values stored in the variables are known as constants. Syntax of declaring variable in vb.net
Dim <variable_name> as <DataType>

Variables and Constants (Contd..)


Constants

10 num1

20 num2

30 sum

Variables

Data Types
It specify what type of value a respective variable can hold.
Data Type Byte Char Integer Double Long Short Single String Type System.Byte System.Char System.Int32 System.Double System.Int64 System.Int16 System.Single System.String

Date
Boolean Object

System.Date
System.Boolean System.Object

Using Operators

Operators are tools for some predefined operations The operators that are used in flowcharts are: Arithmetic operators Relational operators Logical operators

Procedures in VB.NET

It is a series of statements that are executed when called. it allow us to handle code in a simple and organized fashion. In VB.NET we can create two different type of procedures. 1. Sub Procedure 2. Function Procedure

Sub Procedures

They are methods which do not return a value. Each time when the Sub procedure is called the statements within it are executed until the matching End Sub is encountered. Syntax
[AccessSpecifier] Sub <procedure_name>([parameters]) .. .. End Sub

Function Procedures

Function is a method which returns a value. Functions are used to evaluate data, make calculations or to transform data. Syntax
[AccessSpecifier] Function <procedure_name>([parameters]) as <DataType> .. Return <value> End Function

Conditional Statements
If....Else statement If conditional expression is one of the most useful control structures which allows us to execute a expression if a condition is true and execute a different expression if it is False.
Syntax
If condition Then [statements] Else If condition Then [statements] Else [statements] End If

Conditional Statements (Contd..)


Select....Case Statement The Select Case statement executes one of several groups of statements depending on the value of an expression. If your code has the capability to handle different values of a particular variable then you can use a Select Case statement. You use Select Case to test an expression, determine which of the given cases it matches and execute the code in that matched case. Syntax
Select Case testexpression [Case expressionlist-n [statements-n]] . . . [Case Else elsestatements] End Select

Loops
While loop While loop keeps executing until the condition against which it tests remain true.
Syntax
While condition [statements] End While

Loops (Contd..)
Do Loop The Do loop can be used to execute a fixed block of statements indefinite number of times. The Do loop keeps executing it's statements while or until the condition is true. Two keywords, while and until can be used with the do loop. The Do loop also supports an Exit Do statement which makes the loop to exit at any moment. Syntax
Do [statements] [Exit Do] [statements] Loop [{while | Until} condition]

Loops (Contd..)
For Loop The For loop is the most popular loop. For loops enable us to execute a series of expressions multiple numbers of times. The For loop in VB .NET needs a loop index which counts the number of loop iterations as the loop executes.

Syntax
For index=start to end [Step step] [statements] [Exit For] [statements] Next

Call ByValue and Call ByReference

In VB.NET there are two ways in which we can call a function or procedure, viz, by Value or by Reference. The default being Call by Value. Passing a parameter by Reference means that if changes are made to the value of a variable passed, these changes are reflected back in the calling routine. (ByRef) Passing a parameter by Value means that if changes are made to the value of a variable passed, these changes are not reflected back in the calling routine. (ByVal)

Array
Are collections of values of the same data type. Contain elements that can be accessed using a single name and an index number representing the position of the element Syntax Dim arr_name(number-of-elements) as DataType Can be resized using the Redim statement Syntax ReDim arr_name(new-number-of-element)

Parameter arrays
Parameter arrays allow a variable number of arguments to be passed into a function member. The definition of the parameter has to include the params modifier, but the use of the parameter has no such keyword. A parameter array has to come at the end of the list of parameters, and must be a single-dimensional array. When using the function member, any number of parameters (including none) may appear in the invocation .
Syntax
Sub MinValue(ParamArray ByVal args() As Integer) As Integer .. End Sub

Enumeration
Enumeration is a related set of constants. They are used when working with many constants of the same type. It's declared with the Enum keyword. Example:

Enum Seasons Summer = 1 Winter = 2 Spring = 3 Autumn = 4 End Enum

You might also like