LEFT Function?

jmancuso

Member
Joined
Feb 4, 2005
Messages
22
Programming Experience
1-3
Okay, just learning VB .NET migrating from VBA and VB 6.0. This should be super easy but I cant seem to get the LEFT Function to work. Does VB .NET support this?

Thanks.
 

cjaymcmeans

Well-known member
Joined
Jan 12, 2005
Messages
85
Programming Experience
3-5
have you tried using
microsoft.visualbasic as an import??

if no, then try adding it as imports...

if you have then what are you trying to do and can you give me some more details as to what it is that your try to accomplish...

regards
cjay
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Importing the namespace isn't necessary. The Imports statement is a sort of shortcut so that you don't have to type the namespace again and again. Although it would work.
You could do something like this:
VB.NET:
Dim str As String = Microsoft.VisualBasic.Left("Test", 2) ' str = "Te"
The more .NET way of doing that is to use the SubString Function of the String class. The above code would become:
VB.NET:
Dim str2 As String = "Test".Substring(0, 2)  ' str2 = "Te"
 

jmancuso

Member
Joined
Feb 4, 2005
Messages
22
Programming Experience
1-3
Thank you for all the input on this. I figured out how to get it working using

Microsoft.VisualBasic.Left(string,2)

And thank you for the info on the substring function!!!
 

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,461
Programming Experience
10+
You should use the new .SubString method, for example:

Dim MyValue As String
MyValue = Whatever.SubString(0,2)
 
Top Bottom