You are on page 1of 16

Lecture on Visual Basic .

NET

I. Introduction
VB.NET is a programming language a.k.a software development tool. Programming languages are used to create operating systems, applications programs such a Word, Excel, Access, PowerPoint, FrontPage, Publisher, and Telecommunications programs. Everything that we do with a computer must first be written in a programming language. The first programming language developed is called machine language which is written with 1 and 0. This language is often referred to a binary or digital language. This language required the programmer to give step by step instructions for each action in binary code. Computers only understand machine language. The second level programming language is called assembler language. This language allowed the programmer to use alphabet characters such as MV (which means move) that will be translated by the program into machine language. Two methods are used to translate a programming language into machine language.

1. A compiler takes all of the source code and translates the code into another file called the object file which is in binary format and then executes the object file. The source file still remains. Compiled programs execute independent of the programming language and execute much faster than interpreted languages. Object files generally have a .exe extent. When you compile code in vb.net it is first complied in an intermediate language (IL) and then executed Just in Time (JIT) by the Common Language Runtime (CLR) compiler which is distributed with the IL code when sent to a PC or an Internet Site. 2. An interpreter take one line of the source code translates it into machine code, executes the line, returns to the source code and gets the next line, interprets it into machine code. This continues until all of the source code has been translated and executed line by line from the top of the program to the bottom. This is referred to as sequencing through the program. An interpreter functions inside of the programming language. The third level programming languages (Higher Level) consisted of languages that were closer to natural languages. Cobol, RPGII, Qbasic, Pascal, C, C+++, Fortran are examples of third level languages. These languages allow you to use English words such as print, input, and read to write program code. The fourth level languages are the visual languages such as Visual Basic, VB.NET and Visual C+++. These are also called Object Oriented Programming

Lecture on Visual Basic .NET languages because they attached code to objects (icons/visual pictures). Windows 98 was written using OOP. The fifth level languages are the voice actuated languages. Windows Office XP comes bundled with voice actuation and writing pad actuation.

II. Visual Basic.NET Object-Oriented programming Language A.K.A as OOP.


Visual Basic .NET combines a graphical interface called the Integrated Development Environment (IDE) and programming code to make program development as rapid as possible. The IDE contains tools for creating, testing and running computer programs. The core of the .net environment is the IDE known as Visual Studio.Net (VSN). VSN includes visual basic.net among several other programming languages such as C#.net and C+++.net. Microsoft also sells the IDE to third party vendors who use it for their own programming languages. There are three way of writing code in the IDE. 1. Console mode applications in which the code is run from the XP command Prompt. This is the same mode as earlier versions of Basic, BasicA, and Qbasic. There is no graphic user interface. 2. Windows-based mode applications in which code is written and run in windows graphic interface on the desktop. When writing code in the window mode objects are created which are event (action) driven and execute code attached to the graphic object.(OOP). The user interface in the windows mode is a form in which objects are placed and code attached in the background. 3. Web-based mode applications has a web user interface and runs on a web server that can be accessed using a computers internet browser. Code can be written to execute in the Command Prompt environment, Windows environment, and Web Server environment using the IDE. An object is anything that can bee seen, touched, or used; whenever you go to the start button in window you are going to an object. Attributes are the characteristics that describe the object. When you tell someone that you have a Pentium 4 computer that runs at 4 GigaHz, a DVD drive and 1 GigByte of Memory you are describing some of the attributes of your computer.

Lecture on Visual Basic .NET An objects behavior also referred to as methods are the operations (actions) that the object is capable of performing. Your computer can save digital files to a hard drive, transmit and received data over the internet, be used for word processing, etc. A class is a structure, design used to build an object and includes (encapsulates) the attributes and behaviors of the object. Your computer would be a class that has the above attributes and behaviors. A class is not an object until it has been built. Your computer did not become an object until an instances (the building of the computer, the use of the class in the program) of the class occurs. Abstraction refers to the hiding of the internal detail of an object from the user. This prevents the user from changing the object when they should not be messing with it. Attributes that are not hidden are said to be exposed to the user. You only want to expose the behaviors and attributes that are necessary for the user to complete their job and hide all of the rest of them. Once you create a class you can create another class from it called a derived class. The derived class inherits (inheritance) the attributes and behavior from the base class (the class from which it was built). When you buy a new computer the salesman will show a base machine, and then will show you one with a DVD, Joy Stick, Large Monitor, Wireless Keyboard, etc. The computer with all the bells and whistles is derived from the base class and inherits all of its attributes and behaviors and has some of its own. Polymorphism is the oop feature that allows the same instruction to be carried out differently depending on the object. You open a file, open a form, open a report, etc. An event (action) is something that occurs to an object. When you left click the start button (object) on the window desktop a pop up window comes up that allows you to access the programs. The left click was an event that executed code that was attached to the object. If you right click the start button the response will be a different pop up menu. The right click action executes different code on the object. One object can have many different events associated with it. Visual Basic. Net is an event driven OOP language. Visual Basic .Net is a graphical programming language that let you build a complete application without writing any source code. The functionality of the application will be very limited without writing code. Writing Source code attached to objects.

Lecture on Visual Basic .NET All computer languages operate within the Structured Theorem parameters which allow the solving of programming problems with: 1. Sequencing in which source code is executed line by line from top to bottom. All computers execute source code starting at the top of the program and continue to the bottom (end) of the program code. 2. Selection in which a branch of code is executed based on a true or false condition. The control structures used with selection are if, then, endif for single selection, if, then, else, endif for two way selection statement, and a if, then, elseif, then, else enidif for multiple selection. If age < 30 then Print "You are less than 30 yrs old" ElseIf age <40 then print "You are less than 40 yrs old" Else Print "You are older than 40" End If

IF condition1 THEN [statementblock-1] [ELSEIF condition2 THEN [statementblock-2]]... [ELSE [statementblock-n]] END IF

3. Iteration (looping, repetition) in which a branch of code is executed over and over while a condition is true. The control structures are Do-While-Loop, DoLoop-Until, and For-Next for iteration statements. DO [{WHILE | UNTIL} condition] [statementblock] LOOP or DO [statementblock] LOOP [{WHILE | UNTIL} condition] FOR counter = start TO end [STEP increment] [statementblock] NEXT [counter [,counter]...]

4. Select Case allows selection of a branch of code based on a pre-selected condition being true. My friend Brian Marshall considers that the Select Case is a selection statement and that Structured Theorem only has three elements. The control structure for select case is

Lecture on Visual Basic .NET SELECT CASE testexpression CASE expressionlist1 [statementblock-1] [CASE expressionlist2 [statementblock-2]]... [CASE ELSE [statementblock-n]] END SELECT

In summary all computer programming languages solve problems using sequencing, selection; iteration and case select control structures. We will be working with the above control structures when we write code behind the objects. Additionally data used during program execution is obtained through three primary ways. 1. Data is stored within the program. VB.Net does this by using a dimensioned array with a list. For example: Dim strMonth() as String = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"} will store in memory in elements 0 to 11 for the strMonth variable the above data. This is called an initialization list which will automatically set the upper bounds of the array equal to the length of the list. 2. Data is input from the keyboard or other device. Text boxes are the fields place on dialog boxes and in other windows that allow the user to enter a value. The characters entered into a text box needs to be converted into a numeric value before mathematical operations can be performed. The Val function takes number that are in text format and returns a numeric value that can be used in calculations. lblTotal.Text=Val(txtPrice.Text) In this example the data contained in the txtPrice.text box will be converted into a number and assigned to the lblTotal.text box. 3. Data is written to or input from a disk storage device.

III. Creating a project using Microsoft Visual Studio


.NET
Click on new project:

Lecture on Visual Basic .NET

Definitions
A Graphical User Interface (GUI) is the visual part of a program containing forms and controls. A control is a visual object on the screen that helps the program to communicate with the user by accepting input or displaying output. Multi-tasking is the process of doing more than one thing at a time. A front-end program is a client application that connects to a database or other server program. A back-end program is a server program that accepts connections from client applications. A multi-processing systems are computers with more than one processor that are capable of handling more data-processing tasks than computers with just a single processor.

Lecture on Visual Basic .NET

Lesson 1 Things to remember in Visual Basic .NET


1. Microsoft Visual Basic.NET is a software development tool that allows you to create Windows programs. VB.net is a part of Visual Studio.Net 2. VB.NET project is made up of several files. a). VBPROJ extension - holds data about a project. b). SLN extension - information about a solution is stored in this file. c). The solution explorer allows you to see and open the forms and other files that make up a project. 3. The properties window lets you view the characteristics or properties of the objects and make changes to those properties. 4. The toolbox holds the tools that allow you to add objects to a form. 5. To run a program, click the start button on the Standard toolbar. 6. The integrated Development Environment

Lesson 2 To start in Visual Basic .NET


1. The Windows application project type allows you to create a program from scratch. 2. All windows applications begin with a blank form and must have at least one form that becomes the window when the program is run. 3. All other objects are contained within the form(s). 4. By default a window created in VB.Net can be moved, resized, maximized minimized, and closed. 5. Properties are the characteristics of an object and can be changed in the properties window. a). The text property controls what the user sees in the title bar of a form and in other objects. b). The Name property allows the developer to refer to objects using a meaningful name in programming code. 6. Controls are the objects that make up the user interface. 7. A button is a standard pushbutton control the commonly appears in dialog boxes. They can be moved, resize and deleted like other objects. 8. Focus refers to the active status of an object in the window. Only one object can have the focus at a time. Focus is controlled by the tab order. 9. BackColor property controls the background color of a form. 10. Location property can be used to accurately position objects by Pixels.

Lecture on Visual Basic .NET

Lesson 3
1. Windows is an event/action-driven environment which requires the user to take an action to control the work being done. 2. Event procedures must be written for event you wish to handle, click, or double click, or right click. 3. To access the code window double click the object. (an event) 4. VB.NET code is written in sections called sub routines. 5. VB.NET has intelliSense feature to help format our program code. It offers what must follow the original code. 6. The end statement ends a program. 7. PictureBox tool allows you to add a picturebox control to a form. Use the name property. 8. The SizeMode property set to StretchImage cause a picture to resize to fit the dimensions of the Picture Box control. AutoSize cause a PictureBox control to resize to fit the picture. 9. Visible set to False will hide object. Visible set to True will display object. 10. VB.NET code is often used for setting properties of an object which allows the change of properties while the program is running. 11. To change properties to from code you send a message to the object which uses a method to change the property. 12. A button with a & in front of a letter in the Text property cause that letter to become an access key. A button named in the form's AcceptButton property will be activated when he user presses the enter key. The CancelButton property will be activated by the Esc key.

Lesson 4 Simple Math in VB .NET


1. Operators perform specific operations. a). + add values b). - subtracts the value to the right of the operator from the value to the left of the operator. Also can be used to perform unary negation. c). = assigns the result of the expression on the right of the operator tot he item to the left of the operator. d). * (asterisk) is used to multiply - e.g. 5*2=10 e). / (forward slash) is used for division - e.g. 5/2=2.5 f). \ (black slash) is used for integer division - e.g. 5/2=2 g). mod is used for module division which returns the remainder - e.g. 5 mod 2 = 1

Lecture on Visual Basic .NET 2. Values keyed directly into code are called hard-coded values or literals (constants) 3. Text boxes allow the user to enter a value. 4. The VAL() functions is used to convert text numbers in a text box to numeric values. 5. The _ (underscore) is called the line-continuation character. 6. An ' (apostrophe) is used for a comment line that is not executable. 7. The FIX() functions removes the fractional portion of a number by truncating.

Mathematical Order of precedence for evaluating expressions/formulas. Mathematical Operator ^ - exponential * - multiply / - divide \ - integer division mod - modular division + - add - - subtract ( ) parenthesis Use 3^3 = 27 3*3 = 9 5/2=2.5 5\2 = 2 5 mod 2 = 1 5 +2 = 7 5 - 2=3 do what is inside first

Lesson 5 1. The exponential operator (^) raises a number to a power. 2. The rules that dictate the order that math operators are applied in a formula are called the order of operations. 3. Parentheses can be used to override the order of operations. 4. The Visible property can be used to hide a label until you are ready for the user to see it. 5. The apostrophe is used to add comments to VB.NET code. Internal Documentation. 6. Run-time errors (exceptions) occur while the program is running. 7. Try/Catch/EndTry is used for error trapping. 8. Exit Sub is used to exit an error. 9. MsgBox function pops up a dialog box, delivering a message to the user. 10. When a error can not be completely handled, send message to user and use exit sub to end the event procedure before the error can cause additional problems.

Lecture on Visual Basic .NET

Lesson 6 1. Data can be in the form of numbers, text, dates, pictures, and even sound. 2. VB.NET supports a set of data types. Whole numbers, floating-point numbers (decimals), text, dates, and more. Data Type Byte Short Integer Long Decimal Types Single Double Decimal Other Types String Date Boolean Object Range 0 - 255 -32,768 to 32,767 -2,147,483,648 to 2,147,483,647 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 -3.402823E+38 to 3.402823E+38 -1.79769313486232E+308 to 1.79769313486232E+308 -922,337,203,685,477.5808 to 922,337,203,685,477.5807 1 to 65,000 characters Jan 1,0001 to dec 31, 9999 True or False Varies

3. Data stored in memory locations are called variables. 4. AutoSize property will adjust the size of a control to fit its contents. 5. The Dim statement is used to declare variables. 6. Variable names a. Must begin with a letter. b. After the first character letters, numbers and Underscore(_) are allowed. c. No spaces in name d. <=255 characters in name e. Variable name prefixes.

Prefix byt srt int

Data Type Byte Short Integer

Example bytCount srtIndex IntPeople

Lecture on Visual Basic .NET lng sng dbl dec str dte bin obj Long Single Double Decimal String Date Bollean Object lngInches sngWeight dblMass decSalary strName dteAnniversary binSold objValue

7. Scope indicates what procedures have access to a variable. Local, Formlevel, or global. a. Local is declared within an event procedure. b. Form-level is declared in the declarations section of a forms code window. c. Global is declared in a code modules declarations sections. d. general rule is to declare variables locally. 8. Declarations section of a form's code window allows you to declare form-level variables. 9. Object data type can hold may different kinds of data, but is less efficient than specific data types.

Lesson 7
1. Strings hold text or alphanumeric data 2. String is a data type 3. Text in a string variable must be placed in quote marks 4. The assignment operator (=) can be used to assign text fro a text box to a string variable or from a string variable to another string variable. 5. Concatenation is the process of appending one string to the end of another using the &. 6. Single, double, and Decimal data types hold decimal data. a. decimal data type is specifically designed for handling dollars and cents to 4 decimal places. 7. Format() function can be used to format decimal values, phone numbers, and more. Symbol 0 # . Description Cause a digit to appear in the space, if the data has no value a 0 appears Cause a digit to appear in the space, in the data has no value nothing appears Used to specify where you want the decimal point to appear in the

Lecture on Visual Basic .NET format commas will appear in the output Causes a number to be multiplied by 100 and a % sign at the end of the number

, %

8. The Enabled property is used to make a control inactive or active. 9. The SelectionStart and SelectionLength properties and the Len() function can be used together to highlight the text in a text box. Lesson 8 1. Comparisons are made using conditional operators Conditional Description Operators = Equal to > Greater than < less than >= Greater than or equal to <= Less than or equeal to <> Not 2. Decisions are reached by making comparisons. 3. Conditional operators compare values and return either true or false. 4. A boolean variable can be used to store the results of an expressions that include conditional operators. 5. Selection (decision statements) in which a branch of code is executed based on a true or false condition. The structures used are if, then, end if for single selection, if, then, else, end if for two way selection statement, and a if, then, elseif, then, else, end if for multiple selection. The if statement is the most common way to make a decision in a program. 6. Flowcharts allow programmer to plan and document program code using symbols connected by lines.
decision

processing

input output

Lecture on Visual Basic .NET

7. Check boxes are used for Yes/No, or turn option on/off. Can be set to checked or unchecked in properties. 8. Logical operators can be used to combine several comparisons into one statement.

AND A True False False False B True True False False OR A True False False False B True True False False C True True True False Result True True True False C True True True False Result True False False False

XOR A True False False False B True True False False C True True True False Result False True True False

Lecture on Visual Basic .NET

Not A True False Result False True

Operator Precedence used in evaluating expressions High ^ Unary + or * / \ mod + <, >, <=, >=, =, <> NOT AND Low Lesson 9 1. If statements can be nested inside of each other. Indent the nested if so you can keep them straight. Each If must have an Endif. 2. Radio (Option) buttons appear in groups. Only one can be active in the group. 3. Create a GroupBox to contain the radio buttons. The controls in a Groupbox are treated as one unit. 4. The text property of a groupbox control specifies the text that appears at the top of the groupbox. 5. To place a radio button in a group box, click and drag to groupbox. Do not double click. 6. The text property of a radio button specifies the text that appears on the label attached tot he radio button. 7. Coding radio buttons involves using form-level variables that carry values that reflect the selected radio. 8. A form's Load event procedure is executed each time the from is loaded and opened by the program. 9. The Select Case statement allows you to make multi-way selections. a. The case can test a range or use conditional operators. Only selects the true. b. When using conditional operators the Is must be used. Case is >5. OR and XOR Relational Logical Arithmetic

Lecture on Visual Basic .NET c. Case else is applied in no other case is true.

Lesson 10 1. Iteration is another word for looping. Iteration allows us to repeat code over and over while a condition is true/false or until a condition becomes true/false. a.Do while test the condition at the beginning of the loop. The loop may or may not execute once. b. Do until test the condition at the end of the loop. The loop will always loop once. c. Do While age >5 Loop d. Do Loop until age >5 2. InputBox function creates a window that prompts the user for input. a. text for the prompt b. title for the window's title bar c. optional default text for the text box. d. InputBox(" ", " ", " ") 3. Sometimes long event procedures can make a program unresponsive to other events. 4. An endless loop is a loop in which the condition which stops the loop is never met. a. Ctrl+Alt+Break will pause an endless loop. 5. The Application.DoEvents subroutine allows the program to process other events while an event procedure is executing. 6. Loops can be nested in the same way that If statements are nested. Lesson 11 1. ListBox control is used for displaying list of information. a. Items.add method adds items to a listbox control b. Items.Clear method remove entries in a listbox control. 2. For, Next loop is used for executing code a specific number of times. a. Statements between the for and the next are executed. b. Always involve a counter variable. c. Step key word can be used to change increment value. d. Step key word can be used to count backwards. e. can be nested f. indenting code with nested for next is helpful 3. Font property is used to change the font, style, and size of a label

Lecture on Visual Basic .NET Lesson 12 1. Arrays use an index or subscript to access different variable with the same name. 2. All elements of the array are of the same data type. 3. Arrays are declared by specifying the upper bound of the array. a. Dim intMonth(11) as Integer - reserves 12 elements -0 to 11 lowerbound=0 4. Arrays can be declared using initialization lists that set the starting values of the array. a. The upper bound limit is calculated by the system based on the number of items in the list. b. Dim StrMonth() as String={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"} c. Creates a 12 element array - Jan in 0, Dec in 11. 5. Individual element in an array are read or changed by using an index value in () to identify the element to use. 6. The GetLowerBound and GetUpperBound methods can be used to check that an index value is in the allowable range. 7. The length method of an array returns the number of elements in an array. 8. Arrays can be processed sequentially using a loop. a. a loop can be used to apply the same process to each element in an array. b. Set each element in an array to a specific value c. can be used to prompt for input for each element in an array and set its value d. can be searched by using an if statement in a loop that compares each element of the array with a specific value. 9. Parallel arrays are any number of arrays, which may be of different data types, that hold information in corresponding elements.

You might also like