String functions

V

Vik

In a Windows Application, VS.NET does nor recognize Right function. I have
to use it with full specification:
Microsoft.VisualBasic.Right("123", 2)

Adding
Imports Microsoft.VisualBasic, Microsoft.VisualBasic.Strings
does not help.

In a Web Application, Right("123", 2) works without Imports and without full
specification. Why does not it work in the Windows Application ?

Thank you.
 
S

Scott

In System.Windows.Forms there is a property named "Right" that, according to
MSDN, "Gets the distance between the right edge of the control and the left
edge of its container."

If you have included the System.Windows.Forms namespace, which you probably
have in a Windows application, this property is included. It appears that
even though this is a property and Microsoft.VisualBasic.Right is a
function, Visual Studio can't distinguish between the two and defaults to
the Windows.Forms property. I've run into this myself and eventually began
using the String.Substring method instead.
 
J

Jay B. Harlow [MVP - Outlook]

Vik,
Within a Windows Application within the code for a form, Right will see the
Form.Right property which is inherited from Control.

What I will do is use an Import alias:

Imports VB = Microsoft.VisualBasic

Then when I want to use one of the Microsoft.VisualBasic.Strings functions I
will prefix it with VB.

Dim s As String = VB.Right("123", 2)

The problem does not exist in a Web Form as a Web Form does not have a Right
property associated with it.

Hope this helps
Jay
 
H

Herfried K. Wagner [MVP]

* "Vik said:
In a Windows Application, VS.NET does nor recognize Right function. I have
to use it with full specification:
Microsoft.VisualBasic.Right("123", 2)

The code above won't work. 'Right' is a member of 'Strings'.

The reason why you cannot use 'Right' directly is that there is a name
"conflict" between the form's 'Right' property (which can be accessed
without a preceeding 'Me.' inside the class) and the 'Right' function.
This problem won't occur in another class which doesn't have a 'Right'
property and/or doesn't inherit such a property.

I always import the 'Microsoft.VisualBasic' namespace and use
'Strings.Right' to call the function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top