Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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 :)

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