Aug 19 2008

Elective 1 - OOP VB.NET Midterm Reviewer

Published by admin at 11:02 am under Uncategorized

Compiled by Aurelie A. Peralta

Main Topics:

1. Introduction to Object-Oriented Programming

2. .NET Concepts

3. VB.NET programming basics

4. VB.NET Classes and Controls

Discussions:

Introduction to Object-oriented Programming

Materials on this topic can be found here: http://en.wikipedia.org/wiki/Object-oriented_programming

.NET Concepts

What is .NET? .NET is a new way of creating Windows applications that includes a consistent framework of base classes that sits on top of the operating system, a Common Type System (CTS) that makes data types usage consistent across .NET programming languages, a Common Language Runtime (CLR), and high level interfaces supporting Windows and web-based applications.

.NET provides language independence and interoperability, easy interoperability with the internet with no need for the complex plumbing and registration requirements of COM. Its Common Language Runtime simplifies application deployment. In .NET, a single computer can host multiple versions of the same components. It is also based on current communication standards such as XML, SOAP, and UDDI.

A .NET language is any language that can be compiled to MSIL. Official languages released for .NET are VB.NET, C#, Managed C++, and JScript.NET including any third party language as long as it compiles to MSIL.

Application Programmable Interface for .NET includes Windows Forms, Web Forms, and Web Services. Windows Forms are classes used to create windows applications, Web Forms are used to create web-based applications exposed through ASP.NET, and Web Services are re-usable back-end components like Microsoft Passport.

Framework Class Libraries provide the basic functionality of an application. Class library components include Data Access, GUI, Security, XML/SOAP, IO/Network, and Threading.

Common Language Runtime is a runtime execution engine shared by all .NET languages. It processes code compiled into MSIL but the compilers of such languages must adhere to Common Type Language Specifications (CLS). The common language runtime implements class loading, common type system, and garbage collection.

The Common Type System specifies how types have to be defined to run under the common language specification which supports intrinsic data types, class types, structure types, interface types, enumeration types, and delegate types. Class types are reference types that implement the object structures defined by class libraries. Class type members consist of properties, fields, methods, and events. Type definition includes scoping and instantiation specifications. Structure types functions as a value stack type rather than a reference type. The Interface types provide sets of member to be implemented into class types and cannot be instantiated. Enumeration types are useful for assigning predefined property values and method parameters. Delegate types functionally replace function pointers in C and are used to provide forwarding calls and callbacks.

Assemblies are the binaries created by .NET compilers organized as either EXE or DLL file. An assembly contains MSIL instructions and a completely self-describing metadata manifest.

The intermediate Language (MSIL) are instructions created by a .NET compiler. It must be processed by the CLR and it is not machine code. It is similar to Java bytecode except that it currently targets only the Windows platform while bytecode can only be created with the Java language.

The framework base classes are organized into namespaces which provide organization for class types. Namespaces prevents conflicts between class types. Some of the common namespaces for the Framework Base Classes include System, System.IO, System.Security, System.Threading, System.Net, System.XML, and System.Windows.Forms.

The Visual Studio IDE contains editors, compilers, resource management utilities, integrated web browser, and a debugger. It can also provide a command-line compiler.

A project is a collection of files that make up the development set of an application. A solution is a collection of projects working for a central purpose.

The Form is a class in the System.Windows.Forms namespace. Each Form has properties, methods, and events. The first step in creating a Windows application is designing the Form. Forms support numerous categories of properties including appearance, behavior, design, layout, and window style.

There are 3 ways to add a control to a form:

1. Double-click the control in the Toolbox

2. Drag the control from the Toolbox to the Form

3. Click the control in the Toolbox and draw the control on the Form.

What is an Event? Events lie at the heart of Visual Basic programming because code runs in response to events which can be clicking a button, typing into a textbox, or loading a form. When the event is recognized, code associated with the event will be executed. Event driven programming requires the programmer to predict how the user will interact with the application and write code to respond to these actions.

The Form has a method called Close(). To close a form, we can use the code FormName.Close() or Me.Close() to close the current form.

VB.NET Programming Basics

Using Variables and Contants

A variable is a place in memory used to store data. The value of the data can change and each variable is given a type which determines the kind of data to store, the size of the data storage, and the location of this storage whether it will be a value type or reference type. We use variables to capture data from users, store results of calculations, store return data from functions, hold data from a database, simplify complex expressions and many other uses. When you create a variable, you must specify a type. Types fall into 2 general categories namely value types and reference types. Value types directly store their data values while reference types store references to heap memory where the value is actually stored such as Strings and Classes. When declaring variables, you must give it a name. Every variable name must be alpha-numeric with underscore allowed, but must not be a keyword and must not contain spaces. In Visual Basic, use the DIM keyword to declare a local variable. Specify the data type as you declare the variable.

Using Option Explicit forces the explicit declaration of all variables. If you use a variable name without declaration first, Option Explicit On returns exception. Option Explicit Off implicitly creates variable of Object type. Option Explicit can be controlled at the project level or at the module level.

The VB.NET assignment operator is the equals (=) sign. You can assign a value as you declare it or you can assign it after it is declared. The values you assign will depend on the data types of the variables. Strings must be enclosed in quotes, dates must be enclosed in number signs, booleans use values of True or False and so on.

Variable Scope and Lifetime

Scope specifies where in the application that the variable is visible. Lifetime specifies how long the variable will hold its value. You determine the scope and lifetime of a variable based on where you declare it and what keyword is used to declare it.

Local variables only has scope within the procedure or code block where it is declared. Its lifetime is limited to that procedure or block. Declare local variables using the Dim keyword.

Static variables are local in scope but lifetime is module level. They are used to hold values between calls to procedure. Use Static keyword to declare them.

A module is the code page associated with a form. We can also create modules that only have code with no form attached. Each module has a Declarations section which is used to created module scoped variables visible throughout the module. Use the Private keyword to define these variables.

You can also increase the scope of the variable to be visible at the project level or even at the solution level. Use Friend keyword for project level variables and Public keyword for solution level variables.

Constants are similar to variables except that it is always declared with the Const keyword, its value never change, and is more efficient due to early binding.

A structure is a user-defined value type that can store many different data types into one structure. An array is a set of values using a single reference. Unlike structures, all values in an array must be of the same type and have the same scope. Each element of the array is identified by using an index number. Declare arrays using the same keyword as any other variable. An array can be single dimensional or multi-dimensional. Use the parenthesis symbol to specify the size and index of an array.

A procedure is a block of VB.NET code that performs some functionality of the program. Event handlers are examples of procedures. Each procedure has a name and is called by that name. Procedures promote code-reuse by allowing code to be called rather than rewritten.

There are numerous types of procedures but the 2 most commonly used types are Sub Procedures and Function Procedures. Sub procedure performs an action but do not return a value while a Function procedure perform an action and returns a value. There are many Built-in Functions in VB.NET and they are part of the Visual Basic runtime library. All built-in functions are global.

When a form is set as the startup object, the application starts with that form but we can also start the application by creating our own Sub Main(). In the Sub Main(), we can explicitly call Application.Run and Application.Exit. We can set startup object in the project properties window.

Operators and Expressions

Arithmetic Operators: + for addition, - for subtraction, / for division returning floating point values,  \ division returning integer value, Mod for Modulus Division returning the remainder only, * for multiplication, and ^ for Exponent.

Assignment Operators: = for simple assignment, += for adding and assigning, -= for subtracting and assigning, *= for multiplying and assigning, /= for dividing and assigning, and &= for concatenating and assigning values.

 Comparison Operators: >, >=, <=, =, <>

Logical Operators: And, Or, Not, Xor, AndAlso, OrElse

Miscellaneous Operators: & for Forced Concatenation, + for string concatenation, AddressOf for creating procedure delegate, and GetType for returning instance of the type defining an object.

Expressions become one of the basic building blocks of any software application. We build expressions to assign values to variables or properties, manage control of flow, and calculate complex results.

Strings are reference types, not value types so they have some different behaviors. Since strings are objects, they also have many properties and methods associated with them.

Control of Logic Flow

You can control the way that your application executes code by using control of flow structures or program controls. There are two general types of structures namely Desicion and Iterative. Using them correctly can simplify your task of writing code.

Additional learning support materials:

Sample Downloadable Programs for the following topics:

Variable Scope and Lifetime

Control of Logic Flow (Program Controls)

Arrays

VB.NET MDI, Classes and Controls

5 Responses to “Elective 1 - OOP VB.NET Midterm Reviewer”

  1. Ariananarlon 14 May 2009 at 6:33 pm

    Hi there, not sure that this is true, but thanks

  2. KrisBeluccion 03 Jun 2009 at 12:55 pm

    I really liked this post. Can I copy it to my site? Thank you in advance.

  3. AndrewBoldmanon 05 Jun 2009 at 7:42 am

    da best. Keep it going! Thank you

  4. GarykPattonon 17 Jun 2009 at 5:04 am

    Hello. I think the article is really interesting. I am even interested in reading more. How soon will you update your blog?

  5. RobAndreion 03 Jul 2009 at 7:00 pm

    Ahahaha. I hope reviewing this will help me pass this subject. Ahahaha

Trackback URI | Comments RSS

Leave a Reply