VB.NET Q1.Introduction of visual basic? Ans-:visual basic is a third generation event driven programming language & integrated development environment from Microsoft for its released in 1991.Microsoft intended visual basic to relating easy to learn and use. Elements of Visual Basic-:The two basic elements of visual basic are GUI and the code associated with the application that makes it respond to event occurred as a result of a user action. Elements-: IDE is a term commonly used in the programming world to described the interface and environment that we use to create our applications. it is called integrated because we can access virtually all of the development tools that we need from one screen called on interface. The IDE is also commonly referred to as the design environment or the program. The visual basic IDE is made up of a number of components-: IDE-: Integrated Development Environment 1. Menu bar 2. Tool bar 3. Project explorer 4. Properties window 5. from layout window 6. Toolbar 7. from designer 8. Object browser Introduction of VB.Net-:VB.Net is a simple modern, object oriented computer programming language developed by Microsoft to combine the power of.net framework and the common language runtime with the productivity benefits that are hallmark of visual basic. Vb.net has complete support for object oriented concepts. Everything in vb.net is an object including all of the primitive types (short, integer, long, string, Boolean
50
Embed
VB - ticstanda.com · VB.NET Q1.Introduction of visual basic? Ans-: visual basic is a third generation event driven programming language & integrated development environment from
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
VB.NET
Q1.Introduction of visual basic?
Ans-:visual basic is a third generation event driven programming language &
integrated development environment from Microsoft for its released in
1991.Microsoft intended visual basic to relating easy to learn and use.
Elements of Visual Basic-:The two basic elements of visual basic are GUI and the
code associated with the application that makes it respond to event occurred as a
result of a user action.
Elements-: IDE is a term commonly used in the programming world to described
the interface and environment that we use to create our applications. it is called
integrated because we can access virtually all of the development tools that we
need from one screen called on interface. The IDE is also commonly referred to as
the design environment or the program.
The visual basic IDE is made up of a number of components-:
IDE-: Integrated Development Environment
1. Menu bar
2. Tool bar
3. Project explorer
4. Properties window
5. from layout window
6. Toolbar
7. from designer
8. Object browser
Introduction of VB.Net-:VB.Net is a simple modern, object oriented computer
programming language developed by Microsoft to combine the power of.net
framework and the common language runtime with the productivity benefits that
are hallmark of visual basic.
Vb.net has complete support for object oriented concepts. Everything in vb.net is
an object including all of the primitive types (short, integer, long, string, Boolean
etc) and user defined types, events and event assembler. All objects inherit from
the basic class objects.
V . et fra e ork is i ple e t y Mi rosoft’s net framework.therfore it has full
access to all the libraries in the .net framework. It is also possible to run vb.net
program on mono the open source alternative to .net not only under window but
even Linux or Mac OSx.
The following reasons make vb.net a widely used professional language-:
1. Modern general purpose
2. Object oriented
3. Component oriented
4. easy to learn
5. Structured programming
6. It produces efficient programming
7. It can be complied on a variety of computer platform.
8. Part of net. Framework
The .Net framework The .net framework is a revolutionary platform that helps you to write the
following types of applications.
1) Window applications
2) Web applications
3) Web services
The .net framework applications are multiplatform applications. The
framework has been designed in such a way that it can be used from any of
the following languages visual basic, c#, c++, java script and Cobol etc.
The .net framework consists of an various library of codes used by the client
language like vb.net.these language use object oriented methodology.
There is some following same of the components of the .net framework.
common language runtime(CLR)
the .net framework class library
Common language specification.
Common type system
Metadata and assembler
Windows forms
Asp.net and asp.net Ajax
Ado.net
Window workflow foundation(wf)
Window presentation foundation(wcf)
Window communication foundation(wcf)
Linq
Review Q1what are the two major features of visual basic?
Ans-:1) GUI Interface-:vb is a graphical user interface language. This means that a
vb program will always show something on the screen that the user can interact e
with (usually via mouse and keyboard) to get a job done.
2) Modularization-: it is considered good programming practice to modular your
programs. Instead of thinking of a computer program as a single large collections
of code the good programming writes code so that you never need to lock at
more code than fits on the screen(or page)at one time.
3)Object orientation-: object oriented programming is a concept where the
programming thinks of the program in objects that interact with each others. In
oop all the code associated with that object is in one place.
Q2.Write a short note on CLR?
Ans-: CLR stands for common language runtime. It is a managed execution
environment that is a part of Mi rosoft’s et fra e ork. lr a ages the execution of programs written in different supported language clr transforms
source code into a form of bytes code from known common intermediate
language(cil) at runtime clr handles the execution of the cil code.
Q3. What is managed code?
Ans-:managed code is a term coined by Microsoft to identify computers
programming code that requires and will execute only under the management of
a common language runtime virtual machine typically the net framework mono
managed code usually refer to program written in .net language such as c# or
visual basic.net while in managed code refer to program written in c,c++,visual
basic and other language that do not need a runtime to execute.
Q4.Why is JIT needed?
Ans-:jit stands for just in time. Just in time compilation the process of converting
cil to machine code translation. In .net word it is done by jit complier code in
dynamic memory. It means that you will compile yours application twice that you
will compile your applications twice if you run it two times simultaneously.
Q5.What do you mean by MSIL?
Ans-: MSIL stand for Microsoft intermediate language. We can call it as
intermediate language (il) or common intermediate language.
During the compile time the complier convert the source code into
Microsoft intermediate language (msil).Microsoft intermediate language is a cpu
independent set of instructions that can be efficiently converted to the negative
code. During the runtime the common language runtime the common language
ru ti e lr ’s just i time (jit) compiler converts the Microsoft intermediate
language (msil) code into native code to the operating system.
Q6.Explain the concept of assemblies?
Ans-: Microsoft .net assembly is a logical unit of a code that contain code which
the commonly language runtime (clr) executes. It is the smallest unit of
development of a .net applications and it can be .dll or an exe. Assembly is really
Collections of types a d resour e i for atio ’s that are uild to ork together and from a logical unit of functionality. Assemblies are the building block of .net
framework applications. During the compile time metadata is created with
Microsoft intermediate language (msil) and stored in a file called assembly
manifest. Both metadata and Microsoft intermediate language together wrapped
in a portable executable (pe) file.
Q.7 What is CTS?
Ans-: Common type systems (cts) describe a set of types that can be used in
different .net language in common. That is the common type systems (cts) ensure
that objects written in different .net languages can interact with each other. For
communicating between programs written in any .net complaints language the
types have to be compatibles on the basic level.
These types can be value types or reference type. The values types are passed by
values are stored in the stack. The reference type are passed by reference and
stored in the heap. Common type systems (cts) provide base set of data types
which is responsible for cross language integrated. The common language
runtime(clr) can load and execute the source code written in any .net language
only if the types Is described in the common type system(cts).most of the
members defined by types in the .net framework class library (fcl) are common
language specification(cls) complaint types.
Q.Differentiate between values and reference types?
Ans-: value types-: the value types are passed by values and stored in the stack.
When you created a value types a single space in memory is allocated to store the
value and that variable directly holds a value. If you assign it to another variable
the value is copied directly and both variables work independently .predefined
datatypes,structure,enum are also value types and work in the same way values
a d stored i sta k e ory e ause of this gar arge olle tor a ’t a ess the stack.
Reference types-: the reference types are passed by reference and stored in the
heap. Reference type are used by a reference which holds a reference (address)
to the object but not the object itself.beacuse reference types represent the
address of the variable rather than the data itself.beacause reference types
represent the address of the variable rather than the data itself assigning a
refere e aria le to a other does ’t opy the data. Refere e type aria le are stored in a different area of memory called the heap. This means that when a
reference type’s variable is no longer used, it can be marked for garbage
collection. Example of reference types are classes, objects, array, and indexes
interfaces etc.
Q Explain the different kinds of literals?
Ans-: a literal is a textual representation of a particular value of a type. Literal
types include Boolean, integer, floating point string, character and data.
UNIT-2 Q Define a variable?
Ans-: variable are used to store data. a variable as a name to which we refer and
the data type the type of data the variable holds.a variable is nothing but a name
given to storage area that our programs can manipulate. Each variable in vb.net
has a spe ifi type hi h deter i es the size a d layout of the aria le’s e ory the rangeof values that can be stored with in that memory and set of operations
that can be memory and set of operations that can be applied to the variable.we
have already discussed various data types.the basic value type provided in vb.net
can be categorized as-:
Integer,float,decimal,Boolean,data types
Q Declaring of variable?
Ans-: the dim statement is used for variable declaration and storage allocation for
one or more variables. The dim statement is used at module class structure
procedure or block level variables are declared with the dim keyword.dim stands
for dimensions.
Some valid variable declarations along with their definitions are show here-:
Dim studentid as integer
Dim studentsname as string
Dim salary as double
Dim count1,count2 as integer
Dim status as Boolean
Dim exit button as new style system win down forms button
Dim lasttime,next time as date.
Variable intilization in vb.net-:
Variable are initized (assigned a value) with an equal sign followed by a constant
expression.the general form of initialization is-:
Variable _name=value;
For example-:
Dim As Integer
A=15;
You can initialize a variable at the time of declaration as follows-:
Dim StudentID As Integer=100;
Di “tude tNa e As “tri g= Bill “ ith
Example-:
Modules Variable N data Types
Sub Main()
Dim a As Integer=10
Dim b As Integer=5
Dim c As Integer
C=a+b;
Co sole.WriteLi e su of a& = &
End Sub
End Module
Q Scope of variable?
Ans-:the scope of an element in code that can refer to it without qualifying its
a e stated other ay a ele e t’s scope is its accessibility in code.scope is
normally used when writing large programs as large programs divide code into
different classes,modules etcthe different kinds of scope avialible in vb.net are as
follows-:
1)Block Scope-:the element declared is available only within the code block in
which it is declared.
2)Procedure Scope-:The element declared is available only with in the procedure
in which it is declared.
3)Module Level-:the element is available to all code within the module and class
in which it is declared.
4) Namespace Scope-: the element declared is available to all code in the
namespaces.
QVB.NET operators?
ANS-: there are various operators in vb.net.
1) Arithmetic operator
2) Relational operator
3) Logical operator
4) Assignment operator
1) Arithmetic operator-: arithmetic operator is used to mathematical calculations
such as +,-,*,/,% etc.assume variable a hold 2 and b hold 7 then
Operator Description Example
+ Adds two operands A + B will give 9
- Subtracts second operand from the first A - B will give -5
* Multiplies both operands A * B will give 14
/ Divides one operand by another and
returns a floating point result B / A will give 3.5
\ Divides one operand by another and
returns an integer result B \ A will give 3
MOD Modulus Operator and remainder of after
an integer division B MOD A will give 1
Module Module1
Sub Main()
Dim a As Integer=10
Dim b As Integer=20
Console.WriteLine (a+b)
Console.WriteLine (a-b)
Console.WriteLine (a*b)
Console.WriteLine (a%b)
Console.WriteLine (a/b)
End Sub
End Module
2) Relational operator-: this operator is used to compare two values. It is also
called as compression operator. Assume variable a hold 10 and variable b hold 20
then-:
Operator Description Example
=
Checks if the values of two operands are
equal or not; if yes, then condition
becomes true.
(A = B) is not true.
<>
Checks if the values of two operands are
equal or not; if values are not equal, then
condition becomes true.
(A <> B) is true.
>
Checks if the value of left operand is
greater than the value of right operand; if
yes, then condition becomes true.
(A > B) is not true.
< Checks if the value of left operand is less
than the value of right operand; if yes, then (A < B) is true.
condition becomes true.
>=
Checks if the value of left operand is
greater than or equal to the value of right
operand; if yes, then condition becomes
true.
(A >= B) is not true.
<=
Checks if the value of left operand is less
than or equal to the value of right operand;
if yes, then condition becomes true.
(A <= B) is true.
Module Module1
Sub Main()
Dim a As Integer=10
Dim b As Integer=5
Console.WriteLine (a>b)
Console.WriteLine (a<b)
Console.WriteLine (a=b)
Console.WriteLine (a>=b)
Console.WriteLine (a<=b)
Console.WriteLine (a!=b)
End Sub
End Module
4)Logical operator-:the logical operator supporting by vb.net assume variable a
hold Boolean value true and variable 3 holds Boolean value false then-:
Operator Description Example
And
It is the logical as well as bitwise AND
operator. If both the operands are true,
then condition becomes true. This operator
does not perform short-circuiting, i.e., it
evaluates both the expressions.
(A And B) is False.
Or
It is the logical as well as bitwise OR
operator. If any of the two operands is true,
then condition becomes true. This operator
(A Or B) is True.
does not perform short-circuiting, i.e., it
evaluates both the expressions.
Not
It is the logical as well as bitwise NOT
operator. Use to reverses the logical state
of its operand. If a condition is true, then
Logical NOT operator will make false.
Not(A And B) is True.
AND Module Module1
Sub Main()
Dim age As Integer=18
Dim height As Integer=155
If((age>18)and(height=155))Then
Console.WriteLine ( you are eligi le )
Else
Console.WriteLine ( you are ot eligi le )
EndIf
End Sub
End Module
OR Module Module1
Sub Main()
Dim age As Integer=18
Dim height As Integer=155
If((age>18)OR(height=155))Then
Co sole.WriteLi e you are eligi le
Else
Co sole.WriteLi e you are ot eligi le
EndIf
End Sub
End Module
NOT Module Module1
Sub Main()
Dim age As Integer=18
If(Not age=18)Then
Co sole.WriteLi e you are eligi le
Else
Co sole.WriteLi e you are ot eligi le
EndIf
End Sub
End Module
4) Assignment operator-:these are following assignement operators supported by
vb.net-:
Operator Description Example
=
Simple assignment operator, Assigns values
from right side operands to left side
operand
C = A + B will assign value
of A + B into C
+=
Add AND assignment operator, It adds right
operand to the left operand and assigns the
result to left operand
C += A is equivalent to C =
C + A
-=
Subtract AND assignment operator, It
subtracts right operand from the left
operand and assigns the result to left
operand
C -= A is equivalent to C = C
- A
*=
Multiply AND assignment operator, It
multiplies right operand with the left
operand and assigns the result to left
operand
C *= A is equivalent to C =
C * A
/=
Divide AND assignment operator, It divides
left operand with the right operand and
assigns the result to left operand (floating
point division)
C /= A is equivalent to C = C
/ A
QData types in vb.net?
Ans-:A data type is a class that is primarily used just to hold the data.vb.net has
huge no of data types-: store any kind of data more over all the data types used
vb.net are the objects.Vb.net has a number of predefined data types-:
Data Type Storage
Allocation Value Range
Boolean
Depends on
implementing
platform
True or False
Byte 1 byte 0 through 255 (unsigned)
Char 2 bytes 0 through 65535 (unsigned)
Date 8 bytes 0:00:00 (midnight) on January 1, 0001 through
11:59:59 PM on December 31, 9999
Decimal 16 bytes
0 through +/-
79,228,162,514,264,337,593,543,950,335 (+/-
7.9...E+28) with no decimal point; 0 through +/-
7.9228162514264337593543950335 with 28 places
to the right of the decimal
Double 8 bytes
-1.79769313486231570E+308 through -
4.94065645841246544E-324, for negative values
4.94065645841246544E-324 through
1.79769313486231570E+308, for positive values
Integer 4 bytes -2,147,483,648 through 2,147,483,647 (signed)
Long 8 bytes -9,223,372,036,854,775,808 through
9,223,372,036,854,775,807(signed)
Object
4 bytes on 32-
bit platform
8 bytes on 64-
bit platform
Any type can be stored in a variable of type Object
SByte 1 byte -128 through 127 (signed)
Short 2 bytes -32,768 through 32,767 (signed)
Single 4 bytes
-3.4028235E+38 through -1.401298E-45 for negative
values;
1.401298E-45 through 3.4028235E+38 for positive
values
String
Depends on
implementing
platform
0 to appro0 to approximately 2 billion Unicode
characters
UNIT-3 DECISION MAKING AND LOOPING
Decision marking statement-: decision making structures require that the
programmer specify one or more conditions to be evaluated or tested by the
program along with a statement or statement to be executed. If the condition is
determined to be true and optionally other statement to be executed if the
condition is determined to be false. Decision making statement is two types.
1) Iteration/looping statement
2) Conditional statement
Looping statement in vb.net-: there may be a situation when you need to execute
a block of code several number of times. In general, statements are executed
sequentially .a loop statement allows use to execute a statement or group of
statement multiple times and followings is the general form of a loop statement
in most of programming languages.
There are many loops in vb.net.
1) Do loop-: it repeats the enclosed block of statement while a Boolean condition
become true .it could be terminated at any time with the exit do statement.
The syntax of this loop is-:
Do
Statement
Incre/decrement
Loop While(condition)
End Loop
Example-:
Module Module1
Sub Main()
Dim a As Integer=1
Do
Co sole.WriteLi e a
A=a+1
Loop While(a<=10)
End Sub
End Module
2)For Next Loop-:it repeats a group of statement a specified number of times and
a loop index counts the number of loop iterations as the loop executes.
The syntax for this loop as-:
For Counter [As Data Types] =Start to end
[Statement]
[Condition For]
[Statement]
[Exit For]
[Statement]
Next [Counter]
Example-:
Module Module1
Sub Main ()
Dim a As Integer
For a=1 To 20
Console.WriteLine (a)
Next
End Sub
End Module
3) While End While loop-: it execute a series of statement as long as a given
condition is true.
The syntax for this loop as-:
While Condition
[Statements]
[Condition While]
[Statements]
[Exit While]
[Statement]
End While
Example-:
Module Module1
Sub Main ()
Dim a As Integer=1
While (a<=20)
Console.WriteLine (a)
A=a+1
End Sub
End Module
4) For each next loop-: it repeats a group of statements for each element in a
collection. This loop is used for accessing and manipulating all elements in an
array or a vb.net collection.
The syntax for this loop as-:
For Each element[As data type] In group
[Statements]
[Condition For]
[Statements]
[Exit For]
[Statement]
Next[element]
Example-:
Module Module1
Sub Main ()
Dim a As Integer
For a=1 To 20
Console.WriteLine (a)
Next
End Sub
End Module
DECISION MAKING Statement
1)IF then Statement-: it is the simplest form of control statement. If the
condition is true then if block of code will be executed otherwise this are
specified.
Syntax-:
IF Condition Then
Statements
End If
Example-:
Module Module1
Sub Main()
Dim age As Integer=100
Dim height As Integer=5
If((a>b)Then
Co sole.WriteLi e a is greater
EndIf
End Sub
End Module
2)IF THEN ELSE STATEMENT-:an if statement can be followed by an optional else
statement which executes when the Boolean is false.
Syntax-:
IF Condition Then
Statements
Else
Statement
End If
Example-:
Module Module1
Sub Main ()
Dim age As Integer=100
Dim height As Integer=5
If ((a>b) Then
Co sole.WriteLi e a is greater
Else
Co sole.WriteLi e is greater
End If
End Sub
End Module
3)IF ELSE IF STATEMENT-:an if statement can be followed by an optional else. If
else statement which is very useful to test various conditions using single if else if
statement.
Syntax-:
IF(Boolean expression1)Then
Statements
Else If(Boolean expression2)Then
Statement
Else
Statement
End If
Example-:
Module Module1
Sub Main()
Dim day As Integer=5
If(day=1)Then
Console.WriteLine ( Sunday
Else If(day=2)Then
Co sole.WriteLi e Mo day
Else If(day=3)Then
Co sole.WriteLi e Tuesday
Else
Console.WriteLine ( I alid day
End If
End Sub
End Module
4) NESTED IF STATEMENT-: it is always legal in vb.net to nest if then else
statement. Which means you can use one if or else if statement
Inside another if else if statement.
Syntax-:
IF(Boolean expression1)Then
Statements 1
Else If(Boolean expression2)Then
Statement 2
End If
End If
Example-:
Module Module1
Sub Main()
Dim a As Integer=1000
Dim a As Integer=2000
If(daa=100)Then
If(b=200)Then
Co sole.WriteLi e a is 100 and b is 200
End If
End If
End Sub
End Module
5)SELECT CASE STATEMENT-: a select case statement allows a variable to be
tested for equality against a list of values. Each value is called a case and the
variable being switched on is checked for each select case.
Syntax-:
Select [Case] expression
[Case expression list
[Statements 1]]
[Case Else
[else Statement 2]]
End select
Example-:
Module Module1
Sub Main()
Dim day As Integer=5
Select Case day
Case 1
Co sole.WriteLi e Sunday
Case 2
Co sole.WriteLi e Mo day
Case 3
Co sole.WriteLi e Tuesday
Case 4
Co sole.WriteLi e Wed esday
Case ELSE
Co sole.WriteLi e I alid Day
End Select
End Sub
End Module
UNIT-4
Array ARRAY-:an array stores a fixed size sequential collection of elements of the same
types.an array is used to store a collection of data but it is often more useful to
think of an array as a collection of variables of the same type.
All array consist of contiguous memory locations.the lowest address corresponds
to the first element and the highest address to the last element.
Declaration of an array-: to declare an array in vb.net you use the Dim
statement.
For example-: Dim int Data (30) -an array of 31 elements
Dim Str(20) As string -an array of 21 strings
Initialization of array in vb.net-: you can also initialize the array elements which
declaring while declaring the array.
for example-: Dim int Data() As Integer={12,16,20,24,28,32}
Di a es As stri g={ karthik , sa dly }
The elements in an array can be stored and accessed by using the index of the