Visual Basic .NET 2010 Express a From the Ground Up Tutorial

download Visual Basic .NET 2010 Express a From the Ground Up Tutorial

of 12

Transcript of Visual Basic .NET 2010 Express a From the Ground Up Tutorial

  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    1/12

    Visual Basic .NET 2010 Express -A "From the

    Ground Up" Tutorial

    Part 1: Introducing this Tutorial

    What's this course all about?

    Microsoft has made it as easy as they can for you to learn .NET by giving away a really great

    Visual Studio based development system absolutely free: Visual Basic .NET 2010 Express

    Edition. Really. It's actually free. No strings!

    VB.NET 2010 Express is really a free version of Visual Studio 2010, Microsoft's premier

    development environment. In this lesson, you learn what it is, how to get it, and how to get

    started by writing a program.

    No textbook is required. Later lessons feature downloadable example programs to help you

    learn. When you install VB.NET 2010 Express, the first screen you see will look like this:

    Because VB.NET Express is a version of Visual Studio, just about any book about Visual Studio will

    also apply to VB.NET Express to some degree, so use your Visual Studio books if you have them and if

    they apply to Visual Basic.

  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    2/12

    All you have to do is download Visual Basic Express from Microsoft and start learning.

    This course is also a living document. I plan to update it and extend it frequently to keep it

    current and add more content. If you have any suggestions about something that should be

    changed or added, let me know about it.

    The current contents of the tutorial are as follows:

    Part 1 - A "From the Ground Up" Tutorial- An introduction to the course.

    Part 2 - Visual Basic Fundamentals- The basics of the VB Language and How To Find More

    Information.

    Part 3 - About Programming- Software systems and the Systems Development Life Cycle.

    Part 4 - What's New With Visual Basic .NET Express- Special emphasis on VB.NET 2010.

    Part 5 - The .NET Framework and Objects- How the Framework and Objects fit into VB.NET.

    Part 6 - Objects in Detail- More objects and version 1 of the Signature Block program.

    Part 7 - Using Data and Serializing to Files- Intro to ADO.NET, and Using Serialization in

    Version 2 of the Signature Block program.

    Part 8 - Using XML- Introduces the use of XML in VB.NET.

    Part 9 - Programming Logic and System Architecture- Systems: From the CPU Chip to

    Networks.

    Part 10 - Collections of Things- How to use Arrays, Collections, Stacks and Queues.

    Part 11 - Errors: Preventing and Handling Them- Built-In Error Prevention and Structured

    Error Handling

    We'll take it slow in thisfirst lesson,but we willwrite a program - probably the most basic

    program that it's possible to write. Since we're just getting started, I don't want to leave

    anybody behind. In later lessons, the pace will pick up quite a bit.

    The really good news is that Visual Basic .NET 2010 Express Edition is a great learning tool

    even if you buy Visual Studio eventually. It's based on exactlythe same Framework 4 thatthe (much, much) more expensive versions are. (If you're into version numbering, this is

    version 10.0 of Visual Basic.)

    I do a lot of development using VB Express and I can give you my personal assurance that it's

    a first class development system with most of the features of Visual Studio versions that

    Microsoft sells for thousands of US dollars. My advice: Take advantage of Microsoft and use

    VB.NET 2010 Express. Buy the more expensive Visual Studio 2010 version onlywhen you

    absolutely have to.

    (About Visual Basicis totally independent of Microsoft and as far as I'm concerned, Bill hasenough money.)

    http://visualbasic.about.com/od/learnvbnet/a/LVBE_L1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L4.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L4.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L5.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L5.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L6.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L6.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L7.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L7.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L8.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L8.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L9.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L9.htmhttp://visualbasic.about.com/od/learnvsnet/a/blecvbnet20101.htmhttp://visualbasic.about.com/od/learnvsnet/a/blecvbnet20101.htmhttp://visualbasic.about.com/od/learnvsnet/a/blecvbnet20101.htmhttp://visualbasic.about.com/od/learnvsnet/a/blecvbnet20101.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L9.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L8.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L7.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L6.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L5.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L4.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L1.htm
  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    3/12

    As a beginners course in programming, the next lesson has a brief summary of the

    fundamentals.About Visual Basicfeatures more advanced articles on the site but this course

    will make a special effort not to leave beginners and students behind.

    Where did Visual Basic come from?

    Visual Basic was invented by Microsoft, but it's based on an early language called BASIC

    invented by Dartmouth College professors John G. Kemeny and Thomas E. Kurtz in 1964.

    Since C was invented almost ten years later, BASIC is one of the earliest computer languages.Every version of BASIC has been a revolutionary event in programming from the very

    beginning. In fact, the version of BASIC created by Microsoft foundersBill Gatesand Paul

    Allen in February 1975 has an excellent claim to being the very firstpersonal computer

    language. The first version was written in the native machine language of a machine that

    many consider to be the very firstPC, the MITS Altair 8800. Since the first PC version was

    written directly inmachine language,nothing else came before it, not even an assembler

    language.

    The first version of Visual Basiccame out in May of 1991. It was revolutionary because

    everyone could create Windows programs easily and quickly for the first time. Before VisualBasic, Windows programs were usually written using the complicated syntax of C++ and the

    even more complicated requirements of Windows. It was a tricky job for even the most

    experienced programmers. But Visual Basic opened Windows programming for everyone.

    That made it a key part of the amazing early success of Windows. People who didn't live

    through this era often don't understand that IBM and OS/2 had nearly all the money, most

    of the customers, andthey made the computers. They had it all! Microsoft was a tiny,

    insignificant upstart by comparison. The programming universe was literally turned upside

    down when Windows and Visual Basic became the most successful software system in the

    world up to that time.

    I didlive through it and as I write these words, it's even hard for me to believe just how

    amazing that time was.

    But Microsoft has never been a company that let history happen to them. They have always

    made their own history. In February 2002, Microsoft made a 300 billion dollarbet on a

    totally new technology base for their entirecompany. They called it .NET. Bill Gates, who

    usually says what he means, called .NET a "bet the company" move. If .NET had flopped, it

    probably would have been all over for Microsoft.

    On the next page, we zero in on .NET and VB.NET 2010!

    VB.NET - A Microsoft "Flagship" Language

    Visual Basic has always been a flagship language for Microsoft and this didn't change when

    .NET came out.Visual Basicremained a featured language for Microsoft development in the

    new .NET world. Two new languages, J# and C# were announced at the same time but one

    of those hasn't survived. In January 2007, J# was officially "retired". But another new

    language called F# has been added.

    So .NET is a growing, changing environment.

    There is also a .NET version of C++. The versions before Visual Studio 2010 didn't get good

    reviews. Many programmers continued to use the last version published before .NET,

    Version 6. The new 2010 version looks much better. In fact, the C++ team has been using the

    slogan, "10 is the new 6" to emphasize their belief that it's now time to move up.

    http://office.about.com/od/Productivity/fl/Productivity-Quotes-by-Bill-Gates.htmhttp://office.about.com/od/Productivity/fl/Productivity-Quotes-by-Bill-Gates.htmhttp://office.about.com/od/Productivity/fl/Productivity-Quotes-by-Bill-Gates.htmhttp://linux.about.com/cs/linux101/g/machinelanguage.htmhttp://linux.about.com/cs/linux101/g/machinelanguage.htmhttp://linux.about.com/cs/linux101/g/machinelanguage.htmhttp://visualbasic.about.com/od/vbnetspecialtopics/a/aboutvb.htmhttp://visualbasic.about.com/od/vbnetspecialtopics/a/aboutvb.htmhttp://visualbasic.about.com/od/vbnetspecialtopics/a/aboutvb.htmhttp://visualbasic.about.com/od/vbnetspecialtopics/a/aboutvb.htmhttp://linux.about.com/cs/linux101/g/machinelanguage.htmhttp://office.about.com/od/Productivity/fl/Productivity-Quotes-by-Bill-Gates.htm
  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    4/12

    When you write a program in any .NET "managed code" language, the .NET Framework does

    most of the work. Visual Basic, and every other .NET language, is just the skin on top of .NET.

    Once you learn .NET, switching to another language syntax is a lot easier. The really

    important things don't change. In fact, with Visual Studio 2010, Microsoft has announced a

    new policy they call "Coevolution" for the two premier languages, Visual Basic and C#.

    According to Microsoft's Jonathan Aneja, "The intent is to make the languages advance

    together. When major functionality is introduced in one language, it should appear in the

    other as well."

    There are even more .NET languages available now from third party developers!

    Microsoft lists all these at their site:

    COBOL for Microsoft .NET.

    Perl for Microsoft .NET.

    Eiffel for Microsoft .NET.

    Python for Microsoft .NET.

    Pascal for Microsoft .NET.

    Mercury for Microsoft .NET. Mondrian for Microsoft .NET.

    Oberon for Microsoft .NET.

    SmallTalk for Microsoft .NET.

    Standard ML for Microsoft .NET.

    Visual Studio .NET versus Visual Basic Express versus other .NET languages

    I've been using the term, ".NET Framework". This is a "library" of code that all .NET

    languages use. For example, if you declare a "String" variable in your program (like a

    sentence in this lesson), the actual programming that creates the memory for the string is ina programming object called "mscorelib".

    Before .NET, compatibility was a more serious problem because when you upgraded from

    one version of Visual Basic to the next, it was possible to create programs that's weren't

    completely compatible with computers that only had the "runtime" for the previous version.

    With .NET, you can "target" the specific version of the Framework that you want. You can

    also have different versions of .NET and Visual Basic installed "side by side" on the same

    computer. For example, you can have both VB.NET Express and Visual Studio Professional

    installed on the same computer with no problems.

    There's no advantage to using the paid version of VB.NET from a performance point of view.

    The code you create with VB Express and Visual Studio are completely equal. After they're

    compiled to executable code, they arethe same. So if you can create the program you need

    with the free version, why pay? Keep in mind that the limitations you accept with the free

    VB Express are not limitations in what the language can do, they're just limitations in how

    easy it is to write the code to do it. Visual Studio is just a graphical "front end" for the .NET

    Framework that generates the commands and parameter files to do what you need to do.

    The difference in the various versions is just the features of the front end.

    One reason for learning Visual Basic is that other technologies are also based on a "BASIC"

    syntax includingthe languages VBAand VBScript. (Mainly because BASIC was so widely used

    when they were created.) I've said it before, "The only reason for choosing one .NET

    language over others is that you can code faster and create more understandable code. For

    me, that's Visual Basic."

    http://visualbasic.about.com/od/OfficeVBA/a/vba20103.htmhttp://visualbasic.about.com/od/OfficeVBA/a/vba20103.htmhttp://visualbasic.about.com/od/OfficeVBA/a/vba20103.htmhttp://visualbasic.about.com/od/OfficeVBA/a/vba20103.htm
  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    5/12

    Some additional .NET technologies to be aware of

    Although they were also in the previous version, you should be aware of some of the other

    technologies that work with Framework 4:

    Windows Workflow Foundation (WF)

    Write code that describes a whole process, like an assembly line.

    Windows Communication Foundation (WCF)

    The buzzword here is "connected systems". We used to call them "networks" but Microsoft

    has much more ambitious goals in mind.

    Windows Presentation Foundation(WPF)

    Microsoft describes WPF (unfortunately using 'marketing language' instead of English) as "a

    unified programming model for building rich Windows smart client user experiences that

    incorporate UI, media, and documents."

    What the heck does that mean?

    For one thing, it means that a WPF application can be deployed on the desktop orhosted in

    a web browser. Microsoft wants to unify application services like 2D and 3D drawing, vector

    and raster graphics, typography and even audio and video. Microsoft Silverlight is subset of

    WPF that was originally used only on the web but is now becoming a "lightweight" version of

    WPF for any environment.

    VB.NET 2010 Express includes two templates focusing directly on WPF technology, one for

    clients (desktops) and once for web browsers. These technologies go way beyond the scope

    of this introduction course, but be aware that they're available when you need them.

    There's another reason why thisis the right time to learn VB.NET ... It's called the "Version

    2.0 Rule". Learn about it on the next page.

    VB.NET Express 2010 is technology you can rely on!

    Programmers have learned to rely on the "version 2.0" rule over the years. The rule states

    that you should generally depend on version 2.0 of any really new product because it will

    take that long to work the bugs out. Besides, version 1.0 might totally flop and you don't

    want to be left holding the bag. There's nothing to worry about with VB.NET. The underlying

    Framework technology is all the way up to version 4, and that means that the bugs in the

    standard things that you need to do have been thoroughly worked out.

    (Some of the newest technologies, like WPF and WCF still have a little work needed, even

    though they're in production for mission critical systems now.)

    One "bug" that Microsoft has worked out with the .NET Framework and VB.NET Express is

    how to combine the opposite goals of moving "upscale" to the professional business

    development world and still stay affordable for students, beginning programmers, and evenhobby programmers.

    Business success for Microsoft demands that they offer products with the performance,

    sophistication, and of course the huge prices in the corporate world. When I was a corporate

    http://visualbasic.about.com/od/usingvbnet/a/WPFLayout.htmhttp://visualbasic.about.com/od/usingvbnet/a/WPFLayout.htmhttp://visualbasic.about.com/od/usingvbnet/a/WPFLayout.htm
  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    6/12

    software development manager in the old mainframe world, it was fairly easy to justify and

    purchase software for the mainframe in the price range of $100,000 or so. (In current

    dollars.) But that one copy might be used by about a hundred programmers. These are the

    prices that Microsoft wants to charge their most affluent corporate customers. For example,

    a new copy of the most expensive edition of Visual Studio 2010 - Visual Studio Ultimate - will

    set you back nearly $12,000! And a corporation might have to buy them by the hundreds or

    even thousands.

    Whoh!!You and I certainly can't afford those prices. (A corporation doesn't buy the softwareI use, I buy it myself. I'm one of you!)

    Microsoft knows that if they want to continue to be as successful as they have been, they

    musthave a version of VB.NET for the rest of us because the people who can't even afford a

    compiler today will be making those high-dollar purchasing decisions tomorrow.

    The result has been the "Express" editions.

    SQL Server Express Edition

    Visual Web Developer Express Edition

    and, of course ...

    Visual Basic 2010 Express Edition!

    Getting Visual Basic 2010 Express

    The "Express" versions are Microsoft's free, downloadable version of Visual Basic designed

    to get us all hooked on the product. As far as I'm concerned, it worked like a charm. I'm

    hooked.

    Be aware, however, that you do have to register with Microsoft to do any of this. But it really

    is free. The download address for everything is:

    http://www.microsoft.com/express/

    The next page shows you how to install and get ready to use Visual Basic Express!

    System Requirements for VB.NET Express

    Visual Basic Express is the main requirement for this course and you can get it free fromMicrosoft at the web link on the previous page.

    Note the hardware and software requirements. They're not kidding.This is heavy duty

    software and you have to be equipped to run it. In addition toWindows XPor later, you

    need a machine at least this big:

    1.6 GHz or faster processor

    1024 MB RAM (1.5 GB if running on avirtual machine)

    3 GB of available hard-disk space 5400 RPM hard-disk drive

    DirectX 9-capable video card running at 1024 x 768 or higher display resolution

    DVD-ROM drive

    http://go.redirectingat.com/?id=68756X1529941&site=about.com/compute&xs=1&isjs=1&url=http%3A%2F%2Fwww.microsoft.com%2Fexpress%2F&xguid=e1ceaf24c3e762ab86d0f666d4441af7&xuuid=ab0b149ed4f3753ed452cc7303d2311d&xsessid=1f6f840a5f48511fc6e4d2aadce570a0&xcreo=0&xed=0&sref=http%3A%2F%2Fvisualbasic.about.com%2Fod%2Flearnvbnet%2Fa%2FLVBE_L1_3.htm&pref=http%3A%2F%2Fvisualbasic.about.com%2Fod%2Flearnvbnet%2Fa%2FLVBE_L1_2.htm&xtz=-180http://go.redirectingat.com/?id=68756X1529941&site=about.com/compute&xs=1&isjs=1&url=http%3A%2F%2Fwww.microsoft.com%2Fexpress%2F&xguid=e1ceaf24c3e762ab86d0f666d4441af7&xuuid=ab0b149ed4f3753ed452cc7303d2311d&xsessid=1f6f840a5f48511fc6e4d2aadce570a0&xcreo=0&xed=0&sref=http%3A%2F%2Fvisualbasic.about.com%2Fod%2Flearnvbnet%2Fa%2FLVBE_L1_3.htm&pref=http%3A%2F%2Fvisualbasic.about.com%2Fod%2Flearnvbnet%2Fa%2FLVBE_L1_2.htm&xtz=-180http://pcsupport.about.com/od/windowsxp/a/windows-xp.htmhttp://pcsupport.about.com/od/windowsxp/a/windows-xp.htmhttp://pcsupport.about.com/od/windowsxp/a/windows-xp.htmhttp://linux.about.com/cs/linux101/g/virtualmachine.htmhttp://linux.about.com/cs/linux101/g/virtualmachine.htmhttp://linux.about.com/cs/linux101/g/virtualmachine.htmhttp://linux.about.com/cs/linux101/g/virtualmachine.htmhttp://pcsupport.about.com/od/windowsxp/a/windows-xp.htmhttp://go.redirectingat.com/?id=68756X1529941&site=about.com/compute&xs=1&isjs=1&url=http%3A%2F%2Fwww.microsoft.com%2Fexpress%2F&xguid=e1ceaf24c3e762ab86d0f666d4441af7&xuuid=ab0b149ed4f3753ed452cc7303d2311d&xsessid=1f6f840a5f48511fc6e4d2aadce570a0&xcreo=0&xed=0&sref=http%3A%2F%2Fvisualbasic.about.com%2Fod%2Flearnvbnet%2Fa%2FLVBE_L1_3.htm&pref=http%3A%2F%2Fvisualbasic.about.com%2Fod%2Flearnvbnet%2Fa%2FLVBE_L1_2.htm&xtz=-180
  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    7/12

    Also note that you really dohave to completely uninstall any Beta versions before

    downloading and installing Visual Basic Express.

    Failure to uninstall the beta versions before installing the final version was a horrible

    problem back when Visual Basic Express was first introduced ... and it's verytough to solve.

    Writing your first VB.NET Express program

    For decades, programmers have used the program "Hello World" to launch a new languageand I certainly want to uphold tradition.

    This is literally true!

    The tradition dates back to 1978 when Dennis Ritchie and Brian Kernighan published the

    landmark book,"The C Programming Language". TheHello World programeven has it's own

    entry in Wikipedia.As Wikipedia notes, "A 'hello world' program can be a useful sanity test

    to make sure that a language's compiler, development environment, and run-time

    environment are correctly installed."

    "Hello World" is simply a program that displays the phrase on a convenient output device.

    So, here's how to create "Hello World" using Visual Basic Express. If you need more help

    understanding how to start and use VB.NET,Part 4 of this seriesgoes into greater detail. You

    can skip ahead and read it now if you like.

    Start Visual Basic Express and select New Project from the File menu (or press Ctrl-N). Select the

    Windows Application template. Change the name to HelloWorld (If you use the default name

    WindowsApplication1 for your projects, you won't be able to remember what each project does.

    Always use meaningful names so you, or another programmer, can understand them later.)

    Visual Basic Express will create a complete starter Windows program, ready for you to add your code

    and objects. The initial screen looks like this:

    http://cplus.about.com/od/introductiontoprogramming/p/profileofc.htmhttp://cplus.about.com/od/introductiontoprogramming/p/profileofc.htmhttp://cplus.about.com/od/introductiontoprogramming/p/profileofc.htmhttp://php.about.com/od/learnphp/qt/hello_world.htmhttp://php.about.com/od/learnphp/qt/hello_world.htmhttp://php.about.com/od/learnphp/qt/hello_world.htmhttp://en.wikipedia.org/wiki/Hello_Worldhttp://en.wikipedia.org/wiki/Hello_Worldhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P1.htmhttp://en.wikipedia.org/wiki/Hello_Worldhttp://php.about.com/od/learnphp/qt/hello_world.htmhttp://cplus.about.com/od/introductiontoprogramming/p/profileofc.htm
  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    8/12

    Notice that the default name Form1 has also been used for your startup form. It's a good idea to

    rename all of your project controls before you do anything else. Visual Basic will create a lot of your

    system automatically. If you don't provide your own names here, you'll have more default names

    that you won't understand later. So, to get started, change the file name of the form to

    HelloForm.vb.

    The values that are associated with an object are called "properties". For example, the initial

    form added by VB.NET was given the default name Form1. When you changed the file nameto HelloForm, VB.NET changed the Name property to HelloForm at the same time to save

    you work and keep things synchronized. To check, click the form to select it and then scroll

    up in the Properties window until the Name property is visible. (The Properties window will

    normally be at the bottom right in VB.NET.) The file name of the form and the Name

  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    9/12

    property don't have to be the same, but it's less confusing if they are the same. You'll find

    that VB.NET does a lotfor you automatically.

    We'll discuss properties, controls and other things in more detail in the next lessons. For

    now, just remember that every object will usually have a lot of unique values associated with

    it. Scan the other properties for the form to get a feeling for the kinds of values that are

    available.

    While you're looking at the properties of the form, you might want to scroll down andchange the Text property too. Notice that when you change the Text property, the form

    display in the design window is automatically updated with the new title. Here's an

    illustration after all of these properties have been changed.

    On the next page, we add controls to our program and run it!

    Controls are objects that do things for you in your project. They can usually be found in the Toolbox.

    The Toolbox is a good example of an Auto Hide window; a window that will automatically display

    when you move your mouse over the tab for it. You canpinan Auto Hide window in the openposition by clicking the icon as shown in the illustration below.

  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    10/12

    o add the control to the form, just click and drag it to where you want it on the form. You

    can also double click the control to add it. After the controls have been added, you can

    resize the controls and change their properties. Add one Button and one Label to the form.

    Change the names and position them where you want them.

    (I used "btnDisplayHello" for the Button and "lblHelloWorld" for the Label.) Finally, change

    the Text property for the Button. (I used "Display Hello". I also resized the Button slightly.)

    The last thing we need to do is add the code that will display "Hello World!" in the Label

    control when we click the btnDisplayHello Button. To enter code, we use a different window

    called the code window. The easiest way to display the code window, and get Visual Basic to

    give you a running start, is to double click the control that you want to use to perform some

    action. This displays a default event subroutinefor that control with some of the code

    already added for you by VB.NET.

    Notice that a Class and a Sub (that is, a "subroutine") have been created for you and that

    they have the names that you gave to the Form and the Button.

    In addition the btnDisplayHello Name property has been combined with the name of this

    event, that is "Click", using an underscore character. This means that when the program is

    running and btnDisplayHello is clicked, the code you put in this subroutine will be executed.

    Technically, in the Click event subroutine, the event named in the Handles clause at the end

    of the statement is the one that triggers the execution of this subroutine.

    They will usually be the same, however.

    Properties (and methods, which we'll also learn about later) for controls are identified by the

    dot operator. The Name of a control is connected to a method or a property with a dot to

  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    11/12

    indicate that the property or method is part of that control. So the Text property of the

    lblHelloWorld control is assigned the value "Hello World!" when the btnDisplayHello Button

    is clicked.

    Public Class HelloForm

    Private Sub btnDisplayHello_Click(

    ByVal sender As System.Object,

    ByVal e As System.EventArgs

    ) Handles btnDisplayHello.Click

    lblHelloWorld.Text = "Hello World"

    End Sub

    End Class

    If you have worked with previous versions of VB.NET, one of the changes for VB.NET 2010

    that you may notice is on display here. Previous versions required a "line continuation

    character" (That's a space followed by an underscore at the end of the line) to keep lines

    short by spreading a statement over several lines. The Sub statement here is spread over

    four lines but you don't have to use them now. (They still work if you want to use them.)

    Now let's try out the program and see if it works. To run the program, click the Start

    Debugging icon in the toolbar or press F5. Click the btnDisplayHello Button and Hello World

    is displayed in the Label. Here's the completed program:

    The goal of this lesson has been to get a working copy of Visual Basic 2010 Express on your

    computer and make sure that even people who haven't written a single line of programming

    code before could write a program. In future lessons, I won't go through the steps in this

    much detail. I'll assume that you know how to use Visual Basic and how to change properties

    and enter programming code. In future lessons, I'll also provide downloads for the programs

  • 7/26/2019 Visual Basic .NET 2010 Express a From the Ground Up Tutorial

    12/12

    that we create, but since the point of this program was to make sure everyone could enter

    and run a program themselves, I haven't done that this time.

    Extra Credit for the Extra Ambitious

    So if you have any doubts at all about what you're doing, try changing the Hello World

    program to do something else.

    Change the Font property to see what something else looks like. Add a Textbox to the form and add code that will transfer text in the TextBox to the

    Label.

    Change the title on the form when the Button is clicked instead of putting the text in

    a Label.

    In part 2 of the tutorial,Visual Basic Fundamentals,we cover two topics that you need to get

    started. The first is where to find more information. Online learning is different from reading

    a book because you literally have millions of pages of information available to you at the

    click of a mouse. So it doesn't make sense to cover all of the fundamentals here. But it does

    make sense to give you a foundation to work from so the second topic is the Visual Basicsyntax and basic structures. This section of the tutorial covers the basics that you need to

    know to write a program without going into the details that you can and should get directly

    from Microsoft anyway.

    http://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htmhttp://visualbasic.about.com/od/learnvbnet/a/LVBE_L3_P2.htm