mscott Posted September 19, 2002 Posted September 19, 2002 I'm doing some string manipulation in VB.NET. In previous versions of VB, if you wanted to covert something to String you would use the CStr(or ToString, if available). Now in .NET, since everything is more object based, you can use the ToString everywhere. Not so fast my friends..... The catch is if what you're manipulating is null /or nothing. Where you'll receive errors, if you try and use any of the string instance methods. Obviously the solution is to do an Is Nothing check on what you're manipulation. Where the CStr and all it's old VB6 cowarts(CBool, CDate, CInt, etc.) don't care. I'm trying to get away from using on VB6 stuff(especially since Microsoft has taken other stuff from VB6 and not included it all), and use what VB.NET provides. It just seems like a step backward having to do an Is Nothing check anytime I want to convert data types. If anyone has found some ways around this /or information on this, please share. Thanks. Quote
*Gurus* Thinker Posted September 19, 2002 *Gurus* Posted September 19, 2002 I am not getting what you are asking. You could never use CStr on an object in VB6? And an object being Nothing is not the same as a database datafield being Null. Quote Posting Guidelines
mscott Posted September 19, 2002 Author Posted September 19, 2002 Clarify for THINKER What I'm talking about has nothing to do w/ database. I'm talking straight VB.NET. Then what I stated earlier. Quote
mscott Posted September 19, 2002 Author Posted September 19, 2002 Also Thanks, Thinker. I will try to be more specific from here on out. I wasn't and didn't say you could CStr an object in VB6. Maybe I should have been more clear, but I figured someone named Thinker would be able to see, that I was speaking generally. If anyone has any information on what I stated earlier(first post), it would be greatly appreciated. Like I said, earlier, I'd hate to have to use Is Nothing checks everywhere I convert data types. Thanks again. Quote
reboot Posted September 19, 2002 Posted September 19, 2002 Is Nothing is for objects. Like Thinker said, you could never CStr an object in VB6. I really don't get what you're trying to say either. Quote
*Gurus* Thinker Posted September 19, 2002 *Gurus* Posted September 19, 2002 Does it help to say that in VB6, strings were simple datatypes, and in VB.Net, they are objects with properties and methods? Do you know you can do this in VB.Net... strMyString = "Now This is a test".Substring(4) Quote Posting Guidelines
*Gurus* divil Posted September 19, 2002 *Gurus* Posted September 19, 2002 mscott: If there's a chance what you're manipulating could be equal to nothing, then you should be checking, period. If VB6 let you get away with it before (which I'm not sure it did), then you'll have to get used to it now. It's called good programming practice. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
reboot Posted September 19, 2002 Posted September 19, 2002 vb.Net is much 'tighter' than previous versions of vb. This is a good thing. When you run across things that vb.Net doesn't let you get away with anymore, keep in mind it was more than likely a bad thing to be able to do in the first place. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.