472,330 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

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 23574
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap...
9
by: dixie | last post by:
I have been trying to extract the digits between the two / symbols in a date. For example the date (in Australian format, not US) is 23/12/2004. I...
8
by: A.M | last post by:
Hi, Using C#, what is the equivalent of functions Left, Right and Mid that we had in vb6? Thanks, Alan
11
by: Bruce A. Julseth | last post by:
I have: If (Microsoft.VisualBasic.Left(TextBox1.Text, 1) = "$") Then TextBox1.Text = Microsoft.VisualBasic.Right(TextBox1.Text,...
3
by: Ed Chiu | last post by:
Hi, Does C# has functions such as replace, left, right, substring for strings? Without these functions, it's not easy to process strings. TIA
6
by: James Brown [MVP] | last post by:
Hi, I am having trouble understanding how the 'const' modifier affects the 'left-right' rule when deciphering c-declarations: const int *x; ...
8
by: Chaitanya | last post by:
Hello, In my Application i want to know when user clicks both the "Left" and "Right" buttons of the Mouse. I am getting a number like this...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.