Launch your Visual Basic .NET or Visual Studio software.

When the software first loads, you'll see a screen something like this one:

There's a lot happening on the start page. But basically, this is where you can start a new project, or open an existing one. The first Tab, Projects, is selected. At the moment, the area labelled "Open an Existing Project" is blank. This is what you'll see when you run the software for the first time (because you haven't created a project yet). When you create a project, the Name you gave it will be displayed on this page, as a hyperlink. Clicking the link will open the project. At the bottom of the screen, there are two buttons: "New Project" and "Open Project". To get started, click the "New Project" button. When you do, you'll see this dialogue box appear:

Give Your Project Name and Location. Click on ok

In the Visual Basic NET design time environment, the first thing to concentrate on is that strange, big square in the top left. That's called a form. It's actually the pretty bit of your programme, the part that others will see when they launch your masterpiece. Granted, it doesn't look too attractive at the moment, but you'll soon discover ways to lick it into shape. To run the form, try this: • • • • From the menu bar, click Debug From the drop down menu, click Start Alternatively, press the F5 key on your keyboard Your programme is launched

Congratulations! You have now created your very first programme. It should look like this:

Click the Red X on the form to stop it from running. You will then be returned to the software environment. If you compare the first form with the one above, you'll see that they look very similar. But the one above is actually a real programme, something you could package and sell to unsuspecting village idiots So what's going on? Why the two different views? Well, Visual Basic has two distinct environments, a Design environment and a Debug environment. Design Time is where you get to play about with the form, spruce it up, add textboxes, and buttons, and labels (and code, of course ); Debug is where you can test your programme and see how well it performs. Or doesn't perform, as is usually the case. But don't worry about the terminology, for the time being. Just be aware that there's a two step process to VB programming: designing and debugging. So, let's get on and do some designing! Before we can start designing a form, though, we need some tools. And where are tools kept? In a toolbox!

Things like buttons, textboxes, and labels are all things that you can add to your Forms. They are know and are kept in the Toolbox for ease of use.

The Toolbox can be found on the left of the screen. In the picture below, you can see the toolbox icon n Form1:

To display all the tools, move your mouse over the toolbox icon. You'll see the following automatically a

There are seven categories of tools available. The toolbox you'll be working with first is the Common Co toolbox. To see the tools, click on the plus symbol next to Common Controls. You'll see a long list of t

Let's start by adding a textbox to our form. we'll only be using the TextBox and the Label. With the tools displayed. click the Pin icon next to the X.As you can see. there are an awful lot of tools to choose from! For this first section. simply m mouse away. If you want to keep the toolbox displayed. To close the toolbox. do the following: • • • Locate the TextBox tool Double click the icon A textbox is added to your form .

Play around with the sizing handles until you're happy with the size of your textbox. • Create two more textboxes by double clicking on the textbox icon in the toolbar (Or Right-click on the selected textbox and choose Copy. The mouse pointer turns into an extended line with arrowheads. hold your mouse over the textbox and drag to a new position: Notice the small squares around the textbox. If it's only going to contain one line of text. The reason why you can't make it any higher is because the default action of a textbox is to have it contain only a single line of text. Move your mouse over one of them.The textbox gets added to the top left position of your form. Or press F5 on your keyboard: . there's no reason why you should be able to change its height. You'll see how to do this soon. The textbox is resized. Then Right-click on the Form and choose Paste.) • Resize them to the same size as your first one • Line them up one below the other with space in between • Try to create something that looks like the one below To see what your Form looks like as a programme. Hold your left mouse button down and drag outwards. A textbox can only be made higher if it's set to contain multiple lines of text. To move it down. but you can make it wider. Microsoft reasoned. One thing you will notice is that you can't make the size any higher. click Debug > Start from the menu bar. These are sizing handles.

as in the image below • . Click Debug > Stop Debugging from the menu bar 3. Click the Red X at the top right of your Form 2. you can do one of the following: 1. Press Shift + F5 on your keyboard You can also click the Stop button on the VB toolbars at the top.To stop the programme from running.

You've probably noticed the area to the right of the design environment. The form should have the little sizing handles now. somewhere on the form's grey areas. Click anywhere on the form that is not a label or a textbox. That's the Properties box. "AccessibleName". the one that has those daunting names like "AccessibleDescription". "AccessibleRole". On the right of the design environment there should be the following Properties box: . indicating that the form is selected. the area with all the textboxes in a grid.

let's clear up what we mean by "Property". Image. First. BackColor. are called control objects. and can be changed. We're going to change the value of the Text property. No more reading these lessons online . and the form itself. Text. These values are the default values.get the eBook here! What is a Property? Those controls you added to the form (textboxes and labels). as in the image below: This will make the properties easier to find. Click away from the textbox or label until the Properties box reads "Form1 Form" What you are looking at is a list of the properties that a form has: Name . something solid that you can pick up and move about. You can display the list properties alphabetically. Controls (things) have properties. you might want to display the list of Properties in a more accessible form. Font. etc. You can think of controls as things.If your Properties box says "Textbox1 Textbox" or "Label1 Label" then you haven't yet selected the Form. Just to the right of these properties are the values for them. click the Alphabetic icon at the top of the Properties box. If your television . Before we change any in the Properties box. To do that.

The volume property could have a range of values. We'll change only one of these values for now . as in the image below "Text" is a Property of Form1. The properties of your television will have values. and a . we can see how to change them using the Properties Box. This is the default. what other properties would your television have? Think about it. well. and delete the word "Form1" by hitting the backspace key on your keyboard • When "Form1" has been deleted.. then you'd probably have some very angry neighbours! In VB. If the value of the volume property was set to ten. So.NET. do this: • Click inside the area next to "Text". To change this to something of your own. do this: • Locate the word "Text" in the Property box. the loudest value. The On/Off button would have just two values . and the properties and values it has.) If we go back to our Form object. (You can also change a property using code. a volume property.the value of the Text property . which you'll do quite a lot. from zero to ten. it too would have properties: an On/Off button property. type the words "My First Form" .On or Off..were a control. a colour property. Don't be confused by the word "Form1" next to the word "Text". for example. All this means is that the current value of the Text property is set to the word "Form1". you can change a property of a control from the Properties Box.

circled below: When you click Show All Files."My First Project").) The Solution Explorer shows you all the files you have in your project (Notice that the name of your project is at the top of the tree . But click the Show All Files icon. At first glance.• Click back on the form itself (the one with the labels and textboxes). click View > Solution Explorer. the Solution Explorer will look something like this: . or hit the return key on your keyboard • The words "My First Form" will appear as white text on a blue background at the top of the form If you have a look in the top right of the Design Environment. it looks as though there are not many files in the project. (If you can't see it. you'll see the Solution Explorer.

VARIABLES: Why are we discussing variables? And what is a variable? With Visual Basic. you are saving all these files. To actually save your work as you go along. If you save often then you won't lose any of your work if anything goes wrong with your computer. But you can't do this without variables. and most programming languages. click File > Save All and you'll see the following dialogue box (we've chopped ours down a bit): The files are usually saved in the My Document folder in XP (Document folder in Vista). Or press Ctrl + Shift + S on your keyboard. If you want to save your projects elsewhere.When you save your project. Or click the icon in the Toolbar (the stack of floppy disks). click the Browse button. what you are doing is storing things in the computer's memory. under Visual Studio. you put the numbers into storage areas and "tell" Visual Basic to add them up. and manipulating this store. just click File > Save All from the menu bar. To save your work. If you want to add two numbers together. .

It's VB's way of setting up (or declaring) variables. Think of it like this: a variable is an empty cardboard box. . Each empty cardboard box is a single variable. but click only once • Move your mouse to a blank area of your form . put a sticky label on each of the two boxes. What have we just done? Well. To add two numbers together. We've also given each of these variables a name (the sticky labels) so that we can remember where they are. Now. we'll explore another way to do it.labels. we've created a large memory area (the room and the cardboard boxes). write the first number on a piece of paper and put the piece of paper into an empty box. With your Form displayed in the Visual Basic Design environment. Write the second number on a piece of paper and put this second piece of paper in a different cardboard box. do the following: • Click on the Button tool in the toolbox with the left hand mouse button. Buttons.So a variable is a storage area of the computer's memory. and "number2" on the second label. To help you remember which of the thousands of boxes hold your numbers. and we've set up two of the boxes to hold our numbers (two variables). out of all your thousands of empty cardboard boxes two of them contain pieces of paper with numbers on them. Write "number1" on the first sticky label. etc. Now. Now examine this: Dim number1 As Integer Dim number 2 As Integer number1 = 3 number2 = 5 That's code from Visual Basic Net. and in this room you have a whole lot of empty cardboard boxes. imagine you have a very large room. ADDING A BUTTON AND UNDERSTANDING EVENTS: Instead of double clicking the Button tool in the toolbox to add the control to the form. textboxes.the mouse pointer will turn into a cross • Press and hold down the left mouse button • Drag across the form with the button held down • Let go of the mouse button when you're happy with the size • A Button is drawn You can use the above method to draw most of the controls onto the form .

double click your Button control. At the moment. in exactly the same way as we changed the Font property of the Label and Textbox previously. here. • • • • • • Click on the Button to highlight it Click on Text in the Property Box Click in the box next to the word "Text" Delete the word "Button 1" Type "Add two numbers" Click back on the Form Now add a Textbox to your form using one of the methods outlined (either doubleclick. has a list of properties. The code window will appear. just like all the other controls we've seen so far. You can change that to anything you like. your button will say "Button 1". Your Form should now look something like this: The Font property of the Button has also been changed. and will look like this: . To get our first look at the code window. or draw).The Button control. The Text for the Textbox control has had its default Text (Textbox 1) deleted. One of these properties is the Text property.

the Name property of the control is the important one. Private Sub Button1_Click(ByVal sender As System. etc. and the code we're going to write will be executed End Sub Click your mouse on the blank line after Private Sub Button1_Click. Notice.EventArgs) _ Handles Button1. too. too. and that it needs to be executed This is the name of our button. You can do this in your own code. The "Sub" word tells VB that some code follows. _ ByVal e As System. if it becomes to long: Private Private means that no other part of the programme can see this code except for our button Sub Button1 Short for Subroutine. that the underscore character ( _ ) has been used to spread the code over more than one line. if it becomes to long. VB will change this button name for you _Click ( ) This is something called an Event. If you change the Name property.Notice that we've used the underscore character ( _ ) to spread the code over more than one line. But you don't have to. so why does VB insist that it's still called Button1? We'll. In other words. You can do this in your own code.Object. but before End Sub. your code window should now look like this: . You might think that we've just erased the word "Button1" when we changed the Text property. too. the Click Event will fire.Click End Sub The part of the code we're interested in is highlighted in red in the code above. Type the following code: Dim number1 As Integer Dim number 2 As Integer Dim answer As Integer number1 = 3 number2 = 5 answer = number1 + number2 MsgBox answer After typing all that. when the button is clicked.

Click the Button once.Before we explore what's happening here. as in the image below: Click the "Form1. save your work and then click Debug > Start from the Visual Basic Menu.vb [Design]" tab to see your Form. and you should get the following: Stop your programming. This will launch your programme. . you can click the Tabs at the top of the Window. and return to the Design Environment. or press F5 on your keyboard. If you can't see your code.

The final part of the programme used Visual Basic's in-built Message Box. We said to Visual Basic "When you've finished adding up the two variables number1 and number2. Then store the result in the variable called answer. indicating to Visual Basic that we wanted to set up a variable • Then we gave the variable a name (number1) • Next. mathematical way . It's sees the 3.OK. the whole line answer = number1 + number2 means: "Add the variable called number1 to the variable called number2. What Visual Basic will do is to look at what we've stored inside number1. Then Visual basic adds them up for you. and what is going into the second variable was the number 5. You are assigning the value of 3 to the variable called number1 number1 = 3 number2 = 5 The next part is a little bit more complicated. What we wanted to do was to add two numbers together.with the plus sign (+). what happened there? Well." Think of it as working from the right-hand side of the equals sign first. We do the "telling" in the traditional. For now. and look at what's inside number2. Then when you have the answer. store the result in that other variable we set up. here's what we did: • Told Visual Basic that what is going into the first variable was the number 3. we started with the Dim word." So. We'll learn a more about the Message Box later. we "told" VB that what is going inside the variable is a number (As Integer) • Two more variable were set up in the same way. and also sees the plus sign. So we said number1 + number2 Visual Basic already knows how to add up: all we need to do is "tell" it to add up. sees the five. number2 and answer After setting up the three variables. . and we displayed the result by using a Message Box you very first real programme! But let's break that code down a little more. think of it as a handy way to display results. but not too complicated. you use the equals ( = ) sign. assign it the variable on the left of the equals sign. Except we also did something else. • First. To put something into a variable. which is called answer. But it's not really an equals sign . what happened is we've just wrote a programme to add two numbers together.it's an assignment operator.

So delete the line: MsgBox answer. we're setting the property with our code.Message boxes are quite handy when you want to display the result of some code. Here. To set a value.) The Text property you have chosen is the same Text property that you set from the Properties Window earlier. then type a value for the Text property. type an equals sign. We want the contents of the variable called answer to appear in the textbox. (This drop-down box is known as IntelliSense. Double click the Text property and the drop-down box will disappear. It means you can just select a property or method from the list without having to type anything. and is very handy. before. we set it at design time. then type a full stop. But we have a textbox on the form. and we might as well use that. Scroll down until you see the word "Text". But the result is the same .Text = answer Your code window should then look like this: . Type the word Textbox1. This is a list of the Properties and Methods that the Textbox can use. So the rest of the code is just this: Textbox1.the Text property of the textbox will be set to a value of our choosing. You should see a drop-down box appear.

and press the Button on the form. String Concatenation: FullName = FirstName & " " & LastName & -> used for string concatenation. Syntax For If: If Condition then Statement End if Ex: If firstname = Bill Then MsgBox "firstname is Bill" End If Syntax for if – else: If Condition then Statement Else End if Statement Example: . You should see the number 8 appear in the textbox.Run your code again.

Or click once with the left hand mouse button. The user can then select one of these options.If firstname = "Bill" Then MsgBox "firstname is Bill" Else MsgBox "firstname is not Bill" End If Example for Select: Dim creamcake As String Dim DietState As String creamcake = TextBox1. . a drop down list of items appears.Text Select Case creamcake Case "Eaten" DietState = "Diet Ruined" Case "Not Eaten" DietState = "Diet Not Ruined" Case Else DietState = "Didn't check" End Select Create a new project for this section. Then. locate the Combo Box on the Visual Basic . So let's set it up to do that. It looks like this: Double click the icon to add a Combo Box to your form. and then draw one on the form. Add a button to your new form.NET toolbar. When a black downpointing arrow is clicked. A combo box is a way to limit the choices your user will have.

Then locate the Item property from the Properties Box: • Click the grey button. The one with the three dots in it. as above. as in the image below: .• Click on your Combo Box to select it.) • Enter five items. you'll get the following box popping up: • To use the String Collection Editor. When you do. type an item and press Return (it's just like a normal textbox. Each item will be one item in your drop-down box.

less than. You should have something like this: Conditional Operators: The Conditional Operators allow you to refine what you are testing for. Instead of saying "If X is equal t specify whether it's greater than. and a whole lot more. The Editor will close. Examine the list of Operators: Operator Meaning .• Then click the OK button at the bottom. run your programme and test out your new Combo Box. and it will look like nothing has happened. However.

and are used like this: If number <= 10 Then MsgBox "The Number was 10 or Less" End If And You can combine the logical operators with the word And. Like this: If number > 5 Or number < 15 Then MsgBox "Greater than 5 Or Less than 15" End If . Like this: If number > 5 And number < 15 Then MsgBox "Greater than 5 And Less than 15" End If Or You can combine the logical operators with the word Or.> This symbol means Is Greater Than and is used like this: If number > 10 Then MsgBox "The Number was Greater Than 10" End If < This symbol means Is Less Than and is used like this: If number <10 Then MsgBox "The Number was Less Than 10" End If >= These symbols mean Is Greater Than or Equal to. and are used like this: If number >= 10 Then MsgBox "The Number was 10 or Greater" End If <= These symbols mean Is Less Than or Equal to.

<> These symbols mean Is Not Equal to. and are used like this: If number1 <> number2 Then MsgBox "number1 is not equal to number2" End If Loops: Dim answer As Integer Dim startNumber As Integer answer = 0 For startNumber = 1 To 4 answer = answer + startNumber Next startNumber MsgBox answer Do – While: Dim number as Integer number = 1 Do While number < 5 MsgBox number number = number + 1 Loop Do Loop: Do Until number < 5 MsgBox number number = number + 1 Loop Menus: .

You'll see this: This is the control itself. The MenuItem object is the one at the top of the form . click inside the area that says "Type Here". To your new form. But there are lots of properties for the MenuItem object. At the top of your form. To start building your menu. There are many properties for the control.The one that says Type Here. When you do. use the toolbox to add a MenuStrip control: Double click the control to add one to your form. you'll see this: We'll see how to construct our menu soon. If you click on this (it's highlighted above). on the left. But notice the other things that gets added to your project. Examine the bottom of your screen.Start a new project. you'll notice two things. Type the word File: . you'll see that the Properties box on the right changes.

It should look like this: The final item we'll add to our menu is an "Exit" item. type the minus character "-" (in between the "0" key and the "+/=" key on your keyboard). Your menu will look like this: To create items on your File menu. Instead of typing a letter. When you hit your return key. Your menu will then look like this: Add an "Open" and a "Save" item to your menu in the same way. click inside the blue "Type Here" box. Enter the word New. To add a separator.Now press the enter key on your keyboard. But you can add a separator between the "Save" and "Exit". and press the enter key on your keyboard again. you'll see the separator appear: . click inside the Type Here box.

you learned how to add Sub Menus to your VB . you'll see how to add shortcuts to your menu items Underline Shortcut To add an underline. But it does look quite good. Very professional! This tutorial assumes that you have completed the first one.Click inside the "Type Here" area. do this: .NET forms. Run your programme. Click back on your form. away from the menu. In this part. so nothing will happen if you click an item on the menu. Click the File menu. We haven't added any code to the menu yet. You should now have a File menu like this one: To see what your menu look like. to finish off. In the previous tutorial. and add an Exit (or Quit) item.

NET and C#.• • • Click on your New menu item once.NET. you first hold down the Alt key on your keyboard. the "S" of Save. Add underlines for the "F" of you File menu. and the "X" of Exit. To use the underline shortcuts on menus. the "O" of Open. Then type the underline character. . your menu should look like this one: Time to see if your shortcut works. When you're done. OBJECT ORIENTED CONCEPTS The following paragraphs explain OOPS concepts in VB. If you want an underline shortcut. Run your programme. This will select it Position your cursor before the "N" of New Type an ampersand symbol (&) • • Hit the return key on your keyboard You should see this: Notice that "N" of New is now underlined. the ampersand character should be typed before the letter you want underlined.

1) Class: It is template It is designed at design time Ex: paper work (drawing of building plan on paper by civil engineers) 2) Object: Object can be defined as real entity. ·Private: Allows access to the class member only in the same class. Which occupy some memory and with have life Ex: constructed building on the basis of paper plan by civil engineers Class: Template No memory No life Physical entity Object: It has life It has memory It design at run time 3) Access keyword in oops (. . ·Protected: Allows access to the class member only within the same class and from inherited classes.net) Access keywords Access keywords define the access to class members from the same class and from other classes. The most common access keywords are: ·Public: Allows access to the class member from any other class.

Public Imports system Public class class1 Public i as integer Public function raghu () as integer Console.raghu () End class Output=10 Reason: Allows access to the class member from any other class. Private: .writeline (i) End function End class Public class class2 Shared sub main () Dim a as sub class1 a.i=10 a. ·Static: Indicates that the member can be called without first instantiating the class. from inherited classes. and other classes in the same assembly. ·Protected internal: Allows access to the class member only within the same class.·Internal: Allows access to the class member only in the same assembly.

Imports system Public class class1 Private i as integer Public function raghu () as integer Console.i=10 . Conclusion Public class class1 Private i as integer Public function raghu () as integer Console.writeline (i) End function Shared sub main() Dim a as new class1 a.i=10 a.writeline (i) End function End class Public class class2 Shared sub main () Dim a as sub class1 a.raghu() End class Out put: error Reason: Allows access to the class member only in the same class.

raghu () End class Output=error Reason: Allows access to the class member only within the same class and from inherited classes.i=10 a.writeline (i) End function End class Public class class2 Shared sub main () Dim a as sub class1 a.raghu () End sub End class Output:10 Protected: Imports system Public class class1 Protected i as integer Public function raghu () as integer Console. .a.

writeline (i) End function End class Public class class2 Shared sub main () Dim a as sub class1 a.raghu () End class Ouput: 10 Friend: Imports system Public class class1 friend i as integer public sub hello() Console.writeline (i) end sub End class Public class class2 Shared sub main () .Conclusion: Imports system Public class class1 Protected i as integer=10 Public function raghu () as integer Console.

i=10 a.i=10 a.hello () End sub End class output:10 .hello() End sub End class Ouput: 10 Reason: Allows access to the class member only in the same assembly. Protected friend: Imports system Public class class1 protected friend i as integer public sub hello() Console.writeline (i) end sub End class Public class class2 Shared sub main () Dim a as new class1 () a.Dim a as new class1 () a.

from inherited classes. 1) Load into memory once (we can save memory) 2) Instance not required Constructor: It is a method It name same as a class (in c#. and other classes in the same assembly Static: Indicates that the member can be called without first instantiating the class.Reason: Allows access to the class member only within the same class.net it is declared as sub new () In wont return any value see for program Imports system Public class class1 Private i as integer Public sub new () Console.writeline (i) End sub End class Public class class2 Shared sub main () Dim a as new class1 . c++) In vb.

End sub End class Output :0 Reason: default: it will take 0 please see this example Imports system Public class class1 Private i as integer=10 Public sub new () Console.writeline (i) End sub End class Public class class2 Shared sub main () Dim a as new class1 End sub End class output=10 However our .net support two types of constructor 1) Shared 2) Instant .

Shared: 1) It won’t accept any parameter 2) So it can’t be overloaded Instant: 1) It accept parameter 2) So it can be overloaded Note: One constructor can be called from other constructor that can be done in vb.new () Example: Imports system Public class class1 Public sub new () Console.writeline ("hai") End sub Public sub new (i as integer) Console.net myclass.writeline (i) End sub End class Public class class2 Shared sub main () Dim a as new class1 (10) End sub End class Output=10 .

Reason: because of when passing arguments from object only parameter constructor Will be called Note : if u want to display two constructor values Let us see: Imports system Public class class1 Public sub new () Console.new () Console.writeline ("hai") End sub Public sub new (i as integer) Myclass.writeline (i) End sub End class Public class class2 Shared sub main () Dim a as new class1 (10) End sub End class Output: Hai 10 Let us consider example .

writeline (i) End sub Shared sub new () Console.writeline ("hai") End sub Public sub new (i as integer) Myclass.writeline (“this is raghu”) End sub End class Public class class2 Shared sub main () Dim a as new class1 (10) End sub End class Output: This is raghu Hai 10 Reason: Because of shared constructor will be called first when object is created Overloading of constructor () .new () Console.Imports system Public class class1 Public sub new () Console.

new (“raghu”) Console.writeline ("this is raghu”) End sub Public sub new (i as integer) Myclass.writeline (i) End sub End class Public class class2 Shared sub main () Dim a as new class1 (10) End sub End class Output: This is raghu 10 Calling of methods while creating one object with help of constructor: Imports system Public class class1 Public sub new () Console.Imports system Public class class1 Public sub new (j as string) Console.writeline ("this is raghu") .

writeline ("this is raghu1") End sub End class Public class class3: inherits class2 Public sub new () Console.End sub End class Public class class2: inherits class1 Public sub new () Console.writeline ("this is raghu2") End sub End class Public class class4 Shared sub main () Dim a as new class3 () End sub End class Output: This is raghu This is raghu1 This is raghu2 Conclusion: when ever object is created constructor will be called first class &structures Class: it will take help of heap memory .

writeline (“this is placid man”) End sub End class .It is reference type It can inheritable It can be over loadable Structures: It will take help of stack memory It is value type It can’t be inheritable It can't be over loadable Inheritance: Inheritance in a beautiful concept supported by oops (.net) Mainly usage of: 1) Reusability 2) Data redundancy Example: Imports system Public class class1 Public sub raghu () Console.writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Public sub raghu1 Console.

Public class class2 Shared sub main () Dim a as new class2 () a.writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Public sub raghu1 () Console.raghu1 () a.raghu1 () a.raghu () End sub End class Output: This is raghu This is placid man When ever taking about inheritance so many topics Like: 1) Overriding 2) Overload able 3) Dynamic dispatcher Let us consider below example When a make super class reference is pointing to sub class object then super class methods will be called But not sub class Let us see with example: Imports system Public class class1 Public sub raghu () Console.raghu() End sub End class Output: error .writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as class1=new class2 () a.

writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Public sub raghu () Console.raghu () End sub End class .writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as class1=new class2 () a.writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Public sub raghu1 () Console.Above error can be resolved like as fallow: Imports system Public class class1 Public sub raghu () Console.writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as class1=new class2 () a.net use key word override able.raghu () End sub End class Output: This is raghu: When a super class reference is pointing to sub class object and if a method is designed in both classes In this scenario to get the sub class implementation the sub class can override super class method To override super class method super class method should be given as a virtual method To declare virtual methods in the vb. while overriding in the subclass Use keyword in the sub class override Note: 1) to stop overriding use shadows 2) To stop inheritance use keyword not inheritable (final in java) Let us see example: Imports system Public class class1 Public sub raghu () Console.

raghu() End sub End class Output: This is placid man With help of overridable overrides Imports system Public class class1 Public overridable sub raghu () Console.raghu () End sub End class Output This is raghu Imports system Public class class1 Public sub raghu () Console.writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as new class2 () a.writeline (“this is raghu”) End sub End class .Output: there is a conflict of same method names of “raghu” Use keyword like “shadows” With help of shadows: Imports system Public class class1 Public sub raghu () Console.writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Shadows Public sub raghu () Console.writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as class1=new class2 () a.writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Public sub raghu () Console.

NET.writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as new class2 () a.raghu () End sub End class Output: This is raghu This is placid man Abstraction Abstraction can be defined the way of representing of a class or method with out any background.raghu () Console.writeline (“this is placid man") End sub End class Public class class3 Shared sub main () Dim a as new class2 () a.methodname) Imports system Public class class1 Public overridable sub raghu () Console.Public class class2: inherits class1 Public overrides sub raghu () Console. the class declaration should be done as: Must inherit class class1 Abstract and interfaces Abstract: 1)It allow two methods a) Concrete methods b) Non concrete methods .raghu () End sub End class Output: This is placid man Suppose we want to display super class member with help of (mybase. Or without any explanation To create an abstract class in VB.writeline (“this is raghu”) End sub End class Public class class2: inherits class1 Public overrides sub raghu () Mybase.

raghu ("raghu Nethikunta") Username () End sub End class Conclusion: 1) In my above program I have 2absrtact methods setname ().raghu Name=person name End sub Function setname () as string implements in1. raghu () 2)Interface cannot be private 3)By default it is public 4)In interface body don’t use access keyword for methods.setname Console.writeline (name) End function End class Public class class2 Shared sub main () Dim a as new class1 () a. functions Late Binding: Everything is resolved at runtime is called as late binding But vb support only early binding Let us see for program better to understand: Option strict off .2) Not possible to create object for abstract classes 3) It can inherited Interfaces: 1) By default interfaces are public 2) Same as class but except in methods should be abstract 3)And variable should be final 4)It can inherited See for example: Imports system Public interface in1 Function setname () as string Sub raghu (person name as string) End interface Public class class1 Implements in1 Dim name as string Sub raghu (person name as string) implements in1.

net complier throw a beautiful error So take care of option strict while programming for late binding Pass by (Val.raghu() End sub Shared sub main () Dim a as new class1 () Dim b as new class2 () Display (a) Display (b) End sub End class Output: This is raghu This is placid man Conclusion: If use option strict is on our vb. Ref. } static void Main () { Int j=10.writeline ("this is raghu") End sub End class Public class class2 Public sub raghu () Console.writeline ("this is placid man") End sub End class Public class class3 Public shared sub Display (o as object) o. .WriteLine (i). Out) Pass by Val using System.Imports system Public class class1 Public sub raghu () Console. Console. class1 a =new class1(). Public class class1 { public void hello (int i) { i=i+1.

class1 a =new class1 (). Console. a. } .WriteLine (i).WriteLine (i). hello (ref j). } } Output: 11 11 Reason: arguments. Console. parameters both are pointing to same location Pass byout: using System. Console. Console.WriteLine (j). a. } static void Main () { Int j=10.WriteLine (j). Public class class1 { public void hello (out int i) { i=i+1. parameters both are pointing to different location Pass by ref using System. } static void Main () { Int j=10. } } Output: 11 10 Reason: arguments. hello (ref j). class1 a =new class1 (). Console.a. hello (j).WriteLine (j). Public class class1 { public void hello (ref int i) { i=i+1.

class1 a =new class1 (). Console. } static void Main () { Int j=10. Console. hello (ref j).} output: error: Reason: 1)it never accepts any input parameters 2)So it will act as pass by ref (but it not accepts any input parameters) Let us check: using System.WriteLine (i). Public class class1 { public void hello (out int i) { i=100 i=i+1. } } output: 101 101 . a.WriteLine (j).

Sign up to vote on this title
UsefulNot useful