Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > BOOK: Visual Basic 2005 Programmer's Reference
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 12th, 2006, 11:26 AM
Registered User
 
Join Date: Mar 2006
Location: Hampton, VA, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB String Manipulation Functions

I could not find anything in your book about the string manipulation functions, so I went to the VB 2005 Online Help instead. According to Microsoft "Help" all these 1-based functions still exist in VB -- including Mid(), Left(), and Right(). Of course there are additional 0-based "methods" of string objects that do similar functions now.

Much of my old VB 6.0 Code is full of string manipulations, parsing the commands and responses to and from devices with serial port or ethernet interfaces. When I try to use these functions in my VB 2005 the Mid() function works, but the Left() and Right() functions do not. Intellisense finds valid Left() and Right() functions -- but these have nothing to do with strings.

Do you know why this compatibility problem exists, and can you verify that it exists or not in you own version of VB 2005?


Truman Byron Thomas
__________________
Truman Byron Thomas
Reply With Quote
  #2 (permalink)  
Old April 13th, 2006, 08:48 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

Those functions do still exist, although Microsoft doesn't really encourage their use. The "preferred" methods are the 0-based String methods such as String.Substring. (It's annoying that there are no String.Left and String.Right methods.)

But if you want the old functions, they're in Microsoft.VisualBasic.Strings. For example:

    left_text = Microsoft.VisualBasic.Strings.Left$("some text")

If you use them a lot (it sounds like you do), then you can use Imports to make it a bit easier:

    Imports Microsoft.VisualBasic.Strings
    ...
        left_text = Left$("some text")

I hope that helps.


Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm
Reply With Quote
  #3 (permalink)  
Old April 13th, 2006, 10:12 AM
Registered User
 
Join Date: Mar 2006
Location: Hampton, VA, USA.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for finding the Left and Right string functions for me. I have verified that the first part of your answer works on my VB 2005: That is, if you explicitly reference the function names by prefixing them with "Microsoft.VisualBasic.Strings.". However, when I added an
"Imports Microsoft.VisualBasic.Strings" statement just before the Public Class (form) statement, I could NOT remove the explicit reference. It gives a error. So in this case the Imports statement does not work.

Do you think this is a VS 2005 bug that should be reported to Microsoft?

Truman Byron Thomas
Reply With Quote
  #4 (permalink)  
Old April 14th, 2006, 09:02 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

Odd. That worked for me yestderday but not today. I think it's getting confused and trying to use a different namespace's version instead, probably the form's version of Left and Right which deal with the form's position not strings. Unfortunately I can't figure out how to change the order in which it searches namespaces to tell it to search Microsoft.VisualBasic.Strings before it searches System.Windows.Forms. Of course that would probably lead to confusion when you wanted to use the Forms properties.

You could report it as a bug but I suspect Microsoft will say this is by design. Because this is a VB 6 compatability issue, I doubt it would get high priority.

You could import Microsoft.VisualBasic and then use Strings.Left. Or you could define an alias for the import like this:

    Imports Str = Microsoft.VisualBasic.Strings
    ...
        left_text = Str.Left$("some text")

I think I would take one of these two approaches. Or use the newer String methods, even if they are less convenient for this.

Rod

Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm
Reply With Quote
  #5 (permalink)  
Old April 20th, 2006, 01:14 AM
Registered User
 
Join Date: Apr 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Byron, Rod,

The namespace and Imports behavior you describe here is similar to a problem I am having. The Imports statement does not seem to allow my VB.NET code to recognize that Exception is part of the System namespace. Check out my post “Compilation Error ASP.NET 2.0 & IIS 5.1” dated 4/17/2006 in the ASP and ASP.NET > ASP.NET 2.0 Beginner forum.

Did you get Compiler Error Message BC30392? Have you tried using the ASP.NET Development Server? That changes the behavior in my case and my code compiles. I also found that recoding in C# also allows the application to work!

G. Mitchell


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
String manipulation Franco1 Visual Basic 2005 Basics 1 July 16th, 2008 01:53 PM
String manipulation john316 SQL Language 1 October 1st, 2007 05:24 PM
String manipulation YoungLuke C# 4 May 4th, 2007 02:46 AM
String Manipulation twsinc Access 3 February 23rd, 2004 09:57 AM
String Manipulation with VB 6 Jay5817 Beginning VB 6 3 January 16th, 2004 02:08 PM



All times are GMT -4. The time now is 04:29 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.