Equivalent of VB6 Left

W

Wayne Wengert

In VB6 I used to use the Left and Right functions a lot. e.g. strString =
Left(txtTexbox1.Text, 20). In VB.NET I know I can prefix those functions
with
Microsoft.VisualBasic.Left but I suspect there is a .NET method to
accomplish this?



Wayne
 
A

Armin Zingler

Wayne Wengert said:
In VB6 I used to use the Left and Right functions a lot. e.g.
strString = Left(txtTexbox1.Text, 20). In VB.NET I know I can prefix
those functions with
Microsoft.VisualBasic.Left but I suspect there is a .NET method to
accomplish this?


Left: txtTextbox1.text.substring(0, 20)
Right: no framework method available. Calculate Startindex and Length
arguments on your own (you can put it in your own function).

Be aware that Left also works if the string is shorter than the number of
characters to be retrieved. Substring would throw an exception in this case.


Armin
 
H

Herfried K. Wagner [MVP]

Peter,

Peter Proost said:
Strings.Left()
Strings.Right()

.... these methods are the methods mentioned by the OP
('Microsoft.VisualBasic.Strings.{Left, Right}'). However, as you show it's
necessary to qualify them in Windows Forms forms, for example, to prevent a
name clash from occuring.
 
P

Peter Proost

I thought so but I wasn't sure, I just wanted to look smart the last day
before my holiday :)

But I was just wondering, is it better not to use them, or doesn't it
matter?

Greetz Peter
 
H

Herfried K. Wagner [MVP]

Peter,

Peter Proost said:
But I was just wondering, is it better not to use them, or doesn't it
matter?

I use them, but some .NET puritans won't use them ;-).
 
J

Jay B. Harlow [MVP - Outlook]

Wayne,
As Herfried suggests you need to qualify them when you use them on a Windows
form, as Form.Left hides the version from Microsoft.VisualBasic.Strings.

What I normally do is use an import alias (in my forms & other types):

Imports VB = Microsoft.VisualBasic

strString = VB.Left(txtTextbox1.Text, 20)

Hope this helps
Jay

| In VB6 I used to use the Left and Right functions a lot. e.g. strString =
| Left(txtTexbox1.Text, 20). In VB.NET I know I can prefix those functions
| with
| Microsoft.VisualBasic.Left but I suspect there is a .NET method to
| accomplish this?
|
|
|
| Wayne
|
|
 
T

Terry Olsen

What I normally do is use an import alias (in my forms & other types):
Imports VB = Microsoft.VisualBasic

strString = VB.Left(txtTextbox1.Text, 20)

Cool! I did NOT know that! (Johnny Carson voice). You learn something new
every day around here :)
 

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

Top