473,763 Members | 4,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hmm, What happened to Left ?

Jm
Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks
Nov 21 '05
18 1759
"Sahil Malik" <co************ *****@nospam.co m> schrieb:
String.SubStrin g <--- That's what u got now !!


Why?! I am not a fan of weak semantics...

'Left' is still available in the 'Microsoft.Visu alBasic.Strings ' module and
is IMO the best choice.

To avoid a name clash with a form's 'Left' property, use 'Strings.Left' in
Windows Forms code.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #11
"Jim" <no******@this. address> schrieb:
In fact you can still use Left by invoking explicitly

Microsoft.Visua lBasic.Left(str ing, length)

but this does seem a bit unneccesary now we have Substring.


Well, why not use pure assembler? 'Substring' is unnecessary too...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #12
Herfried,

The why is in my messages in this thread

As well as the why not by the way

:-)

Cor
Nov 21 '05 #13
Hefried,
Why?! I am not a fan of weak semantics... ?

How is String.SubStrin g "weak semantics"? To me it is very OO, you have a
string object & you want to get part of that string object.

See my other post on using Strings.Left.

Jay
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:uE******** ******@TK2MSFTN GP09.phx.gbl... "Sahil Malik" <co************ *****@nospam.co m> schrieb:
String.SubStrin g <--- That's what u got now !!


Why?! I am not a fan of weak semantics...

'Left' is still available in the 'Microsoft.Visu alBasic.Strings ' module
and is IMO the best choice.

To avoid a name clash with a form's 'Left' property, use 'Strings.Left' in
Windows Forms code.

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

Nov 21 '05 #14
Jm,
In addition to all the other comments.

A Form has a Left property so it hides the VB.Left function, what I normally
do is use an Import Alias in my form source files to allow use of the
function.

Imports VB = Microsoft.Visua lBasic

Public Class MainForm

...

Public Sub Test
Dim Str as string
Str = "1234"
msgbox VB.left(str,2)
End Class

A word of caution on String.SubStrin g (System.String methods) & Strings.Left
(Microsoft.Visu alBasic.Strings functions): System.String methods uses base 0
indexes while Microsoft.Visua lBasic.Strings uses base 1 indexes. I would
recommend you stay with either the System.String methods or the
Microsoft.Visua lBasic.Strings functions to avoid possible confusion & subtle
problems later...

Hope this helps
Jay

"Jm" <ja*****@ihug.c om.au> wrote in message
news:cr******** **@lust.ihug.co .nz... Hi all

I feel stupid for asking this, but i just went to use the left() function
from vb6 only to find it doesnt do what it used to under .NET. Im assuming
theres something else now im meant to do when i want to say for example

Dim Str as string
Str = "1234"
msgbox left(str,2)

Thanks

Nov 21 '05 #15
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
Why?! I am not a fan of weak semantics...

?

How is String.SubStrin g "weak semantics"? To me it is very OO, you have a
string object & you want to get part of that string object.


'Left', 'Mid' and 'Right' make it more obvious which part of the string is
returned, and thus make code more readable. 'Substring' can be used to to
the same, but the user will have to analyze the values passed to it in order
to be able to determine if the left, right, or an arbitrary part (middle) of
the string is returned. In other words: The name 'Substring' only tells
the reader that a part of the string is returned, names like 'Left' and
'Right' provide more/additional information.

Notice that I was not discussing that 'Substring' is more OO than 'Left',
'Right', etc. OO is a good tool, but in some cases (like working with
strings or dealing with numbers) it IMO doesn't add much benefit.

Would

\\\
Dim d As Double = ...
Dim e As Double = d.Cos() * 2
///

really have benefits over

\\\
Dim d As Double
Dim e As Double = Math.Cos(d) * 2
///

only because it's more OO?

SCNR

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #16
Herfried,
'Left', 'Mid' and 'Right' make it more obvious which part of the string is
returned, and thus make code more readable. I agree it may be more obvious...

However! I'm just wondering about "weak semantics", to me saying it is "weak
semantics" is like insisting a glass is half full, when it is obvious it is
really half empty! Considering most of the time, it really doesn't matter if
I am getting the Left, Mid or Right of a string, I just want a part of the
string...

When you just want part of a string, any part of the string, SubString or
just Mid is sufficient. Left & Right can be implemented in terms of
SubString or Mid themselves...
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned. If one uses SubString enough is this really an issue? In other words, they
soon pick up on:
- x.SubString(0, n) is Left
- x.SubString(n) is Right (not the same as VB.Right!)
- x.SubString(m,n ) is Middle

Which if you believe Overloading is "evil", then yes I agree it may be "weak
semantics". However! I see overloading as a very powerful OO tool (which
like any construct can be easily abused), so the above does not cause me any
real issues... Info on "Overloadin g vs. Object Technology"
http://www.inf.ethz.ch/personal/meye...verloading.pdf

I do find VB.Left, VB.Right, & VB.Mid can be "better" in that they have more
tolerant argument checking, which also makes String.SubStrin g "better" as it
insists on correct arguments!

Jay

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:eh******** ******@TK2MSFTN GP14.phx.gbl... Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
Why?! I am not a fan of weak semantics...

?

How is String.SubStrin g "weak semantics"? To me it is very OO, you have a
string object & you want to get part of that string object.


'Left', 'Mid' and 'Right' make it more obvious which part of the string is
returned, and thus make code more readable. 'Substring' can be used to to
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned. In other words: The name 'Substring'
only tells the reader that a part of the string is returned, names like
'Left' and 'Right' provide more/additional information.

Notice that I was not discussing that 'Substring' is more OO than 'Left',
'Right', etc. OO is a good tool, but in some cases (like working with
strings or dealing with numbers) it IMO doesn't add much benefit.

Would

\\\
Dim d As Double = ...
Dim e As Double = d.Cos() * 2
///

really have benefits over

\\\
Dim d As Double
Dim e As Double = Math.Cos(d) * 2
///

only because it's more OO?

SCNR

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

Nov 21 '05 #17
Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
'Left', 'Mid' and 'Right' make it more obvious which part of the string
is returned, and thus make code more readable. I agree it may be more obvious...

However! I'm just wondering about "weak semantics", to me saying it is
"weak semantics" is like insisting a glass is half full, when it is
obvious it is really half empty! Considering most of the time, it really
doesn't matter if I am getting the Left, Mid or Right of a string, I just
want a part of the string...


When learning string algorithms for university, I found those much clearer
and easier to understand which used 'Left' or 'Right' instead of picking out
a part of a string starting at a certain position and ending at a certain
position, or starting at a certain position and being of a certain length,
respectively. Imagine describing an algorithm that works on a string to
somebody via telephone. Would you say "Take the substring starting at
position 22 and ending at the string's end" or would you say "Take the
string's last three characters". I'd say the latter. Sure, taking the
start and end of a string /is/ taking /part of/ the string, but that's a
more general description of what is done.
When you just want part of a string, any part of the string, SubString or
just Mid is sufficient. Left & Right can be implemented in terms of
SubString or Mid themselves...
If I just want a part of the string that I don't have more information
about, I use 'Mid'. For the special cases, I prefer 'Right' and 'Left' for
the reasons described above.
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned.


If one uses SubString enough is this really an issue? In other words, they
soon pick up on:
- x.SubString(0, n) is Left
- x.SubString(n) is Right (not the same as VB.Right!)
- x.SubString(m,n ) is Middle


You definitely /can/ get used to it and then be able to use it without any
problems.

BTW: It's interesting that the method's name is 'Substring', but most
people refer to it as 'SubString', even those who are using case-sensitive
programming languages ;-).
Which if you believe Overloading is "evil", then yes I agree it may be
"weak semantics". However! I see overloading as a very powerful OO tool
(which like any construct can be easily abused), so the above does not
cause me any real issues... Info on "Overloadin g vs. Object Technology"
http://www.inf.ethz.ch/personal/meye...verloading.pdf
Thanks for the link, that's an interesting article. Well, I really liked
the sample of named constructors the author of the article you referenced
above gave... ;-). I believe in the power of overloading and I am confident
that it is a very powerful OO tool, but my concerns were not primarily
related to overloading in general.
I do find VB.Left, VB.Right, & VB.Mid can be "better" in that they have
more tolerant argument checking, which also makes String.SubStrin g
"better" as it insists on correct arguments!


:-)

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #18
Herfried,
BTW: It's interesting that the method's name is 'Substring', but most
people refer to it as 'SubString', even those who are using case-sensitive
programming languages ;-). I was using Substring (in this thread), but I "corrected" myself, as
SubString was used earlier in this thread...

Jay
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:Oy******** ******@TK2MSFTN GP09.phx.gbl... Jay,

"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> schrieb:
'Left', 'Mid' and 'Right' make it more obvious which part of the string
is returned, and thus make code more readable.

I agree it may be more obvious...

However! I'm just wondering about "weak semantics", to me saying it is
"weak semantics" is like insisting a glass is half full, when it is
obvious it is really half empty! Considering most of the time, it really
doesn't matter if I am getting the Left, Mid or Right of a string, I just
want a part of the string...


When learning string algorithms for university, I found those much clearer
and easier to understand which used 'Left' or 'Right' instead of picking
out a part of a string starting at a certain position and ending at a
certain position, or starting at a certain position and being of a certain
length, respectively. Imagine describing an algorithm that works on a
string to somebody via telephone. Would you say "Take the substring
starting at position 22 and ending at the string's end" or would you say
"Take the string's last three characters". I'd say the latter. Sure,
taking the start and end of a string /is/ taking /part of/ the string, but
that's a more general description of what is done.
When you just want part of a string, any part of the string, SubString or
just Mid is sufficient. Left & Right can be implemented in terms of
SubString or Mid themselves...


If I just want a part of the string that I don't have more information
about, I use 'Mid'. For the special cases, I prefer 'Right' and 'Left'
for the reasons described above.
the same, but the user will have to analyze the values passed to it in
order to be able to determine if the left, right, or an arbitrary part
(middle) of the string is returned.


If one uses SubString enough is this really an issue? In other words,
they soon pick up on:
- x.SubString(0, n) is Left
- x.SubString(n) is Right (not the same as VB.Right!)
- x.SubString(m,n ) is Middle


You definitely /can/ get used to it and then be able to use it without any
problems.

BTW: It's interesting that the method's name is 'Substring', but most
people refer to it as 'SubString', even those who are using case-sensitive
programming languages ;-).
Which if you believe Overloading is "evil", then yes I agree it may be
"weak semantics". However! I see overloading as a very powerful OO tool
(which like any construct can be easily abused), so the above does not
cause me any real issues... Info on "Overloadin g vs. Object Technology"
http://www.inf.ethz.ch/personal/meye...verloading.pdf


Thanks for the link, that's an interesting article. Well, I really liked
the sample of named constructors the author of the article you referenced
above gave... ;-). I believe in the power of overloading and I am
confident that it is a very powerful OO tool, but my concerns were not
primarily related to overloading in general.
I do find VB.Left, VB.Right, & VB.Mid can be "better" in that they have
more tolerant argument checking, which also makes String.SubStrin g
"better" as it insists on correct arguments!


:-)

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

Nov 21 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1824
by: Neil Zanella | last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is doing something I am not expecting. My understanding, according to the documentation of std::vector<>::resize(), is that when you specify a second argument the number of elements specified in the first argument is each in turn set to the second argument. void Foo::bar(int x) { static std::vector<int> foo; std::cout << "source: " << x << std::endl;...
2
2015
by: Lauren Wilson | last post by:
Hi folks, Just "upgraded" from A2K to A2K3. Everything is just hunky dory (so far) -- EXCEPT that the Add-in I had with A2K that auto inserts error code is no longer available in the Add-in manager or anywhere on my PC. I DO have the VSTO Access Developer Extensions installed for 2003. Anyone have a clue what happened to the Add-in? Is there another source for this Add-in? I have scoured the Microsoft web sites for
2
1811
by: N J | last post by:
Hi, Please take a look at http://webmonky.myby.co.uk/error.JPG . This is the second time this has happened. All I did was run command ... CurrentDb.Execute "Update tblDownload Set OrderType = """ & "REFUNDED" & """ Where ID = " & Me.Text43 & ";", dbfailonerror DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70 ....and access seems to make data turn into chinese charactors and put
1
2289
by: Mikey | last post by:
Can somebody tell me what happened to the Source Profiler? It used to be under the Build menu in VC6, but now it's gone, and I cannot find anything in the docs that say what happened to it. The docs now only say something about atttaching a third party tool, but do not give any hints of what that might be. Can the old VC6 profiler be used with a fresh VC .Net compile (totally unmanaged code). Any advice, hints, etc appreciated.
6
2731
by: SugarDaddy | last post by:
I'm pretty new to C#, but I've had a lot of experience with MFC. MFC had a mechanism for updating dialog controls using an idle message. For those unfamiliar, basically you would override OnIdle and call UpdateDialogControls(), and that would send WM_UPDATECOMMANDUI messages to all the controls in the dialog. Then you could add handlers for each control that you wanted to update. For example, if you wanted a button to be disabled if...
0
1365
by: han zhiyang | last post by:
I've just studied the "how to" web service and the async pattern in donnet.I make a test with these knowledges,but I got a strange result. Here is my test. 1.Write a simple "Add" service named MathWS( the class name),and put it in a ..asmx file named math.asmx in the "D:/winnt/interpub/wwwroot/mathws" directory. "mathws" is my new-built directory. 2.run the http://localhost/mathws/math.asmx,find it works well,and run run the...
7
1611
by: Mike Rand | last post by:
I am having a really hard time trying to get some client side code hooked up in VS2005, ASP 2.0. The code is in an .inc file (vbscript). The first problem I am encountering is the ASP.NET page doesn't like vbscript and throws fits about the syntax. Second, the page throws fits about the server side code tags (<% ... %>),...are these supported anymore? Third, when I set the onclick event of a client side HTML button it does not recognize...
1
1439
by: dkintheuk | last post by:
Hi all, Just had the wierdest thing happen overnight to one of my databases. I have a frontend/backend set up with the front end under development on my machine. I was copying a load of old files of the network while I had my front end performing some tasks overnight and I have managed to copy an old version of the front end over the version i had open. I didn't know I
3
2167
by: Giampaolo Rodola' | last post by:
http://groups.google.com/group/python-dev2 It seems it no longer exists. What happened?
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.