Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 7 - Learning the Visual Basic .NET Language
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Learning the Visual Basic .NET Language
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2005-11-17

    Table of Contents:
  • Learning the Visual Basic .NET Language
  • The Evolution of VB .NET
  • Variables and Data Types
  • Arrays
  • Variable Operations
  • The String Class
  • Conditional Structures
  • Loop Structures
  • Functions and Subroutines

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Learning the Visual Basic .NET Language - Conditional Structures


    (Page 7 of 9 )

    In many ways, conditional logic—deciding which action to take based on user input, external conditions, or other information—is the heart of programming.

    All conditional logic starts with a condition: a simple expression that can be evaluated to True or False. Your code can then make a decision to execute different logic depending on the outcome of the condition. To build a condition, you can use any combination of literal values or variables, along with logical operators. Table 3-7 lists the basic logical operators.

    Table 3-7. Logical Operators

    Operator

    Description

    =

    Equal to

    <>

    Not equal to

    <

    Less than

    >

    Greater than

    <=

    Less than or equal to

    >=

    Greater than or equal to

    And

    And (evaluates to True only if both expressions are True)

    Or

    Or (evaluates to True if either expression is True)

    You can use the comparison operators (<, >, <=, >=) with numeric types and strings. A string is deemed to be “less than” another string if it occurs earlier in an alphabetic sort. Thus “apple” is less than “attach.”

    The If End If Block

    The If … End If block is the powerhouse of conditional logic, able to evaluate any combination of conditions and deal with multiple and different pieces of data. Here’s an example with an If … End If block that features two conditions:

    If MyNumber > 10 Then
        ' Do something.
    ElseIf MyString = "hello" Then
        ' Do something.
    Else
       
    ' Do something.
    End If

    Keep in mind that the If … End If block matches one condition at most. For example, if MyNumber is greater than 10, the first condition will be met. That means the code in the first conditional block will run, and no other conditions will be evaluated. Whether or not MyString contains the text “hello” becomes irrelevant, because that condition will not be evaluated.

    The Select Case Block

    VB .NET also provides a Select Case structure that you can use to evaluate a single variable or expression for multiple possible values. In the following code, each case examines the MyNumber variable, and tests if it’s equal to a specific integer.

    Select Case MyNumber
        Case 1
            ' Do something if MyNumber = 1.
        Case 2
            ' Do something if MyNumber = 2.
        Case Else
            ' Do something if MyNumber is anything else.
    End Select

    If desired, you can handle multiple cases with one segment of code by including a list of comma-separated values in the Case statement.

    Select Case MyNumber
        Case 1, 2
            ' Do something if MyNumber = 1 Or MyNumber = 2.
        Case Else
            ' Do something if MyNumber is anything else.
    End Select

    Unlike the If … End If block, Select Case is limited to evaluating a single piece of information at a time. However, it provides a leaner, clearer syntax than the If … End If block for situations in which you need to test a single variable.

    More Visual Basic.NET Articles
    More By Apress Publishing


       · This article is an excerpt from the book "Beginning ASP.NET in VB.NET: From Novice...
     

    Buy this book now. This article is excerpted from chapter three of the book Beginning ASP.NET in VB.NET: From Novice to Professional, written by Matthew MacDonald (Apress, 2004; ISBN: 1590592786). Check it out at your favorite bookstore today. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway