MarkD Posted May 4, 2005 Posted May 4, 2005 I'm trying to do the following line of code to copy (in this case) a Date to a String (but I don't normally know what the objects are in advance): objTo = CType(objFrom, typename(objTo)) When I do "typename" is not resolved; I get a "not defined" msg when I hover the cursor over it. I AM using "Imports microsoft.VisualBasic.Information" as the first line in my module to call in the MS namespace. But that doesn't seem to resolve either, as when I type it in intellisense (or whatever it's called) wants to fill in the .VisualBasic and the .Information as I type in the dots. But when I leave the line the "m" in Microsoft. doesn't capitalize. what gives? Shouldn't importing be all I need to resolve things? and why no recognition on Imports stmt? Can I use TypeName function in this way for casting Quote
MarkD Posted May 4, 2005 Author Posted May 4, 2005 I got it! For future interest/reference... On further fooling around with it I discovered that I simply could not use another function within the Ctype as the system.whatevertype argument so, it's not very eloquent, but I had to do the following: Select Case TypeName(objTo) Case "Date" objTo = CType(objFrom, System.DateTime) Case "String" objTo = CType(objFrom, System.String) End Select glad I only have to deal with strings to dates or dates to strings on this one :) Quote
Administrators PlausiblyDamp Posted May 4, 2005 Administrators Posted May 4, 2005 What type is the variable objTo declared as? Just out of curiosity wher ewould it be getting a value assigned to it? Just not clear from the code posted what the benefit of the conversion would acheive. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
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.