Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...