Solution to using Left/Right in Forms without qualifiers

  • Thread starter Thread starter Nobody
  • Start date Start date
N

Nobody

If you want to use Left/Right in VB.Net forms without having to prepend them
with "Microsoft.VisualBasic", or an alias like "VB.", you can use this
method. It involves "hiding" or shadowing the Left and Right properties of
the Form by using Shadows keyword, and provide your own functions. You can
still access the Left/Right properties of your form by prefixing them with
MyBase keyword. Example:

Public Class Form1

Private Shadows Function Left(ByRef s As String, ByVal n As Integer) As
String
Return Microsoft.VisualBasic.Left(s, n)
End Function

Private Shadows Function Right(ByRef s As String, ByVal n As Integer) As
String
Return Microsoft.VisualBasic.Right(s, n)
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim s As String

s = "Hello world!"
Console.WriteLine(Left(s, 5))
Console.WriteLine(Right(s, 5))
Console.WriteLine(Mid(s, 5, 1))
Console.WriteLine(MyBase.Left)
Console.WriteLine(MyBase.Right)
End Sub
End Class


Output:

Hello
orld!
o
154
454
 
Nobody pretended :
If you want to use Left/Right in VB.Net forms without having to prepend them
with "Microsoft.VisualBasic", or an alias like "VB.", you can use this
method. It involves "hiding" or shadowing the Left and Right properties of
the Form by using Shadows keyword, and provide your own functions. You can
still access the Left/Right properties of your form by prefixing them with
MyBase keyword. Example:

Public Class Form1

Private Shadows Function Left(ByRef s As String, ByVal n As Integer) As
String
Return Microsoft.VisualBasic.Left(s, n)
End Function

Private Shadows Function Right(ByRef s As String, ByVal n As Integer) As
String
Return Microsoft.VisualBasic.Right(s, n)
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim s As String

s = "Hello world!"
Console.WriteLine(Left(s, 5))
Console.WriteLine(Right(s, 5))
Console.WriteLine(Mid(s, 5, 1))
Console.WriteLine(MyBase.Left)
Console.WriteLine(MyBase.Right)
End Sub
End Class


Output:

Hello
orld!
o
154
454

LOL... Seems easier to just alias the namespace :) But, hey, it's an
alternative for the whiners I guess....
 
Tom Shelton said:
Seems easier to just alias the namespace

Not when someone has a lot of code to upgrade, and the code will look
familiar and easier to read. Left/Right properties are seldom needed for
forms, perhaps in Resize event, so just few changes are needed.
 
After serious thinking Nobody wrote :
Not when someone has a lot of code to upgrade, and the code will look
familiar and easier to read. Left/Right properties are seldom needed for
forms, perhaps in Resize event, so just few changes are needed.

Well, if your going to do that, then you will want to inherit every
form in your project form this form.
 
Not when someone has a lot of code to upgrade, and the code will look
familiar and easier to read.

Why not upgrade within vb6 instead?

If the intent of the upgrade is to migrate to .net then the programmer(s)
may try to use that as an excuse to rewrite the code instead.
 
DanS explained :
I'm guessing that's directed at me, but whatever.... :)

Probably - but it wasn't meant as an insult or anything. We all gripe
about something once in a while.
Many of you seem to be missing the point here....

I'm not going to go through any effort to be able to use
Left/Right on the form level as string operators. That's just
stupid. I'll now prepend them as necessary to return substrings.

My initial gripe was about not being able to just sit down and
use one of the most basic functions included in nearly every
basic language published. I needed to look up how use that
functionality. Not that I wasted a lot of time on it, but having
used several BASICs in, well, seems to be 30 years now (holy
cr*p), I was a bit miffed.

Well, I guess it would probably miff me as well - except I stoped using
VB in favor of C# a long time ago :) And C# doesn't have any of those
functions....
Let's say you've been using a word processor family for a long
time, and then suddenly on one of the new releases, they
completely changed some functionality that has been ingrained in
it since day 1, v0.0.0.1, so you had to learn a completely new
way of doing what you had been doing forever. You know I'm
talking about 'the ribbon', right ?

So I'm going to keep trying to use 'the Framework', because I
need to, since I write smaller utility apps that support the
company I work for's products, so I need to keep up with the
Joneses.

And from time to time I'll probably rant about something. Who
doesn't ?

That's ok - as long as you don't expect everyone to agree :)
Besides, what good's a discussion group if everyone's all lovey-
dovey and agreeing on everything all the time ?

LOL... to true.
 
Nobody said:
If you want to use Left/Right in VB.Net forms without having to prepend
them with "Microsoft.VisualBasic", or an alias like "VB.", you can use
this method. It involves "hiding" or shadowing the Left and Right
properties of the Form by using Shadows keyword, and provide your own
functions. You can still access the Left/Right properties of your form by
prefixing them with MyBase keyword. Example:

Public Class Form1

Private Shadows Function Left(ByRef s As String, ByVal n As Integer) As
String
Return Microsoft.VisualBasic.Left(s, n)
End Function

Private Shadows Function Right(ByRef s As String, ByVal n As Integer)
As String
Return Microsoft.VisualBasic.Right(s, n)
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim s As String

s = "Hello world!"
Console.WriteLine(Left(s, 5))
Console.WriteLine(Right(s, 5))
Console.WriteLine(Mid(s, 5, 1))
Console.WriteLine(MyBase.Left)
Console.WriteLine(MyBase.Right)
End Sub
End Class


Output:

Hello
orld!
o
154
454
Thanks, but that workaround should not be necessary. As it is I only use the
string dismantling once in my app so it would take longer to write this
code, than it would even using the ridiculous Microsft.VisualBasic...
prefix.
 
Tom Shelton said:
LOL... Seems easier to just alias the namespace :) But, hey, it's an
alternative for the whiners I guess....

I reject the concept that I am a 'whiner' just because vb.net has
shortcomings (many of them silly and lazy).
 
Nobody said:
Not when someone has a lot of code to upgrade, and the code will look
familiar and easier to read. Left/Right properties are seldom needed for
forms, perhaps in Resize event, so just few changes are needed.
Agreed. I only needed it once but in some projects it may indeed be
worthwhile.
 
DanS said:
I'm guessing that's directed at me, but whatever.... :)

Many of you seem to be missing the point here....

I'm not going to go through any effort to be able to use
Left/Right on the form level as string operators. That's just
stupid. I'll now prepend them as necessary to return substrings.

My initial gripe was about not being able to just sit down and
use one of the most basic functions included in nearly every
basic language published. I needed to look up how use that
functionality. Not that I wasted a lot of time on it, but having
used several BASICs in, well, seems to be 30 years now (holy
cr*p), I was a bit miffed.

Let's say you've been using a word processor family for a long
time, and then suddenly on one of the new releases, they
completely changed some functionality that has been ingrained in
it since day 1, v0.0.0.1, so you had to learn a completely new
way of doing what you had been doing forever. You know I'm
talking about 'the ribbon', right ?

So I'm going to keep trying to use 'the Framework', because I
need to, since I write smaller utility apps that support the
company I work for's products, so I need to keep up with the
Joneses.

And from time to time I'll probably rant about something. Who
doesn't ?

Besides, what good's a discussion group if everyone's all lovey-
dovey and agreeing on everything all the time ?

Absolutely agreed Dan!
 
StrandElectric pretended :
I reject the concept that I am a 'whiner' just because vb.net has
shortcomings (many of them silly and lazy).

Nope. They are based on your misunderstanding.
 
StrandElectric pretended :
I reject the concept that I am a 'whiner' just because vb.net has
shortcomings (many of them silly and lazy).

Let me expound on what I mean...

Personally, a properly architectured app, should almost never run into
this problem. Why? Because there SHOULD BE NO LOGIC in your from in
the first place. Learn OOP and design patterns, and things will be
much clearer as to why they way they are. And, you will come to
realize that it is not VB.NET - but VB.CLASSIC that was "silly and
lazy".
 
A racing car is still a car, but would you complain about all
the differences as even shifting works differently?

For me you are like someone that has been narcotized by aliens who
then dragged you out of your street car, shoving you into a racing
car where you woke up later, and you still haven't realized your
location after many years.
 
Am 19.01.2011 02:12, schrieb DanS:
.....pretty bad.

It was an analogy but no personal attack. I actually found it funny. :-D
You sitting in the car trying to shift gears again and again not having
noticed you're sitting in a different car, haha...... Not funny? ;-)
 
Tom Shelton said:
StrandElectric pretended :

Nope. They are based on your misunderstanding.
So Tom, vb.net has no shortcomings? It is perfect? (and BTW, although you
didn't claim it, has the most complete and marvellous help system
imaginable). Any perceived problems are because of my misunderstanding?
No-one yet has been able to explain why syntax like left and right or left$
and right$ cannot be employed in the context of splitting strings.
 
Armin Zingler said:
A racing car is still a car, but would you complain about all
the differences as even shifting works differently?

For me you are like someone that has been narcotized by aliens who
then dragged you out of your street car, shoving you into a racing
car where you woke up later, and you still haven't realized your
location after many years.

All lovely words and images, even 'from' (from a previous poster). (I don't
use those in my apps). But like politicians (but undoubtedly more sincere)
you dodge the issue. If a language can be constructed to recognise the
tortured syntax you suggest, why can't it simply recognise left etc (or
left$) in the context of splitting strings? And that's only one example.

We have here in Australia, in NSW in fact, a leader who has a pe-prepared
and obscure all-purpose answer which she just spouts over and over again,
regardless of the question. The question never gets answered. This is
therefore familiar to me. You are simply playing with words. You are
achieving the opposite to your intention. If you are from Microsoft, I
venture to suggest that more and more people are seeing through you. I was
persuaded that vb.net has many improved features (see my detailed first
impressions post), but you will never persuade me that tortured syntax and
useless help systems (those are the lazy ones) are the way to go.
 
Armin Zingler said:
Am 19.01.2011 00:17, schrieb StrandElectric:

You don't need Microsoft.VisualBasic.

OK, but that's one way round the problem and it does work... We should of
course not need *any* ways round the problem. The problem should bot be
there.
 
StrandElectric formulated the question :
So Tom, vb.net has no shortcomings? It is perfect?

Nope. It has lots of problems, this just isn't one of them.
(and BTW, although you
didn't claim it, has the most complete and marvellous help system
imaginable). Any perceived problems are because of my misunderstanding?
No-one yet has been able to explain why syntax like left and right or left$
and right$ cannot be employed in the context of splitting strings.

Huh? It can. You've been shown how - so, I'm not sure why you are all
worked up.
 
StrandElectric formulated the question :
OK, but that's one way round the problem and it does work... We should of
course not need *any* ways round the problem. The problem should bot be
there.

If you had any concept of namespaces, you would understand exactly why
it happens. Like I said, this is a lack of understanding on your part.
 
Back
Top