Unit 1 - Getting started with visual basic PDF

Title Unit 1 - Getting started with visual basic
Course Visual basic
Institution Bangalore University
Pages 69
File Size 8.9 MB
File Type PDF
Total Downloads 111
Total Views 147

Summary

Power Point Presentation of unit 1 getting started with visual basic...


Description

UNIT ONE GETTING STARTED WITH VISUAL BASIC

VB.NET  Object-oriented

computer programming

language.  Not backwards-compatible with VB6.  All objects inherit from the base class Object.  Implemented by Microsoft's .NET framework.  Full access to all the libraries in the .NET Framework.

OTHER FEATURES: 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. 

.NET FRAMEWORK

Source : https://en.info-novitas.hr/technologies/microsoft-technologies/

.NET FRAMEWORK The .NET framework is a software development platform developed by Microsoft.  The framework was meant to create applications, which would run on the Windows Platform.  The .NET framework can be used to create both Form-based and Web-based applications  .NET Components 

  

CLR Class library .NET Languages

https://www.guru99.com/net-framework.html

CLR (COMMON LANGUAGE RUNTIME)  

Provides a “runtime environment” for the execution of code written in ANY .NET Language. “Manages” The overall execution of . NET code  Inheritance, Memory, Debugging, and application development across Multiple languages 



Languages that utilizes the . NET framework must follow the CLS Common Language Specification  Outlines the rules and standards required or needed by the CLR to execute . NET code. 

 

The CLR will execute Managed Assemblies Intermediate Languages managed by the CLR are called Managed Code



The CLR will manage for the IL   



Garbage collection Object instantiation Memory allocation

Components written in Managed Code by the CLR are called .NET Managed assemblies.

CLASS LIBRARY A class library is a collection of methods and functions that can be used for the core purpose.  The .NET Framework includes a set of standard class libraries  Methods are split into either the System.* or Microsoft.* namespaces. 

.NET LANGUAGES .NET applications can be written by any or a combination of many . NET languages  Languages include 

VB  C#  J#  Managed C++ (default in studio is set for managed C++) 



Applications can be developed without the use of Studio .NET  

Applications can be developed still using a simple text editor ASP .NET Applications as well as other apps can be still developed using notepad

CTS Common Type System (CTS) is a standard that specifies how type definitions and specific values of types are represented in computer memory.  Allows programs written in different programming language to easily share information 

https://en.wikipedia.org/wiki/Common_Type_System

VB.NET OPERATORS 

Arithmetic operators



Comparison operators



Logical operators



Concatenation operators

OPERATORS 

 

  

Arithmetic operators are used to perform arithmetic calculations such as addition and subtraction. Comparison operators are used to compare two or more values. Logical operators are used to perform logical operations such as AND, OR, NOT on one or more expressions. Concatenation operators are used to join two string values. & and + arethe two concatenation operators available in VB.NET. The operator & is used to concatenate two strings and + is used to add two numbers and concatenate two strings.

ARITHMETIC OPERATORS Operator

Purpose

Example: Let a=10

Output

+

Addition

b=a+5

55

-

Subtraction

c=a–5

45

*

Multiplication

d = a * 10

500

/

Division

e=a/6

8.33

f=a\6

8

g = a mod 7

1 2500

\

MOD

Division (integer part only given as output) Modulas (Remainder after division)

^

Power

h = a^2

=

Assignment

m = 100

COMPARISION OPERATORS Operator

Purpose

Example: Let a=50

Output

=

Check if a value is equal to another

Dim b As Boolean b=(a=55)

FALSE

b=(a55)

TRUE

b=(a>100)

FALSE

b=(a=50)

TRUE

b=(a <

>=

b) AND (bb) OR (bb)

FALSE

LOGICAL OPERATORS

DATATYPES Data types determine the type of data that any variable can store.  There are various data types in VB.NET. They include: 

Datatype

Bytes

Boolean

Platform dependent.True/False

Byte

1 byte

Char

2 bytes

Date

8 bytes

Integer

4 bytes

Long

8 bytes

String

Platform dependent

VARIABLE DECLARATION Dim VariableName as DataType Dim x_var as Integer

CONDITIONAL STATEMENTS, LOOPS AND ARRAYS

Flow Control And Conditional Statements If…Then…Else statement: If Boolean expression Then Statement or block of statement Else Statement or block of statement End If If(boolean_expression 1)Then ' Executes when the boolean expression 1 is true ElseIf( boolean_expression 2)Then ' Executes when the boolean expression 2 is true ElseIf( boolean_expression 3)Then ' Executes when the boolean expression 3 is true Else ' executes when the none of the above condition is true End If

Select…Case statement

Select Case expression statements ' some other case blocks ... Case Else statements End Select



Select Case is a conditional statement, that helps you test a variable for equality against a set of values.



Syntax



Select



Case expression



statements



' some other case blocks



...

  

Case Else statements

End Select

LOOPS IN VB.NET For…Next Loop For variable = startingValue To lastValue

statement or block of statements Next Example: For i = 1 to 10

Console.WriteLine("value of i: {0}", i) Next

Do While loop Syntax: Do { While | Until } condition [ statements ]

[ Continue Do ] [ statements ] [ Exit Do ] [ statements ] Loop

Do [ statements ] [ Continue Do ] [ statements ] [ Exit Do ] [ statements ] Loop { While | Until } condition

For each Dim arr() As Integer = {1, 3, 5, 7, 9} Dim a As Integer 'displaying the values

For Each a In arr Console.WriteLine(a) Next

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

While a < 10 Console.WriteLine("value of a: {0}", a) a=a+1 End While

UNIT 1 – Unit Test MCQ - Answers 1 - Which of the following is a basic data type in VB.NET? A - Boolean B - Byte C - Char D - All of the above.

2. The default property for a text box control is A. Text B. Enable C. Multiline D. Password char

3. A GUI A. uses buttons, menus, and icons B. should be easy for a user to manipulate C. stands for Graphic Use Interaction D. Both a and b

4. Visual Studio .NET provides which feature: A. debugging B. application deployment C. syntax checking D. All of the above

5. GUI stands for _______ A. Graphical User Interchange B. Graphical User Interface C. Geometrical User Intelligence D. Geometrical User Interchange

6. Which language is not a true object-oriented programming language? A. VB6 B. VB.Net C. Java

D. C++

7. What does IDE stand for? A. Integrated Design Environment B. Integrated Development Environment C. Interior Design Environment D. Interior Development Environment

8. Which type of project can a developer choose in the New Project dialog box? A. Visual Basic Projects B. Visual C++ Projects C. Visual C# Projects D. All of the above

9. For which task does the IDE provide multiple ways to accomplish the task? A. Putting a control on the form B. Running the program C. Activating the property window for a control D. All of the above

10. An object is composed of: A. Properties B. events C. methods D. All of the above

11. Which statement about objects is true? A. One class is used to create one object. B. One class can create many objects. C. One object is used to create one class. D. One object can create many classes.

12. Which property determines whether a control is displayed to the user? A. Visible B. Enabled C. Show D. Hide

13. The Button control can be activated: A. by clicking the button with the mouse. B. programmatically through the click event. C. both (a) and (b) D. with the form’s DefaultButton property.

14. The Java and Visual Basic .NET belong to this type of programming language. A. Assembly language B. Machine language C. High level programming language D. Object oriented programming language

15. A window that lists the solution name, the project name and all the forms used in the project. A. Properties Window B. Solution Explorer C. Windows Form Designer D. Project Window

16. In VB.NET language, which one is not the integer value? A. 12 B. '23' C. 10 D. 100

17. The function procedures are ___________ by default. A. public B. private C. protected D. inherited

18. _________ are interactive objects that you place in dialog boxes or other windows to carry out user actions. A. Forms B. Controls C. Classes

D. Objects

19. Which of the following is correct about VB.NET? A. VB.NET has complete support for object-oriented concepts. VB.NET has complete support for object-oriented concepts. B. 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 even assemblies. C. All objects inherits from the base class Object. D. All of the above

20. Which of the following accesss modifier specifies that an argument is passed in such a way that the called procedure or property cannot change the value of a variable A. ByRef B. ByVal C. Default D. Friend

21. …………………… is the process by which you can derive new classes from other classes. A) Abstraction B) Encapsulation C) Polymorphism D) Inheritance

22. ………………… is the ability to create procedures that can operate on objects of different types. A) Abstraction B) Encapsulation C) Polymorphism D) Inheritance

23. Which of the following is an entry point method of VB.NET program? A. Sub Main B. function main C. Both of the above D. None of the above

24. Which is not a main component of the Visual Studio IDE? A. Solution Explorer B. Tool Box C. Start Menu D. Designer Window

25. Whenever an application is created, a ______ is added. A. Form B. Class C. Property D. Object

ARRAYS, STRUCTURES AND VAL

ARRAYS IN VB.NET An Array is a collection of values of similar data type. Each array i VB.Ne is an object and is inherited from the System.Arra class. Arrays are declared as follows:

Dim () As

EXAMPLE

Dim myIntege (9) As Integer (Or)

Dim myIntege () As Integer myInteger = New Integer() {1, 2, 3, 4, 5}

THE FOR EACH LOOP

For Each in

Next

Example: Dim myIntege () As Integer = New Integer() {3, 7, 2, 14, 65}

' iterating through the array Dim As Integer For Eac

i myIntegers prin statement

Next

IMPORTS STATEMENT The imports statement is used to include a namespace into the program. Namespaces act as containers to store types such as classes, structures etc.,

STRUCTURES IN VB.NET A user defined data typ .

The are us types.

defined and provide a method for packing together data of different

Use structure keyword to declare the structure It is value type and store on Stack Cannot have explicit default constructor but can have parameterized constructors Cannot have destructor Cannot participate in inheritance Structure members can be private as well

Structure Customer Privat custi As Integer Private name As String Private balance As Double Public Sub New ByVa custi As Intege ByVa name As String ByVa opam As Double) Me.custi = custid Me.name = name balance = opamt End Sub

Public Sub Deposi ByVa amount As Double) balance += amount End Sub Public Su ShowAccou () Console.WriteLin ("Balance of {0} is {1}", name, balance) End Sub

Class StructTest Public Shared Sub Main() Dim c As New Customer(1234, "Rakesh Verma", 9000) c.Deposit(5000) c.ShowAccount() End Sub End Class

VAL FUNCTION converts any string representation of a number to a number returns double to hold the number contained in expression v (expression)

GET STARTED WITH YOUR FIRST CONSOLE APPLICATION Import System.Console Module Module1 Sub Main() Console.WriteLin (“Hello from visual basic 2008”)

Console.ReadLin () End Sub End Module

OBJECT ORIENTED PROGRAMMING

There are mainly two types of programming1.PROCEDURE ORIENTED PROGRAMMING

2.OBJECT ORIENTED PROGRAMMING

POP • POP follows the concept of breaking a problem into smaller tasks ,solves each task seperately and then combines all the tasks to solve the entire problem.

• Reusablity becomes difficult.

OOP • OOP uses the concept of object to reuse the exisiting code. • An object may contain certain behaviour and properties. • Behaviour is called as method and properties are called attributes.

BASIC PRINCIPLES OF OOP Encapsulation: • Data hiding is the process of showing only the relevant information and hiding the irrelevant information from the user.

• It binds the variables and functions into a single unit called a class.

Abstraction • is the process of providing the essential features without providing the background details or explanations.

• Inheritance is the process of OOP which allows you to reuse the existing code. • It is a mechanism to design or construct a class from the other.

• Polymorphism • means ,one name multiple forms • Method overloading: Same method name ,but different number of arguments. • Method Overriding :Same method name and same number of arguments declared in different classes

classes and member access modifiers

Functions and Sub procedures / Programs in VB .NET (Methods) 

Functions and sub procedures must either have a sub or function keyword in the function or sub procedure heading



They can be either public or private (following the same conventions in OOP languages such as C++ or Java)



All parameters are passed by value by default in VB .Net



Parameters of any data type may be passed by reference



All Objects and arrays are passed by reference not value



All events are handled by a sub procedure in VB .Net



Functions return a value and Sub Procedures do Not

Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer Dim result As Integer If (num1 > num2) Then result = num1 Else result = num2 End If FindMax = result End Function

Sub CalculatePay(ByRef hours As Double, ByRef wage As Decimal)

'local variable declaration Dim pay As Double pay = hours * wage Console.WriteLine("Total Pay: {0:C}", pay)

End Sub

CLASSES AND OBJECTS 

A class is similar to a container that may have datamembers such as variables, constants, methods, properties ,events , constructors etc.,



An object is an instance of a class

[access-modifier] class variables-declaration methods declaration

End Class class Class1 Dim x as integer

Public y as integer End Class

CLASS IN VB.NET 

[ ] [ accessmodifier ] [ Shadows ] [ MustInherit | NotInheritable ] [ Partial ] _



Class name [ ( Of typelist ) ]



[ Inherits classname ]



[ Implements interfacenames ]



[ statements ]



End Class

Where, 

attributelist is a list of attributes that apply to the class. Optional.



accessmodifier defines the access levels of the class, it has values as - Public, Protected, Friend, Protected Friend and Private. Optional.



Shadows indicate that the variable re-declares and hides an identically named element, or set of overloaded elements, in a base class. Optional.



MustInherit specifies that the class can be used only as a base class and that you cannot create an object directly from it, i.e., an abstract class. Optional.



NotInheritable specifies that the class cannot be used as a base class.



Partial indicates a partial definition of the class.



Inherits specifies the base class it is inheriting from.



Implements specifies the interfaces the class is inheriting from.

Access Modifiers 

Public



Private



Protected



Friend



ProtectedFriend

FUNCTION AND SUB PROCEDURES [access-modifier]Function (parameterlist) As type [access-modifier]sub (parameterlist) As type Sub procedure body End Sub

Creating Objects Dim As New () Objectname.variablename Objectname.methodname()

Constructors and destructors 

Constructors and destructors are special types of methods



A constructor is a method that is called when the object is created



A destructor is a method that is called when the object is destroyed.



In visual basic we use New method to create a constructor and Finalize or Dispose methods are used to call a destructor





The main features of a constructor are-

It is a sub procedure declared with a New keyword



It does not have any return type



It is invoked automatically when the object is created.

Partial classes 

A class definition consists of a set of member variables and methods



The member variables are declared within a class body.



However you can break the class into two or more classes where each class is known as partial class and stored in separate source file.



These definitions in different source files are combined when they are executed.



A class is divided into two or more classes using the partial keyword.

Sh...


Similar Free PDFs