Function LEFT, RIGHT in VB.Net


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Function LEFT, RIGHT in VB.Net

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Function LEFT, RIGHT in VB.Net

    I cannot use function LEFT, RIGHT in VB.Net. Anyone know what function use instead LEFT, RIGHT

  2. #2
    Join Date
    Jul 2004
    Posts
    81
    Qualify the calls with the VB class name:
    e.g.,
    Strings.Left

    If there is nothing in the global namespace with these names, VB doesn't need them to be qualified, but in a form, for instance, you'll get conflict with the form's 'Left' property.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com
    Instant C# - VB to C# Converter
    Instant VB - C# to VB Converter

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Those functions were actually VBA functions that were supported in Visual Basic up to version 6. Support for them was dropped in .NET with the class names mentioned by David Anton.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Mar 2011
    Location
    New York
    Posts
    5

    Function LEFT, RIGHT in VB.Net

    Left and Right functions can be used to truncate strings after a certain number of characters from the left and right of the string, respectively. Each of these functions requires two arguments:
    # The string from which the substring should be extracted.
    # The length of the string to return.

  5. #5
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    The 3 VB functions Left, Right and Mid have been combined into a single one in .NET: String.Substring.

    It is pretty straighforward to use for Left and Mid, but need some fidling for the equivalent or Right:

    Code:
    Dim x As String = "I am me"
    
    'This is the Left : Result "I"
    Debug.WriteLine(x.Substring(0, 1))
    
    'This is the Mid : Result "am"
    Debug.WriteLine(x.Substring(2, 2))
    
    'This is the Right : Result "me"
    Debug.WriteLine(x.Substring(x.Length - 2, 2))
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  6. #6
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    Just to make things clear.

    When you talk about the Left and Right functions, you are talking of functions in the Microsoft.VisualBasic namespace. This namespace has been designed to simulate the commands of the old Visual Basic commands. You do not have to specify the namespace when you call those functions, because by default, the environment activate an Imports on it (you can see it under the list of references in the project's properties).

    You can thus still use the old functions that you were used to if you used to program in VB6, and end up with the same problems, such as the conflict between the Right and Left properties of a form and the Right and Left functions of the Microsoft.VisualBasic namespace.

    However, all those functions have been replaced by something else in .NET. An object oriented language does not use functions, it uses methods on the variables. Thus calling Substring on a String object (a method in the String class) is the most appropriate way to go.

    Under the hood, it makes no difference. When you use the Right and Left functions, the compiler compiles a call to Substring.

    The same thing applies to a lot of things. Instead of calling MsgBox, you might be better calling the MessageBox.Show method.

    Using the framework class methods over those in the Microsoft.VisualBasic namespace has 2 advantages.

    The most important is that you learn to code in .NET, and will thus be able to more easily understand code written in other langages. By the same token, learning another .NET language such as C# will be a lot easier, since you will continue to use the same methods.

    The .NET methods are also usually more versatile, often offering more ways to do the same thing, or parameters that are not available in the Microsoft.VisualBasic functions.
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

Similar Threads

  1. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 07:53 AM
  2. AnimateWindow API
    By Tim Manos in forum VB Classic
    Replies: 4
    Last Post: 10-19-2001, 07:06 AM
  3. Please help me -- urgent -- deadlock error
    By chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 08:36 AM
  4. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 04:45 PM
  5. I am helpless - Edit Info form
    By Dan in forum VB Classic
    Replies: 0
    Last Post: 03-17-2000, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center