Problem with LEFT

  • Thread starter Thread starter Wayne Wengert
  • Start date Start date
W

Wayne Wengert

I use statements like LEFT(textstring,6) in my app. I have "Imports
Microsoft.VisualBasic" at the top of the code but to use LEFT I have to code
:
Microsoft.VisualBasic.Left(sting, integer)

If I code just "Left" it is flagged as an error with the message

"Public Overloads Property Left() As Integer has no parameters and its
return type cannot be indexed"

How can I get the VisualBasic version of Left as the default?
 
Are there other namespaces that implement a "Left". The form in question has
the following namespaces

Imports Microsoft.VisualBasic

Imports System.IO

Imports System.Char ' Allows use of ControlChars.nnnn

Imports System.Data.OleDb



Wayne
 
You don't have to manually import the Microsoft.VisualBasic namespace --
Visual Studio does that implicitly for VB projects. You should be able to
use "Left" (and other VB keywords) automatically, without the Imports...
statement and without using the fully-qualified name.

Your problem looks like a namespace conflict. Try right-clicking on the
Left keyword in the module, and select "Go to definition" -- it'll bring up
the object browser, and highlight the method it's trying to use (the other
Left.)

Just to play Devil's advocate, have you considered using the .Net framework
equivalents for Left and other VB keywords? For example, you could replace
"x = Left(MyString, 5)" with x = MyString.Substring(0, 5). There's nothing
wrong with using the VB functions, but in my opinion it's generally a better
practice to use the .Net equivalents when possible.

Check out these links:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnguinet/html/drguinet0_update.asp

http://msdn.microsoft.com/vbasic/us...tml/vbtchmicrosoftvisualbasicnetinternals.asp

Hope this helps,
Robert Jacobson
 
Hmmm.. that gets me....

<System.ComponentModel.BrowsableAttribute(False),
System.ComponentModel.DesignerSerializationVisibilityAttribute(0),
System.Windows.Forms.SRCategoryAttribute("CatLayout"),
System.Windows.Forms.SRDescriptionAttribute("ControlLeftDescr"),
System.ComponentModel.EditorBrowsableAttribute(0)>

Public Property Left As Integer

Member of System.Windows.Forms.Control

I don't see how to find what control has a "Left" property. I'll check out
the links you provided.

Wayne
 
Wayne,
Remember Left & Right are a properties of System.Windows.Forms.Control,
System.Windows.Forms.Form inherits from Control.

If you want to use the VB.Left or VB.Right functions within a Form or
UserControl, you need to prefix it with a namespace.

One handy method is to use

Imports VB = Microsoft.VisualBasic

for your import, then you can use VB.Left to call the function.

Hope this helps
Jay
 
re devils advocate - note that the VB string handling
functions are in some but not all cases faster than using
SubString - there is an MS doc that covers this but I
havent got the url to hand

hth

guy
-----Original Message-----
You don't have to manually import the
Microsoft.VisualBasic namespace --
 
Back
Top