Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,383 VB.NET Programmers. There are 1,379 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Casting to an iFormatProvider?

 
Reply to this topicStart new topic

Casting to an iFormatProvider?

JasonMcAuley
post 9 May, 2008 - 07:22 AM
Post #1


D.I.C Head

**
Joined: 10 Apr, 2008
Posts: 122



Is it possible to cast something to an iFormatProvider?

I have a date that is going to dynamically change formatting; so I need to pass it a variable format.

Is it possible to pass a format to a control as a property and apply that format to an item under the control?

Example of how the format is being used in my control

CODE

Me.cvMaxDate.ValueToCompare = value.ToString(Format)


If I pass the Format mask to the control as an String, it won't allow me to use it in the ToString, and if I try to cast it to an iformatprovider, I get a cast exception.

I tried making the format property of data type iformatprovider; however when I pass the date format to the control with

CODE

Format="MM/dd/yyyy"


I get "Cannot create an object of type 'System.IFormatProvider' from its string representation 'MM/dd/yyyy' for the 'Format' property."


I just can't seem to get that dynamic format to work whatever I do!

Any help would be greatly appreciated!

User is offlineProfile CardPM
Go to the top of the page
+Quote Post


PsychoCoder
post 9 May, 2008 - 07:37 AM
Post #2


ToCode || !ToCode

Group Icon
Joined: 26 Jul, 2007
Posts: 5,858

You could always create a function that accepts an iFormatProvider value as a parameter

vb

Private Function FormatDate(format As iFormatProvider) As String

End Function


Here you would pass it the iFormatProvider you wish to format to and it will return your value, formatted the way you like. Just my 2¢
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

JasonMcAuley
post 9 May, 2008 - 07:48 AM
Post #3


D.I.C Head

**
Joined: 10 Apr, 2008
Posts: 122

But if I pass it to the control via the control properties, how can I receive it as a iformatprovider data type. The control properties won't accept a value of type iformatprovider.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/17/08 03:46AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month