VB.NET...Certain things a step backwards

mscott

Newcomer
Joined
Jan 22, 2002
Messages
22
Location
PA
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.
 
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.
 
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.
 
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.
 
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...
Visual Basic:
strMyString = "Now This is a test".Substring(4)
 
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.
 
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.
 
Back
Top