VB.NET...Certain things a step backwards

mscott

Member
Joined
Jan 22, 2002
Messages
22
Location
PA
Im 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 youre manipulating is null /or nothing. Where youll 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 youre manipulation. Where the CStr and all its old VB6 cowarts(CBool, CDate, CInt, etc.) dont care.

Im 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.
 
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.
 
Clarify for THINKER

What Im talking about has nothing to do w/ database. Im talking straight VB.NET. Then what I stated earlier.
 
Also

Thanks, Thinker. I will try to be more specific from here on out.

I wasnt and didnt 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, Id 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 dont get what youre 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...
Code:
strMyString = "Now This is a test".Substring(4)
 
mscott: If theres a chance what youre manipulating could be equal to nothing, then you should be checking, period. If VB6 let you get away with it before (which Im not sure it did), then youll have to get used to it now. Its 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 doesnt 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