|
-
Aug 4th, 2002, 06:25 AM
#1
Thread Starter
Member
Ctype in VB.Net
Is there a function in the system.convert namespace that equals the ctype function ?
For example the Cdbl function is equal to the system.convert.todouble function.
-
Aug 5th, 2002, 08:30 AM
#2
System.Convert.ChangeType(object, typetochangeto)
-
Aug 5th, 2002, 04:23 PM
#3
Thread Starter
Member
Give me an example.
I have this piece of code:
Dim objControl As Control
Dim objPicBox As PictureBox
objPicBox = CType(objControl, PictureBox)
Show me how to do ....
-
Aug 5th, 2002, 04:52 PM
#4
Addicted Member
You can still use ctype
you can still use ctype.
Dim objControl As Control
Dim objPicBox As PictureBox
objPicBox = CType(objControl, PictureBox)
i believe that will work!?!
But i could be wrong, i do use it in my current application though
-
Aug 5th, 2002, 11:03 PM
#5
Lively Member
What's wrong with just using CType?
-
Aug 6th, 2002, 08:27 AM
#6
you use it the EXACT same way as CType
one reason not to use CType is that it is a part of the Microsoft.VisualBasic namespace that was added for backwards compatability. I myself try to avoid it becuase it is 1 less reference I need since that dll provides me nothing I cant do with the standard .NET classes.
-
Aug 6th, 2002, 12:16 PM
#7
Thread Starter
Member
Hey Cander,
did you ever try this ?
Check it out and you will see that it can't be used in the same way.
system.convert.changetype(objControl, PictureBox) does not work !
So try it and tell me how to do ... ( if you can )
-
Aug 6th, 2002, 12:26 PM
#8
hmm no I didnt try it, but according to the win class viewer, that is all you should have to do. Ill have to try it tomorrow when I get back to work.
-
Aug 6th, 2002, 12:29 PM
#9
ohh.try this
System.Convert.ChangeType(objcontrol, TypeOf(PictureBox))
maybe that will work..I dont have .NET where I am now, so I cant test.
-
Aug 6th, 2002, 12:42 PM
#10
Lively Member
Originally posted by Cander
one reason not to use CType is that it is a part of the Microsoft.VisualBasic namespace that was added for backwards compatability.
That's not true. There's absolutely nothing wrong with using that namespace. The one to avoid that's there for backwards compatibility is the Microsoft.VisualBasic.Compatibility namespace.
The Microsoft.VisualBasic namespace is an integral part of the VB.NET language. Check the documentation. Nowhere does it say that it's only for backwards compatibility. There's also a Microsoft.CSharp namespace. Is that one supposed to be for backwards compatibility, too?
-
Aug 6th, 2002, 12:50 PM
#11
Lively Member
Also, CType isn't even found in Microsoft.VisualBasic to begin with. This quote is straight out of Microsoft's documentation:
CType is compiled inline, meaning the conversion code is part of the code that evaluates the expression. Execution is faster because there is no call to a procedure to accomplish the conversion.
This means that all these substitutes you people are cooking up are actually slower.
CType is just VB.NET's implementation of casting. There's no reason to avoid it, just like there's nothing wrong with this line in C#:
int i=(int)longVariable;
Last edited by Tygur; Aug 6th, 2002 at 02:29 PM.
-
Aug 6th, 2002, 12:53 PM
#12
Thread Starter
Member
TypeOf(PictureBox) does not work
-
Aug 7th, 2002, 08:27 AM
#13
Originally posted by Tygur
Also, CType isn't even found in Microsoft.VisualBasic to begin with. This quote is straight out of Microsoft's documentation:
This means that all these substitutes you people are cooking up are actually slower.
CType is just VB.NET's implementation of casting. There's no reason to avoid it, just like there's nothing wrong with this line in C#:
int i=(int)longVariable;
Ok Im a retard!
I had assumed it was part of the backwards compat namespace....
-
Aug 7th, 2002, 05:24 PM
#14
yay gay
is there any option to put off the visual basic namespace so i just can't use its functions? it would be a good way to me get used to dont use it anymore
-
Aug 7th, 2002, 05:38 PM
#15
I found out something interesting today. The compiler already refs that namespace built into it, so it raelly doesnt matter.
-
Aug 7th, 2002, 11:02 PM
#16
Member
Originally posted by PT Exorcist
is there any option to put off the visual basic namespace so i just can't use its functions? it would be a good way to me get used to dont use it anymore
Yes! Just Right-Click on your project name in the Solution Explorer, then select Properties - Imports. In the “Project Imports:” list, delete Microsoft.VisualBasic. I strongly recommend adding the Microsoft namespace so that you don't have to include "Microsoft." in front of everything from the VisualBasic namespace. I did this early on in the program that I'm working on and I've NEVER regretted it. No more accidental MsgBox's for this guy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|