0% found this document useful (0 votes)
20 views70 pages

PMCS Unit 4

VB.NET is an object-oriented programming language that combines the power of .NET Framework. Everything in VB.NET is an object, including primitive data types. VB.NET code is written in a graphical environment using forms and controls. It produces efficient programs that can be compiled for multiple platforms. Key features include boolean conditions, automatic garbage collection, and easy multithreading. Variables and constants are declared with data types and used to store and manipulate data. Common operators allow for arithmetic, comparison, and logical operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views70 pages

PMCS Unit 4

VB.NET is an object-oriented programming language that combines the power of .NET Framework. Everything in VB.NET is an object, including primitive data types. VB.NET code is written in a graphical environment using forms and controls. It produces efficient programs that can be compiled for multiple platforms. Key features include boolean conditions, automatic garbage collection, and easy multithreading. Variables and constants are declared with data types and used to store and manipulate data. Common operators allow for arithmetic, comparison, and logical operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 70

PMCS - DBMS UNIT 4

VISUAL PROGRAMMING
VB.NET
• VB.Net is a simple, modern, object-oriented computer programming language developed by Microsoft to combine the power of .NET

Framework

• Everything in VB.NET is an object

• all of the primitive types (Short, Integer, Long, String, Boolean, etc.)

• VB.Net programming is very much based on BASIC and Visual Basic programming languages

VB.Net a widely used professional language −

• Modern, general purpose.

• Object oriented.

• Component oriented.

• Easy to learn.

• Structured language.

• It produces efficient programs.

• It can be compiled on a variety of computer platforms.

• Part of .Net Framework.


• What is Visual Basic?
• Visual basic is an event driven programming language.
• Visual basic is used to create applications fast, as well as, very easily.
• Visual basic provides us with a complete set of tools to simplify rapid application development
(rad).
• Write the naming reason of Visual Basic.

• The word "visual" refers to create the graphical user interface (gui), rather than writing numerous
lines of code to describe the appearance and location of the interface elements. we simply drag and
drop the pre-built objects into place on the screen.
• The word "basic" comes from the original "basic" language. it is now contains several hundred
statements, functions and commands.
• IDE, Forms & Controls

• What is IDE?

• The expansion for IDE is Integrated Development Environment. The Visual Basic integrated development

environment means assortment of menus, tool bars, windows, tool box and other tools that are used to create Visual

Basic application easily.

• Form Window:

• The controls have to be placed on the form. The forms are the basic building blocks of a Visual Basic application. It

is the window or the screen with which users interacts when they run the application. A form is actually a control and

has its own properties, events and methods with which you can control its appearance and behavior.

Properties can be changed in two ways.

• At Design Time

• At Run Time.
Features of vb.net
VB.Net has numerous strong programming features that make it endearing to multitude of programmers worldwide.

Let us mention some of these features −

• Boolean Conditions

• Automatic Garbage Collection

• Standard Library

• Assembly Versioning

• Properties and Events

• Delegates and Events Management

• Easy-to-use Generics

• Indexers

• Conditional Compilation

• Simple Multithreading
VARIABLES
• Variable is a named memory location used to hold a value that can be changed during the script
execution.

Following are the basic rules for naming a variable.

• You must use a letter as the first character. Eg.name

• You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
eg. First name, first.name,firstname!

• Name can't exceed 255 characters in length.

• You cannot use Visual Basic reserved keywords as variable name. eg. Private, public, for
SYNTAX
• Dim <variablename> As <variabletype>

• Ex. Dim num As Integer


Type Range of Values

Data types Byte

Integer
0 to 255

-32,768 to 32,767
Type Range of Values
String (fixed length) 1 to 65,400
Long -2,147,483,648 to 2,147,483,648
characters

• Data types Single -3.402823E+38 to -1.401298E-45


for negative values
String (variable 0 to 2 billion
1.401298E-45 to 3.402823E+38 length) characters
Data types used for positive values.
Date January 1, 100 to
to store the type December 31, 9999
of variable. Double -1.79769313486232e+308
4.94065645841247E-324
to -
for
• Numeric negative values
4.94065645841247E-324 to Boolean True or False
• Non numeric 1.79769313486232e+308
positive values.
for

Object Any embedded


object
Currency -922,337,203,685,477.5808 to
922,337,203,685,477.5807
Variant (numeric) Any value as large
Decimal +/- as double
79,228,162,514,264,337,593,543,
950,335 if no decimal is use
+/- Variant (text) Same as variable-
7.9228162514264337593543950
335 (28 decimal places).
length string
constant
• Constant is a named memory location used to hold a value that
CANNOT be changed during the script execution.
Following are the rules for naming a constant.
• You must use a letter as the first character.
• You can't use a space, period (.), exclamation mark (!), or the
characters @, &, $, # in the name.
• Name can't exceed 255 characters in length.
• You cannot use Visual Basic reserved keywords as variable name.
• declared the same way the variables are declared.
Syntax

• Const <constname> As <constanttype>=<constant value>

• Ex.
Const pi As Integer = 3.14
operators
• An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

Types:

• Arithmetic Operators

• Comparison Operators

• Logical/Bitwise Operators

• Concatenation operators

• Assignment Operators

• Miscellaneous Operators
Arithmetic Operators
• Assume variable A holds
• 5 and variable B holds 10, then
Operator Description Example
The standard arithmetic + Adds the two operands A + B will give 15
operators are
- Subtracts the second A - B will give -5
• Addition: + (plus sign) operand from the first
• Subtraction: − (minus sign) * Multiplies both the operands A * B will give 50

• Multiplication: * (asterisk) / Divides the numerator by the B / A will give 2


denominator
• Division: / (slash)
% Modulus operator and the B % A will give 0
• Exponentiation: ^ (caret, or remainder after an integer
division
upward-pointing arrow)
^ Exponentiation operator B ^ A will give 100000
Comparison Operators

• assume variable A holds 10 and variable B holds 20, then


Operator Description Example
• Equal: = = Checks if the value of the two operands are (A = B) is
equal or not. If yes, then the condition is true. False.
• Not equal: <> <> Checks if the value of the two operands are (A <> B) is
equal or not. If the values are not equal, then True.
• Less than: < the condition is true.

• Less than or equal to: <= > Checks if the value of the left operand is
greater than the value of the right operand. If
(A > B) is
False.
yes, then the condition is true.
• Greater than: > < Checks if the value of the left operand is less (A < B) is
than the value of the right operand. If yes, then True.
• Greater than or equal to: >= the condition is true.
>= Checks if the value of the left operand is (A >= B) is
greater than or equal to the value of the right False.
operand. If yes, then the condition is true.

<= Checks if the value of the left operand is less (A <= B) is


than or equal to the value of the right operand. True.
If yes, then the condition is true.
Logical Operators

• Assume variable A holds 10 and variable B holds 0, then −


Operator Description Example
AND Called Logical AND operator. If both the conditions are True, then the Expression is a<>0 AND b<>0 is False.
true.

OR Called Logical OR Operator. If any of the two conditions are True, then the condition is a<>0 OR b<>0 is true.
true.

NOT Called Logical NOT Operator. Used to reverse the logical state of its operand. If a NOT(a<>0 OR b<>0) is false.
condition is true, then Logical NOT operator will make false.

XOR Called Logical Exclusion. It is the combination of NOT and OR Operator. If one, and (a<>0 XOR b<>0) is true.
only one, of the expressions evaluates to be True, the result is True.
Concatenation Operators
• Concatenation Operators can be used for both numbers and strings. The output depends on the context, if the variables hold numeric value
or string value.
• Assume variable A holds 5 and variable B holds 10 then −

Operator Description Example


+ Adds two Values as A + B will give 15
Variable. Values are
Numeric
& Concatenates two A & B will give 510
Values

Assume variable A = "Microsoft" and variable B = "VBScript", then −

Operator Description Example


+ Concatenates two A + B will give
Values MicrosoftVBScript
& Concatenates two A & B will give
Values MicrosoftVBScript
Assignment operators
Operator Description Example
= Simple assignment operator, Assigns values from right side C = A + B will assign value of A + B into C
operands to left side operand
+= Add AND assignment operator, It adds right operand to the C += A is equivalent to C = C + A
left operand and assigns the result to left operand
-= Subtract AND assignment operator, It subtracts right operand C -= A is equivalent to C = C - A
from the left operand and assigns the result to left operand
*= Multiply AND assignment operator, It multiplies right operand C *= A is equivalent to C = C * A
with the left operand and assigns the result to left operand
/= Divide AND assignment operator, It divides left operand with C /= A is equivalent to C = C / A
the right operand and assigns the result to left operand
(floating point division)
\= Divide AND assignment operator, It divides left operand with C \= A is equivalent to C = C \A
the right operand and assigns the result to left operand (Integer
division)
^= Exponentiation and assignment operator. It raises the left C^=A is equivalent to C = C ^ A
operand to the power of the right operand and assigns the
result to left operand
<<= Left shift AND assignment operator C <<= 2 is same as C = C << 2
>>= Right shift AND assignment operator C >>= 2 is same as C = C >> 2
&= Concatenates a String expression to a String variable or Str1 &= Str2 is same as
ARRAYS
• An array is a data structure used to store elements of the same data type.
• The elements are ordered sequentially with the first element being at index 0 and
the last element at index n-1, where n is the total number of elements in the array.
• Each array variable is known as array element.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
Declare & Initialize array
Static Declare:
• Dim num() As Integer - Dynamic array
• Dim name(10) As String – fixed size array
• Dim name(0 to 2) As String
Initialize
Dim num() As Integer={10,20,30}
Dim name() As String={“john”, “don”, “khan”}
Dynamic array
• Dynamic arrays are arrays that can be dimensioned and re-
dimensioned as par the need of the program.
Dynamic array declare:
ReDim [Preserve] arrayname(subsricpts)
• Where,
• The Preserve keyword helps to preserve the data in an existing array,
when you resize it.
• arrayname is the name of the array to re-dimension.
• subscripts specifies the new dimension.
• Explanation of Code:
• Creating a module named Module1.
• Creating the main sub-procedure.
• Creating an array named nums to hold integer values.
• Specifying that the above array will store two elements, that is, at index 0 and 1 while
allowing room for resizing.
• Adding the element 12 to the index 0 of array nums.
• Adding the element 23 to the index 1 of array nums.
• Using a for loop to create a variable x to help us iterate from the first to the last elements
of the array nums. Note that the array now has two elements, 12 and 23.
• Printing some text and the elements of the array on the console.
• Ending the for loop and jumping to the next part of the code.
• Resize the array nums to allow elements at indexes 0 to 2. It will now be able to store 3
elements rather than 2. The Preserve keyword helps us maintain the current elements of
the array, that is, 12 and 23.
• Adding the element 35 to index 2 of the array. The array now has three elements, 12, 23
and 35.
• Using a for loop to create a variable x to help us iterate from the first to the last elements
of the array nums. Note that the array now has three elements, 12, 23 and 35.
• Printing some text and the elements of the array on the console.
• Ending the for loop and jumping to the next part of the code.
• Pause the console window waiting for the user to take action to close it.
• End of the sub-procedure.
• End of the module.
Deleting an array
• DECLARE:
• Dim num(1) As Integer
• DELETE:
• Erase num
Multi dimensional array / rectangular array
• Dim twoDstringarray(10,20) As String
• Dim threeDIntarray(10,10,10) As Integer

Dim a(,) As Integer = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}}
FUNCTIONS
• A procedure is a group of statements that together perform a task
when called. After the procedure is executed, the control returns to
the statement calling the procedure.
• VB.Net has two types of procedures −
• Functions
• Sub procedures or Subs
• Functions return a value, whereas Subs do not return a value.
Defining a Function
The Function statement is used to declare the name, parameter and the body of a
function.
The syntax for the Function statement is −
[Modifiers] Function FunctionName [(ParameterList)] As ReturnType
[Statements]
End Function

Where,
•Modifiers − specify the access level of the function; possible values are: Public,
Private, Protected, Friend, Protected Friend and information regarding overloading,
overriding, sharing, and shadowing.
•FunctionName − indicates the name of the function
•ParameterList − specifies the list of the parameters
•ReturnType − specifies the data type of the variable the function returns
EXAMPLE FUNCTION
Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
' local variable declaration */
Dim result As Integer
If (num1 > num2) Then
result = num1
Else
result = num2
End If
FindMax = result
End Function
Function Returning a Value

• In VB.Net, a function can return a value to the calling code in two


ways −
• By using the return statement
• By assigning the value to the function name
Recursive Function

• A function can call itself. This is known as recursion.


CONTROL STATEMENTS
• 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 statements to be executed if the condition is
determined to be true
• It repeats a group of statements a specified number of times and a
loop index counts the number of loop iterations as the loop executes.
A) Decision Making condition
B) Decision making Looping
Decision Making condition

• If ... Then statement


• An If...Then statement consists of a boolean expression followed by one or more statements.

• If...Then...Else statement
• An If...Then statement can be followed by an optional Else statement, which executes when the boolean expression is false.

• nested If statements
• You can use one If or Else if statement inside another If or Else if statement(s).

• Select Case statement


• A Select Case statement allows a variable to be tested for equality against a list of values.

• nested Select Case statements


• You can use one select case statement inside another select case statement(s).
If Then
• It is the simplest form of control statement, frequently used in
decision making and changing the control flow of the program
execution
• Syntax:
If condition Then
[Statement(s)]
End If

Example:
If (a <= 20) Then
c= c+1
End If
If...Then...Else

• An If statement can be followed by an optional Else statement, which


executes when the Boolean expression is false.
• Syntax:
If(boolean_expression)Then
'statement(s) will execute if the Boolean expression is true
Else
‘ statement(s) will execute if the Boolean expression is false
End If
Nested If Statements

• It is always legal in VB.Net to nest If-Then-Else statements, which


means you can use one If or ElseIf statement inside another If ElseIf
statement(s).
• Syntax:
If( boolean_expression 1)Then
'Executes when the boolean expression 1 is true
If(boolean_expression 2)Then
'Executes when the boolean expression 2 is true
End If
End If
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 expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End Select
Nested Select Case Statement

• It is possible to have a select statement as part of the statement


sequence of an outer select statement. Even if the case constants of
the inner and outer select contain common values, no conflicts will
arise.
LOOPS
• Do Loop
• It repeats the enclosed block of statements while a Boolean condition is True or until the condition becomes True. It could be terminated at any time with the
Exit Do statement.

• For...Next
• It repeats a group of statements a specified number of times and a loop index counts the number of loop iterations as the loop executes.

• For Each...Next
• 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.

• While... End While


• It executes a series of statements as long as a given condition is True.

• With... End With


• It is not exactly a looping construct. It executes a series of statements that repeatedly refer to a single object or structure.

• Nested loops
• You can use one or more loops inside any another While, For or Do loop.
Loop Control Statements

• Exit statement
• Terminates the loop or select case statement and transfers execution to the
statement immediately following the loop or select case.
• Continue statement
• Causes the loop to skip the remainder of its body and immediately retest its
condition prior to reiterating.
• GoTo statement
• Transfers control to the labeled statement. Though it is not advised to use
GoTo statement in your program.
Do Loop

• It repeats the enclosed block of statements while a Boolean condition


is True or until the condition becomes True. It could be terminated at
any time with the Exit Do statement.
• Syntax:
Do
Statement
Loop {While|Until} (condition)
(or)
Do {While|Until} (condition)
Statement
Loop
For...Next Loop

• It repeats a group of statements a specified number of times and a


loop index counts the number of loop iterations as the loop executes.
• Syntax
For counter [ As datatype ] = start To end [ Step step ]
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next [ counter ]
• If you want to use a step size of 2, for example, you need to display
only even numbers, between 10 and 20
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.
For Each element [ As datatype ] In group
[ statements ]
[ Continue For ]
[ statements ]
[ Exit For ]
[ statements ]
Next
[ element ]
While... End While Loop

• It executes a series of statements as long as a given condition is True.


While condition
[ statements ]
[ Continue While ]
[ statements ]
[ Exit While ]
[ statements ]
End While
With... End With Statement

• It is not exactly a looping construct. It executes a series of statements


that repeatedly refers to a single object or structure.

With object
[ statements ]
End With
Module loops With aBook
Public Class Book Console.WriteLine(.Name) Output:
Public Property Name As String VB.Net Programming
Zara Ali
Public Property Author As String Console.WriteLine(.Author) Information Technology
Public Property Subject As String
End Class Console.WriteLine(.Subject)
Sub Main() End With
Dim aBook As New Book
Console.ReadLine()
With aBook
End Sub
.Name = "VB.Net Programming"
.Author = "Zara Ali" End Module
.Subject = "Information Technology"
End With
Nested Loops

• VB.Net allows using one loop inside another loop. Following section shows few examples to
illustrate the concept.

Syntax
The syntax for a nested For loop statement in VB.Net is as follows −
For counter1 [ As datatype1 ] = start1 To end1 [ Step step1 ]
For counter2 [ As datatype2 ] = start2 To end2 [ Step step2 ] ...
Next [ counter2 ]
Next [ counter 1]
The syntax for a nested While loop statement in VB.Net is as follows −
While condition1
While condition2 ...
End While
End While
The syntax for a nested Do...While loop statement in VB.Net is as follows −
Do { While | Until } condition1
Do { While | Until } condition2 ...
Loop
Dialog boxes
• Many built-in dialog boxes to be used in Windows forms for various tasks like opening and saving
files, printing a page, providing choices for colors, fonts, page setup, etc., to the user of an
application.
• These built-in dialog boxes reduce the developer's time and workload
• CommonDialog class and overrides the RunDialog() method
• functions of the ShowDialog() method that can be called at run time in the
Windows Form.
• Abort: The Abort Dialog box is used when a user clicks on the Abort button to return
the DialogResult.Abort value.
• Ignore: The Ignore Dialog box is used when a user clicks on the Ignore button to
return the DialogResult.Ignore.
• None: It is used to return nothing when the user clicks on the None button, and the
dialog box is continued running.
• OK: When the user clicks the OK button of the Dialog box, it returns a
DialogResult.OK,
• Cancel: When a user clicks on the Cancel button of the Dialog Box, it returns
DialogResult.Cancel,
• Yes: When a user clicks the Yes button of the dialog box, it returns DialogResult.Yes.
• Retry: When a user clicks on the Dialog Box Retry button, it returns a
DialogResult.Retry,
• No: When a user clicks on the No button of the Dialog box, it returns
DialogResult.No,
• commonly used dialog box controls in the VB.NET Windows Form.
• Color Dialog Box
• Font DialogBox
• OpenFile Dialog Box
• Print Dialog Box
tools
UNIT - 4 PART -2
Controls
• Rich controls
• A RichTextBox control is an advanced text box that provides text editing and advanced formatting features including loading rich text
format (RTF) files.

• Creating a RichTextBox

• We can create a RichTextBox control using a Forms designer at design-time or using the RichTextBox class in code at run-
time.
• Runtime creation
Control Purpose
• Dim dynamicRichTextBox As New RichTextBox()
Displays different ad images
and, when clicked, will
navigate to the URL
AdRotator
associated with that image.
You can define the rotation
schedule in an XML file.
Common properties and importants
Common dialog ( discussed in previous part -
1 in unit 4)
• Open File
• Save File
• Open Folder
• Find and replace
• Print
• Page setup
• Font
• Color
Advanced controls
• Word finder

• Scroll bar

• Track bars

• Scan buttons

• Windows menu

• Datetime picker

• Rich text box


• 1.Create a windows application as a word finder, which finds & replace the occurrence of that word with another word in VB.NET.

2.Create an application in which a user can enter a numeric value using one scroll bar between 0 to 100 and displays conversion of the value into Fahrenheit in VB.NET.

3.

There are 3 Track Bars on the Form. The first Track Bar is stands for Red, second for Green and third for Blue, depends on the position of indicator the background color o

f label is display on Mouse Move in VB.NET.

4.

Write a program to create a Tree view dynamically with buttons Add To Root, Add To Selected Node, Remove and Scan buttons. On click of Scan button all the nodes of t

he Tree view should be listed in the List box placed in side by.

• 5.Write

a Program to Implement a MDI application. It should have File menu with option New, Close, Close All and Exit. It should also have window menu to arrange the child fo

rms like Tile Horizontal, Tile Vertical, Cascade and Arrange Icons in VB.NET.

6.

There are 3 Scroll Bars on the Form. The first Track Bar is stands for Red, second for Green and third for Blue, depends on the position of indicator the background color o

f form should be changed in VB.NET.


THANK YOU..

You might also like