0% found this document useful (0 votes)
40 views4 pages

Declaration Statements: SR - No Statements and Description Example

The document discusses statement types in Visual Basic programs. There are two main categories of statements: declaration statements and executable statements. Declaration statements name and define variables, constants, procedures, etc. and include statements like Dim, Const, and Class. Executable statements perform actions like calling procedures, branching code, and assigning values; examples are If/Then statements and assignment statements. The document provides examples of different declaration statements like Dim, Const, and Enum and their usage.

Uploaded by

Somesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Declaration Statements: SR - No Statements and Description Example

The document discusses statement types in Visual Basic programs. There are two main categories of statements: declaration statements and executable statements. Declaration statements name and define variables, constants, procedures, etc. and include statements like Dim, Const, and Class. Executable statements perform actions like calling procedures, branching code, and assigning values; examples are If/Then statements and assignment statements. The document provides examples of different declaration statements like Dim, Const, and Enum and their usage.

Uploaded by

Somesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

statement is a complete instruction in Visual Basic programs. It may contain


keywords, operators, variables, literal values, constants and expressions.
Statements could be categorized as −
 Declaration statements − these are the statements where you name a
variable, constant, or procedure, and can also specify a data type.
 Executable statements − these are the statements, which initiate actions.
These statements can call a method or function, loop or branch through
blocks of code or assign values or expression to a variable or constant. In the
last case, it is called an Assignment statement.

Declaration Statements
The declaration statements are used to name and define procedures, variables,
properties, arrays, and constants. When you declare a programming element, you
can also define its data type, access level, and scope.
The programming elements you may declare include variables, constants,
enumerations, classes, structures, modules, interfaces, procedures, procedure
parameters, function returns, external procedure references, operators, properties,
events, and delegates.
Following are the declaration statements in VB.Net −

Sr.No Statements and Example


Description

1 Dim number As Integer


Dim Statement
Dim quantity As Integer = 100
Declares and allocates Dim message As String = "Hello!"
storage space for one or
more variables.

2 Const maximum As Long = 1000


Const Statement
Const naturalLogBase As Object
Declares and defines one = CDec(2.7182818284)
or more constants.

3 Enum CoffeeMugSize
Enum Statement
Jumbo
Declares an enumeration ExtraLarge
and defines the values of Large
its members. Medium
Small
End Enum

4 Class Box
Class Statement
Public length As Double
Public breadth As Double
Declares the name of a Public height As Double
class and introduces the End Class
definition of the variables,
properties, events, and
procedures that the class
comprises.

5 Structure Box
Structure Statement
Public length As Double
Declares the name of a Public breadth As Double
structure and introduces Public height As Double
the definition of the End Structure
variables, properties,
events, and procedures
that the structure
comprises.

6 Public Module myModule


Module Statement
Sub Main()
Declares the name of a Dim user As String =
module and introduces InputBox("What is your name?")
the definition of the MsgBox("User name is" & user)
variables, properties, End Sub
events, and procedures End Module
that the module
comprises.

7 Public Interface MyInterface


Interface Statement
Sub doSomething()
Declares the name of an End Interface
interface and introduces
the definitions of the
members that the
interface comprises.

8 Function myFunction
Function Statement
(ByVal n As Integer) As Double
Declares the name, Return 5.87 * n
parameters, and code End Function
that define a Function
procedure.

9 Sub mySub(ByVal s As String)


Sub Statement
Return
Declares the name, End Sub
parameters, and code
that define a Sub
procedure.

10 Declare Function getUserName


Declare Statement
Lib "advapi32.dll"
Declares a reference to a Alias "GetUserNameA"
procedure implemented (
in an external file. ByVal lpBuffer As String,
ByRef nSize As Integer) As Integer

11 Public Shared Operator +


Operator Statement
(ByVal x As obj, ByVal y As obj) As obj
Declares the operator Dim r As New obj
symbol, operands, and ' implemention code for r = x + y
code that define an Return r
operator procedure on a End Operator
class or structure.

12 ReadOnly Property quote() As String


Property Statement
Get
Declares the name of a Return quoteString
property, and the End Get
property procedures used End Property
to store and retrieve the
value of the property.

13 Public Event Finished()


Event Statement
Declares a user-defined
event.

14 Delegate Function MathOperator(


Delegate Statement
ByVal x As Double,
Used to declare a ByVal y As Double
delegate. ) As Double

Executable Statements
An executable statement performs an action. Statements calling a procedure,
branching to another place in the code, looping through several statements, or
evaluating an expression are executable statements. An assignment statement is a
special case of an executable statement.
Example
The following example demonstrates a decision making statement −
Live Demo
Module decisions
Sub Main()
'local variable definition '
Dim a As Integer = 10

' check the boolean condition using if statement '


If (a < 20) Then
' if condition is true then print the following '
Console.WriteLine("a is less than 20")
End If
Console.WriteLine("value of a is : {0}", a)
Console.ReadLine()
End Sub
End Module

When the above code is compiled and executed, it produces the following result −
a is less than 20;
value of a is : 10

You might also like