locked
Left() generates error, length of string not declared. RRS feed

  • Question

  • In the following code, in regard to the Left() string function, I get: " 'Public property Left as Integer' has no parameters and its return type cannot be indexed. "

    I do not understand.  It is the standard Left(start_with, number_of_chars) string function.  It has nothing to do with an integer.

    ______________________________________________________
     Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim deSource As String = Me.TextBox2.Text
            Dim str As String
            Decrypt(deSource)
            'Display the Decrypted message in TextBox1.
            Me.TextBox1.Text = (Decrypt(deSource))
            str = Me.TextBox1.Text
            If (Left(str, intPassWordLength) <> (strPassWordVar)) Then
                MessageBox.Show("Incorrect Password")
                Me.Hide()
                Form5.Show()
            Else
                'XXXXXXX
            EndIf
    How to fix?  Code please, with explaination...not just explaination, I will not understand.



    • Edited by dahermit Monday, April 30, 2012 3:30 AM
    Monday, April 30, 2012 2:50 AM

Answers

  • Either use the full qualified namespace to call the method ( Microsoft.VisualBasic.Left()) or you can also use the String.Substring() method like:

    If str.Substring(0, intPassWordLength) <> (strPassWordVar)) Then


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, April 30, 2012 5:46 AM
  • Hello Dahermit,

    This will only happen if the windows forms class is inherited because in that the Left is the property to tell what is the left edge. (This behaviour is called ambiguous). You have then to full qualify the member which you want to use. A member is a property, method or a constructor.

    By the way why are you using all those parenthesis. This code will in my idea run in your situation.

    If Microsoft.VisualBasic.Left(str, intPasswordLength) <> strPassWordVar Then


    Success
    Cor

    Wednesday, May 2, 2012 7:06 AM

All replies

  • Either use the full qualified namespace to call the method ( Microsoft.VisualBasic.Left()) or you can also use the String.Substring() method like:

    If str.Substring(0, intPassWordLength) <> (strPassWordVar)) Then


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, April 30, 2012 5:46 AM
  • I used the: "Microsoft.VisualBasic.Left()", and it worked.  Which to an old user of earlier VB's, begs the question, why?  Does it have to do with VB 2010 using "Left" for graphics purposes now?
    Monday, April 30, 2012 11:44 AM
  • I used the: "Microsoft.VisualBasic.Left()", and it worked.  Which to an old user of earlier VB's, begs the question, why?  Does it have to do with VB 2010 using "Left" for graphics purposes now?

    Somehow yes. If you create a new Winform application, the IDE assume that the Left is referring to the Left() property of the form. If you do the same inside a class that doesn`t inherit from System.Windows.Forms.Control ( like a form does ) then the Left() method is avaible.


    Hannes

    If you have got questions about this, just ask.

    In a perfect world,
    users would never enter data in the wrong form,
    files they choose to open would always exist
    and code would never have bugs.

    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, April 30, 2012 12:11 PM
  • Hi dahermit,

    Have you tried using 'LSet'?

    If (LSet(str, intPassWordLength) <> (strPassWordVar)) Then

    regards Ron

    Tuesday, May 1, 2012 11:58 PM
  • Hi dahermit,

     I could give you an alternative to what has been shown already if you are using VB.Net 2008 or later.  :)

     The 1st suggestion from Hannes to use .Substring is the easiest alternative.




    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.

    Wednesday, May 2, 2012 12:58 AM
  • Hello Dahermit,

    This will only happen if the windows forms class is inherited because in that the Left is the property to tell what is the left edge. (This behaviour is called ambiguous). You have then to full qualify the member which you want to use. A member is a property, method or a constructor.

    By the way why are you using all those parenthesis. This code will in my idea run in your situation.

    If Microsoft.VisualBasic.Left(str, intPasswordLength) <> strPassWordVar Then


    Success
    Cor

    Wednesday, May 2, 2012 7:06 AM