LEFT function throwing error

bmackkc

New member
Joined
Jan 12, 2007
Messages
4
Programming Experience
1-3
The following code snippet, as part of a class POP.vb, works:

Public Class PopMail
Private s As System.Net.Sockets.NetworkStream
Private t As New System.Net.Sockets.TcpClient
Private Connect As Boolean = False
Public Sub New(ByVal Server As String)
'open port 110 on the server
Try
'catch any error resulting from a bad server name
t.Connect(Server, 110)
s = t.GetStream()
If Left(getdata(), 3) = "+OK" Then
Connect = True
End If
Catch ex As Exception

However, if I use that same code within a form, it throws the error "'Public Property Left() as Integer' has no parameters and its return type cannot be indexed."

The definition of Left() on the form code points to System.Windows.Forms.Control. On the POP.vb class, it points to Microsoft.VisualBasic.Strings.

I can correct the error by prepending Left() with "Microsoft.VisualBasic." What I don't understand is why Left() means one thing on a form, and another in a class page? Can somebody explain this for me?

Thanks

Mike

 
It's Strings.Left, but don't use it, use the .Net framework String instance Substring method instead. Examples:
VB.NET:
Dim s As String = "+OK ready"
If s.Substring(0, 3) = "+OK" Then
'or
If "+OK ready".Substring(0, 3) = "+OK" Then
'or
If getdata().Substring(0, 3) = "+OK" Then
And Left is a property of Control (which Form class inherits from). Inside a class you have option of accessing its own properties directly (like just Left) or through Me keyword to current instance of class (Me.Left)
 
Back
Top