Asohk.com
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Visual basic.NET for Beginners

Go down

Visual basic.NET for Beginners Empty Visual basic.NET for Beginners

Post  Admin Mon Aug 04, 2008 7:15 am

VB .NET is different! This first lesson tells you why.
We cover a little of the background of Visual Basic at Microsoft is covered and why it was necessary for Microsoft to bring out a completely new product: VB .NET!
But best of all, we talk about how to program VB .NET on the cheap!


Why did they break VB?

Visual Basic is the most successful software language known in the history of the Universe!

That might seem a little over the top ... but it's literally true. We don't know anything about software languages on other planets, but VB is the most successful way to program here on Earth.

This course is designed to introduce beginners to Visual Basic .NET. By "beginners", I mean someone who has some familiarity with programming, but no experience with VB.NET. The goal for this tutorial is VB.NET - not basic programming concepts - so we won't cover "how to program a loop." (But check out our tutorial designed for people who have never written a program at this address!) We will write a basic VB.NET program that doesn't assume that you already know how to write one.

To make this as simple as possible, we start out by showing you how to write VB.NET programs that run "from the Command Prompt" - that is, not in a window. To do this, you don't need the full graphical development tool, Visual Studio (which is bundled with VB.NET). Later on, we show you a pretty sophisticated VB.NET program that also runs at the Command Prompt. Even if you have purchased the full graphical Visual Studio, it's still a good idea to start with Command Prompt applications because you learn more about how VB.NET actually works that way. But since many of you probably signed up for this course to learn how to use the Visual Studio tools, the last segment (lesson 4) concentrates on using Visual Studio.

And one more thing. I make a special effort to cover how to do it "on the cheap". I don't assume that everyone has a corporate budget to buy all of Microsoft's latest software! They don't make it easy ... but there are a few tricks you can use.


Since it was introduced in 1991, more programmers have used Visual Basic than any other way to program. Accurate numbers are difficult to find ... but consider that VB is not only the leading language for professional programmers, but it's a language used in everything from palmtops to server farms, from VBScript to VBA, and its also included in the most popular Office applications like Word, Access and Excel. In fact, hundreds of companies have decided to use Visual Basic as the 'macro language' for their own application software.

Through six major releases, Visual Basic has gained in popularity and power until it reached a crescendo of popularity with Visual Basic 6.0. And just as it did, Microsoft decided to THROW IT ALL AWAY and replace the whole thing with new and different programming language which they decided to call VB.NET! VB.NET is so different from Visual Basic 6.0 that even Microsoft people have been heard to say that it is easier for someone with no background at all in VB 6 to learn VB.NET because they have less to 'unlearn' that way.

Why did they do it?
They had no choice.

VB 6 had become like the dinosaurs that were the most successful animals on Earth for 150 million years, but died out anyway just as the most advanced dinosaurs came onto the scene. Think of VB 6 as being kinda like Tyrannosaurus Rex. (Lots of Java programmers might agree with you and we need all the agreement we can get in software development!)

Microsoft decided that it would be far, far better if they killed their own product with their own even better product than see it get killed by somebody else's better product. And VB 6 was starting to get killed. If you were watching, the future was clear. And nobody has ever accused Microsoft of not watching. (By the way, the official Microsoft position is that they will support, but not upgrade, VB 6 until 2005 - but it seems to me that they're actively undermining VB 6 right now anyway.)

The good news is that Microsoft did it right! VB.NET is an excellent new direction and once you "make it over the hump" and really get the new vision, you'll be glad you did. The goal of this course is to "get you over that hump". Let's get started.

Next page > Stop Bill From Getting More of Your Money!
Admin
Admin
Admin
Admin

Posts : 60
Join date : 2007-12-17

https://asohk.forummotion.com

Back to top Go down

Visual basic.NET for Beginners Empty VB.NET is more .NET than VB

Post  Admin Mon Aug 04, 2008 7:26 am

So the best place to start learning about VB.NET is .NET.

If I had to point to one thing that makes VB.NET different from VB 6, it would be that VB.NET is totally object oriented (OOP) and VB 6 is just object friendly by comparison. In VB.NET, quite literally, everything is an object.
Let's look at just one example of the difference. This is a good example because it shows you the change in the language syntax as well as the change to total object orientation.

In both VB 6 and VB.NET, it's possible to create a Form object (the windows that make up Windows are examples of Form objects) and assign it to another variable. Here's a short VB 6 program which declares two VB 6 objects. Declaring something as an Object means that it can contain any object in VB 6. So let's see if we can assign our Form f to the Object O.

Dim f As Form
Dim o As Object
o = f

But when you run it, you get an error, "Object variable or With block variable not set".

Really clear and understandable error message, isn't it!

What is happening is that VB 6 doesn't treat everything as an object so it tries to assign a property of the Form object (in this case, the controls collection) to the object o. That has never been initialized so you get the error.

If you want it to work in VB 6, you have to code it this way (the changed keyword is displayed in bold).

Dim f As Form
Dim o As Object
Set o = f

Then VB 6 treats the assignment as an object assignment instead of trying to assign the property. ("OH!!!" Says VB 6, "You wanted the form OBJECT assigned, not the PROPERTY! NOW I understand!!!")

In VB.NET, however, everything is an object. It works just fine the obvious and simple way:

Dim f As Form
Dim o As Object
o = f

When you get into .NET, you discover that the rules are a lot more complex and detailed, but they're also more consistent and once you understand them, they make more sense.

The next 'big difference' is that .NET uses a runtime engine (called the CLR, or Common Language Runtime) that is identical for all .NET languages. VB.NET (and other languages) compile to a code that is called IL Code (Intermediate Language) which is then executed by the CLR.

Now ... Some of you might be saying, "Hey! VB has used a runtime module for years. This isn't new."

True. But this one is compatible across all .NET languages (and even has a published interface, the CLI or Common Language Interface, so anyone could write a language for it). It's also been rewritten from the ground up. It has taken the best ideas from the Java JVM (Java Virtual Machine) and made them even better. (Yah! This is Microsoft "extend and embrace" again! But from your point of view as a consumer, it has resulted in a wondeful product!)

This 'total rewrite' - and the switch to complete OOP - made it possible to implement a whole raft of new language elements. At this point, it takes a 600 page text book (there are some great ones reviewed at About Visual Basic) to even start to cover these new language features in detail. Since this is just an introduction, I will only list a few of the more important ones. Many of these have more detailed articles available here at About Visual Basic. Don't worry if some of the concepts are a bit foreign to you. The goal is just to just briefly give you a view of the highlights. You won't have to pass a test.

* Inheritance

This is the key OOP feature that most people point to as the difference between VB 6 and VB.NET. It was not implemented in VB 6. Although it's a convenient shorthand to say "inheritance" is the key new VB.NET feature, in reality, .NET has implemented dozens, maybe hundreds (depending on how you want to count them) of new object oriented features.
* Structured Exception Handling

For error handling, VB 6 has On Error GoTo and ... well ... I guess that's about it, isn't it? But VB.NET has a whole methodology implemented in the tried and proven Try-Catch logic borrowed from the C world. And it also has the On Error GoTo statement but the Microsoft documentation says that using it is a mortal sin.
* Multithreading

This refers to the ability of a single program to execute different processes concurrently. It's a way of speeding up response when you know that one part of a program takes a long time to run but the rest of the program can be executing without waiting for the result. This is a new feature that is mainly provided by the new CLR runtime (the default remains single threading), and there are new VB.NET language elements that must be used to implement it.
* Completely Revised Types

First, the innovative Variant data type introduced by VB is not supported at all in .NET. Microsoft seems to have finally admitted that it wasn't such a good idea after all. And VB.NET supports strong type checking. Standby's like Integer and Long are longer. Arrays are zero based. In general 'Types' are a much bigger deal in .NET than they were in VB 6.
* Memory Management

I can still remember a conversation I had years ago when Java was a new language. "What is this Java?" I asked. The techie I was talking to said, "It's a language that supports garbage collection."

Memory management (or 'garbage collection') is the ability of a language to check whether software objects, like program variables, are still needed and to reclaim the memory they were using if they are not. Although it's possible to do garbage collection in your source code, it's almost always a bad idea because VB.NET just handles the job better than your source code can. And VB 6 doesn't.
* "XCopy" Program Installation

AH! Back to the Future! This is the way we used to do it!

An alternative description of this new feature that you sometimes read is, ".NET eliminates DLL Hell." Due to the way .NET keeps track of program modules, you can install a new system just by copying the files to a folder. But this feature (like many others) is really just one visible result of a more fundamental change. The same feature allows .NET to do automatic version control, side-by-side execution, and generally do a better job of managing the components of your system.
* GDI+ (the new .NET graphics objects)

What can I say in a paragraph? A whole new world. Want to do transparent forms?
* ADO.NET (the new .NET database objects)

Database oriented people like to describe .NET as the system that supports ADO.NET.

Next week, we write some code! And not just any code! We're going to write code using all three of the "cheap" methods that we learned about earlier. Look for it!
Admin
Admin
Admin
Admin

Posts : 60
Join date : 2007-12-17

https://asohk.forummotion.com

Back to top Go down

Visual basic.NET for Beginners Empty VB.NET in Three Acts

Post  Admin Mon Aug 04, 2008 7:44 am

It's popular for books and tutorials to say that they will show you how to build killer software for yourself on your own computer. (Heck! I've even said it!) Creating an application like that is a stretch even for people who have a lot of experience. So we're going to emphasize the opposite. Since this course is advertised as being for Beginners, the applications we will build are designed to be as simple as possible and still get the idea across. In addition, to fulfill my promise of emphasizing "cheap", I'll build one from the command line, one using SharpDevelop, the free development environment, and one using Visual Studio .NET (In our uncomplicated application, there is no difference between Visual Studio .NET Learning Edition that I recommend and the complete (that is, expensive!) version.)


The Command Line VB.NET

DOS"Command line" refers to DOS (Disk Operating System) that used to be the actual operating system (Windows 98 and earlier) and is still available in "emulation" even in the latest Windows versions. The term "command line" (or "Command Prompt" as Microsoft labels it these days) means that you can't just click buttons and menus to do things. Anything you do has to be entered as a one line "command". For example, in Windows, you can drag and drop a file from one folder to another to move it. In DOS, you have to enter a command to MOVE X Y where X and Y are file names.

The example here was developed using Windows XP. DOS can be found in XP by selecting Start > All Programs > Accessories > Command Prompt. In order to use the command line to develop and run a VB.NET program, you must first download (or obtain on CD) the .NET Framework SDK (Software Development Kit). You can get that by going to the Microsoft site here.

Actually using the tools available on the SDK in DOS will require some serious effort to learn how to do! As I said earlier, this method is cheap, not easy. Even Jesse Liberty (in his book Learning Visual Basic .NET) takes the shortcut of using a DOS environment setup by Visual Studio to run command line examples. When the SDK is installed, it creates an environment that should allow you to run the examples here. If you have problems, there is extensive documentation available with the SDK.

Later on, we create what I call the "Two Button Form". But since we don't have buttons for a command line program, we're going to get even more elementary and just read in some characters and then display the same characters. The goal is to break the ice and get started, not to write the most amazing software application ever seen.

After you have downloaded and installed the .NET Framework SDK, open Notepad and type the following program. Save the program as a '.vb' file in a convenient directory. I've used the root directory in my example below but you should probably create a special test directory for these program files to keep your hard drive more organized.

Module Module1
Sub Main()
System.Console.WriteLine ("About VB Example")
System.Console.WriteLine ()
' Prompt user for identifier
Dim ReplyString As String
System.Console.Write("Type A or B: ")
ReplyString = System.Console.ReadLine()
System.Console.Write("You typed: " & ReplyString)
End Sub
End Module

To run this program, enter the command VBC (Visual Basic Compiler) followed by the name of the program. In order for this to work, your computer must be configured so the operating system can 'find' VBC. Ordinarily, the SDK setup program will do this automatically, but if you have difficulty, there are batch files (.BAT) in the SDK that will also do it for you. When all else fails, as a last resort, you might try reading the SDK documentation!

If everything else is correct you can compile and run the program as shown below:
Compile and Run About VB Example

A Module is a basic building block of VB programs and is something of a holdover from VB 6. When we build the next application, you will see that we use a Class instead of a Module and one Class roughly equates to one object. In this example, The VB.NET compiler simply converts the Module to a Class anyway. In this program, we've given the name Module1 to our Module. Also note that the Module is ended at the bottom. VB.NET requires well defined blocks of code.

Unless you specify otherwise, the Sub Main() is the entry point for the program. That is, it's the first procedure that is executed when you run your program. Main is where you would put the code that needs to be run first. Later on, you will see that Visual Studio will often add a parameter to your project to change the first procedure to something else, such as a form. The Sub (short for Subroutine) is carefully ended just like the Module was.

Every other executable statement in the program (the Dim statement just creates a variable and isn't actually an executable) actually uses the services of one of the main objects in VB.NET: the System.Console object. This is a great opportunity to learn about the "holy trinity" of OOP: Encapsulation, Inheritance, and Polymorphism.

Let's look more carefully at the first statement in the program:

System.Console.WriteLine ("About VB Example")

System ObjectVisual Studio provides a tool called the Object Browser that lets you see the relationships between objects. Let's look at the mscorlib Namespace. (You can see a table showing what all the icons in these diagrams mean here.)

All objects in .NET inherit from a single top-of-the-heap object called, naturally, Object. You can see Object in the diagram as an Intrinsic (part of the .NET Foundation) "Bases and Interfaces" class for the Console object.

A number of different Namespaces can be found in the VB.NET library file MSCORLIB.DLL including the System Namespace. The "plus-in-a-box" icon tells you that the two namespaces above System also have other objects in them. The name "MSCORLIB" suggests exactly what it is. It's the Microsoft Core Library for .NET.

The concept of Encapsulation means that you can consider all of the objects as simply "black boxes" that provides services. Console is one of the "black boxes" inside System. Some of the services that Console makes available are actually provided by System but they are Inherited from System by the Console object. As a programmer, however, you only need to know what services the Console object ultimately provides.

WriteLineThe right pane of the Object browser helps you find these services. Here's a view of just the variations of the WriteLine method that are found in the Console object. This brings up the concept of Polymorphism.

Polymorphism isn't a weird religion that worships parrots. It means that the same object can take on many different forms. ("poly" meaning "many" and "morph" meaning "form") Notice that there are eighteen WriteLine methods listed by the object browser but each one has a slightly different parameter list. This is how all of the C family of languages ... and now .NET languages ... tell which WriteLine method your program wants. The number and type (there's that 'strong typing' again) of the arguments passed to a method is called the method signature. The compiler looks at that to determine which method to use even though the name is the same.

This subject gets LOTS more interesting with topics like overriding, shadowing, delegates, interfaces, and subclasses. Enough to make your head spin. For right now, all you really have to know is that objects generally have lots of methods, and that you can select the one you want in code by using different signatures.

WriteLineVisual Studio .NET helps you out with a tool called Intellisense that lets you choose exactly which one of the methods you really want to use. For example, if I entered exactly the same line of code in Visual Studio, I would get the helpful hints shown. Notice that VS.NET also tells me that there are eighteen methods to choose from and helpfully suggests the second one. It even gives me the right values to fill in (the False and True constants). I did say that you got value for money with Visual Studio .NET!
Admin
Admin
Admin
Admin

Posts : 60
Join date : 2007-12-17

https://asohk.forummotion.com

Back to top Go down

Visual basic.NET for Beginners Empty The Sharp Way To Develop Code!

Post  Admin Mon Aug 04, 2008 8:23 am

Reading and writing the same characters in DOS is fun, I guess ... but it does get old kind of quickly, so let's move on to SharpDevelop.

Unfortunately, as of this writing (November 2003), SharpDevelop doesn't really have a Visual Basic Windows Forms based development system. As I said in the first lesson, SharpDevelop is being created by a brave group of Free Software coders taking advantage of the fact that Microsoft has decided that it's in their interest to make the technical foundation of .NET a public standard. The SharpDevelop people are currently putting their effort behind getting their C# version to work really well. In the fairly recent past, they did have some Visual Basic Forms tools working, but rather than pursue a "two track" approach, they decided to put it all back on the shelf and bring out an improved version at some point in the future.

The About Visual Basic site is very interested in making sure that our readers are aware of all the ways they can take advantage of Visual Basic. For that reason, you can find articles at About Visual Basic tracking the progress of SharpDevelop in creating their product. So as soon as something is available, you will find an announcement at About Visual Basic!

The net result of all this is that, at the present time, you can only develop the same command line application in SharpDevelop for VB .NET that you can with the Microsoft SDK. The difference is that you can develop the system in the SharpDevelop graphical environment (even though you can't - yet - use any graphical components in your project). But there is very little difference in the resulting program. Why? Because it uses the same objects from the Microsoft .NET Framework. Every one of the SharpDevelop team members thank Microsoft every morning for Microsoft's fair minded generosity in making all this free code available to them. (Not!)

Even without the VB Forms components, the SharpDevelop system is worth a download just to see what a genuine (and free!) alternative to Microsoft Visual Studio looks like.

SharpDevelop
Visual basic.NET for Beginners Sharpd10
Admin
Admin
Admin
Admin

Posts : 60
Join date : 2007-12-17

https://asohk.forummotion.com

Back to top Go down

Visual basic.NET for Beginners Empty Re: Visual basic.NET for Beginners

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum