Solved & Left function

Posted on 2006-05-04
Last Modified: 2011-08-18
In some strange way i'm not able to use the vb left function in my application.

  dim test as string = left("TEST",1)

Results in an error:
Public Property Left() As Integer' has no parameters and its return type cannot be indexed.
right clicking the function, go to definition: opens the object browser and takes me to System.Windows.Forms.Control.Left

Replacing left with its full path (Microsoft.VisualBasic.Strings.left) works fine ...???
Question by:SjoerdvW
    LVL 25

    Assisted Solution

    Well, there is a left property on a form. So the default is Me.Left which is the left property of the form.

    I suggest just using something like:

    Dim s As String = "TEST"
    Dim x As String = s.Substring(1, 1)

    I imagine that "TEST" would probably come from a variable anyway--otherwise, just put a T in it to start with, right?


    LVL 7

    Author Comment

    Yep. TEST is comming from a variable.

    First of all: I should use Substring(0,1) to get the first char.
    Scnd: What if the variable is empty? Substring would result in an error......
    LVL 55

    Accepted Solution

    According to .net documentation, if you are using forms, you must fully qualify Microsoft.VisualBasic.Left function, that is:

    Dim x As String = Microsoft.VisualBasic.Left(s,1)
    LVL 55

    Expert Comment

    by:Jaime Olivares
    if the string is empty (s=""), Left will return an empty string ("")
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    If you want the FIRST letter with Substring() then you start at 0.  You can check the length of the string before attempting to parser it:

            Dim s As String = "TEST"
            If s.Length >= 1 Then
                Dim x As String = s.Substring(0, 1)
                MessageBox.Show(x, "First Letter", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If

    LVL 25

    Expert Comment

    by:SStory bad...
    The point is the same. You can't do it. period, if you use it inside of a windows form because it has the Left property.
    Why not use the substring?

    Of course you can and should test it before making assumptions.  That is good programming.  LEFT() wouldn't be so great either if it was empty.

    The vb library is there  to keep us from being totally alienated as vb devs, and I use quite a bit of it still, such as CSTR()
    but in this case substring works just fine.

    I do question why Microsoft didn't just add a left and right method to the string as that would have been simpler in many cases and read better.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    A short article about problems I had with the new location API and permissions in Marshmallow
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now