469,315 Members | 1,795 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Left and Right Functions

This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have to
do to make it work in VB.Net)

I have imported this:

imports system.string
Nov 21 '05 #1
12 22931
Dim s As String
s = s.SubString(1, 2)

SubString() is like the SUB() function in VB 6. You can create your own
Right() function using SubString():

Private Function strRight(ByVal s As String, ByVal i As Integer) As String
If Not ((i >= s.Length) Or (s.Length < 1)) Then
s = s.Substring(s.Length - i, i)
End If
Return (s)
End Function
"patang" <pa****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have
to
do to make it work in VB.Net)

I have imported this:

imports system.string

Nov 21 '05 #2
Oops. Sorry, been too long. SubString() is like MID(), not SUB. DOH!

"Michael C#" <xy*@abcdef.com> wrote in message
news:bX*******************@fe12.lga...
Dim s As String
s = s.SubString(1, 2)

SubString() is like the SUB() function in VB 6. You can create your own
Right() function using SubString():

Private Function strRight(ByVal s As String, ByVal i As Integer) As String
If Not ((i >= s.Length) Or (s.Length < 1)) Then
s = s.Substring(s.Length - i, i)
End If
Return (s)
End Function
"patang" <pa****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have
to
do to make it work in VB.Net)

I have imported this:

imports system.string


Nov 21 '05 #3
patang,

Strange, this give for me no compiling error, what version are you using and
when it is 2003 did you install the SP1.

Cor
Nov 21 '05 #4
If you are coding this in a form, then you are bumping into a namespace
issue. Left and Right in forms pertain to x-axis distances (there is no name
collision with Mid). Try
Microsoft.VisualBasic.Right(s, 2)
which is a fully qualified reference to the string function you want.

I find this irritating too, but you get used to it fairly quickly. In this
particular case, I use mid() more often and use right() and left() less often.

"patang" wrote:
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have to
do to make it work in VB.Net)

I have imported this:

imports system.string

Nov 21 '05 #5
patang,

Strange, this give for me no compiling error, what version are you using and
when it is 2003 did you install the SP1.

Cor
Nov 21 '05 #6
"patang" <pa****@discussions.microsoft.com> schrieb:
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have
to
do to make it work in VB.Net)


'Right' is in conflict with a property of your form. Use 'Strings.Right'
instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
If you are coding this in a form, then you are bumping into a namespace
issue. Left and Right in forms pertain to x-axis distances (there is no name
collision with Mid). Try
Microsoft.VisualBasic.Right(s, 2)
which is a fully qualified reference to the string function you want.

I find this irritating too, but you get used to it fairly quickly. In this
particular case, I use mid() more often and use right() and left() less often.

"patang" wrote:
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have to
do to make it work in VB.Net)

I have imported this:

imports system.string

Nov 21 '05 #8
"patang" <pa****@discussions.microsoft.com> schrieb:
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have
to
do to make it work in VB.Net)


'Right' is in conflict with a property of your form. Use 'Strings.Right'
instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
Herfried,

Funny normally I just take a piece of a form to test this, now I did it in a
seperated class.
(As you know am I never using this kind of commands because of the First
indexer)

:-)

Cor
Nov 21 '05 #10
Herfried,

Funny normally I just take a piece of a form to test this, now I did it in a
seperated class.
(As you know am I never using this kind of commands because of the First
indexer)

:-)

Cor
Nov 21 '05 #11
Patang,
As the others suggests. Left & Right are properties of Forms. If you attempt
to use the Left & Right functions on a form you will receive this error.

What I normally do is use an import alias in my form class files.

Something like:

Imports VB = Microsoft.VisualBasic

Public Class MainForm
Inherits System.Windows.Forms.Form

...

Public Sub SomeMethod()
Dim s As String
s = "the"
s = VB.Right(s, 2)
End Sub

End Class

The advantage of the import alias "VB = Microsoft.VisualBasic" is that it
will work with all types (classes, modules, enums, ...) in the
Microsoft.VisualBasic namespace.

Hope this helps
Jay
"patang" <pa****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have
to
do to make it work in VB.Net)

I have imported this:

imports system.string

Nov 21 '05 #12
Patang,
As the others suggests. Left & Right are properties of Forms. If you attempt
to use the Left & Right functions on a form you will receive this error.

What I normally do is use an import alias in my form class files.

Something like:

Imports VB = Microsoft.VisualBasic

Public Class MainForm
Inherits System.Windows.Forms.Form

...

Public Sub SomeMethod()
Dim s As String
s = "the"
s = VB.Right(s, 2)
End Sub

End Class

The advantage of the import alias "VB = Microsoft.VisualBasic" is that it
will work with all types (classes, modules, enums, ...) in the
Microsoft.VisualBasic namespace.

Hope this helps
Jay
"patang" <pa****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
This is really silly question.

Dim s As String
s = "the"
s = Right(s, 2)

Why this gives me compilation error? (This works in VB6 .. what do I have
to
do to make it work in VB.Net)

I have imported this:

imports system.string

Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by mitsura | last post: by
9 posts views Thread by dixie | last post: by
8 posts views Thread by A.M | last post: by
11 posts views Thread by Bruce A. Julseth | last post: by
3 posts views Thread by Ed Chiu | last post: by
6 posts views Thread by James Brown [MVP] | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.