Behaviour of Left() function

 

A few months ago, I wrote an .HTA application to make life a little easier on the job.  As I look at expanding the capabilities of this application, I am considering a move to VB. 

The following code raises a design time error:


Error 1 'Public Property Left() As Integer' has no parameters and its return type cannot be indexed. \Visual Studio 2005\Projects\frmRMCxpress.vb 9 12 RMCxpress


If Left(txtHostName.Text, 1) = "\" Then

MsgBox("Remove leading and trailing \", MsgBoxStyle.OkOnly, "Help")

End If


 

Does anyone have any suggestions as to why this error is being raised.  I don't see a thing wrong with the syntax.  I also tried setting the focus to the control txtHostName  prior to the code above.

 

Thanks.

 



Answer this question

Behaviour of Left() function

  • Marc EMILE

    Sorry, my mistake... there is no Left function in the String class. You can use Substring from the String class or write Microsoft.VisualBasic.Left instead of simply Left.

     


  • Mark Shehan

    Try

    If txtHostName.Text.Left(1) = "\" Then

    Left happens to be a property of the Form.


  • rebcharles

     

    Thanks for the help, neither suggestion worked.  I ended up doing away with the If/Then function entirely and used the Trim function instead.  I just strip the bad stuff without any prompt at all which is where I was planning to end up anyway.

    txtHostName.Text = txtHostName.Text.Trim("\")      'remove leading or trailing \

    txtHostName.Text = txtHostName.Text.Trim()         'remove leading and trailing spaces

    txtDomainName.Text = txtHostName.Text


  • falcon31

    Try using the 'Left$' function instead of 'Left':

    If Left$(txtHostName.Text, 1) = "\" Then

    MsgBox("Remove leading and trailing \", MsgBoxStyle.OkOnly, "Help")

    End If



  • Behaviour of Left() function