473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 23828
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 panel, I want to trap the left mouse click. The...
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 want to be able to extract the 12 (Month) from...
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, TextBox1.Text.Length - 1) End If Adding: Imports...
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; // x is a pointer to a 'const int' int const *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 "3145728". But the MouseButtons Enum contains only Left,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.