Home All Groups Group Topic Archive Search About
Author
18 Sep 2006 2:49 PM
Que
Hi

The I wrote the following Code

        If Not txtInvoice.Text = "" Then

            txtInvoice.Text =
Convert.ToInt32(txtInvoice.Text()).ToString("000000")

        End If

txtInvoice is a TextBox

I use FxCop and it says I should rewrite the code with the following
resolution

"frmInvoiceDetail.txtInvoice_Leave(Object, EventArgs)
                   :Void makes a call to
System.Convert.ToInt32(System.String)
                   that does not explicitly provide an IFormatProvider.
                    This should be replaced with a call to
System.Convert.ToInt32(
                   System.String,System.IFormatProvider)."

What does it mean that I should Provide an IFormatProvider.

What is IFormatProvider

How does this work

Excuse me for my ignorance

Thanks in Advance

Regards
AQ

Author
18 Sep 2006 5:12 PM
Cor Ligthert [MVP]
Que,

This should be enough, I never know what character has to be for those
question marks.

Cint(txtInvoice.Text)ToString(????????)

Maybe you can try it yourself.

Show quoteHide quote
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationnumberformatinfoclasstopic.aspI hope this helps,Cor"Que" <aq.maho***@gmail.com> schreef in berichtnews:1158590996.295164.205***@i3g2000cwc.googlegroups.com...> Hi>> The I wrote the following Code>>        If Not txtInvoice.Text = "" Then>>            txtInvoice.Text => Convert.ToInt32(txtInvoice.Text()).ToString("000000")>>        End If>> txtInvoice is a TextBox>> I use FxCop and it says I should rewrite the code with the following> resolution>> "frmInvoiceDetail.txtInvoice_Leave(Object, EventArgs)>                   :Void makes a call to> System.Convert.ToInt32(System.String)>                   that does not explicitly provide an IFormatProvider.>                    This should be replaced with a call to> System.Convert.ToInt32(>                   System.String,System.IFormatProvider).">> What does it mean that I should Provide an IFormatProvider.>> What is IFormatProvider>> How does this work>> Excuse me for my ignorance>> Thanks in Advance>> Regards> AQ>
Author
18 Sep 2006 7:11 PM
Que
hi

thanks for the quick reply.
i do have that code,as you suggested
what i needed to know is how and why should IFormatProvider be
implimented and used

thanks again.
Que
Author
18 Sep 2006 7:41 PM
Claes Bergefall
An IFormatProvider provides culture specific information regarding how
dates, numbers etc are formatted (since different countries has different
rules). The Convert.ToInt32 method you are calling uses an IFormatProvider
that matches the settings you have in the regional settings in your control
panel. If you're getting input directly from the user this is most likely
the behaviour you want (I'm guessing that txtInvoice is a txtbox or
similar). If you need to transfer data between systems using different
country settings you need to use a common format for it so that each system
interprets it the same way (for example; 12.3 is not the same thing in
Sweden as it is in the US). That's when you specify a specific
IFormatProvider that uses the common rules that you need.

In your case it looks like FxCop is a bit overprotective. If you want to get
rid of the warning change your line to:
Convert.ToInt32(txtInvoice.Text,
CultureInfo.CurrentCulture).ToString("000000")
This is what the framework does for you internally anyway when you use the
version with only one parameter

   /claes

Show quoteHide quote
"Que" <aq.maho***@gmail.com> wrote in message
news:1158590996.295164.205770@i3g2000cwc.googlegroups.com...
> Hi
>
> The I wrote the following Code
>
>        If Not txtInvoice.Text = "" Then
>
>            txtInvoice.Text =
> Convert.ToInt32(txtInvoice.Text()).ToString("000000")
>
>        End If
>
> txtInvoice is a TextBox
>
> I use FxCop and it says I should rewrite the code with the following
> resolution
>
> "frmInvoiceDetail.txtInvoice_Leave(Object, EventArgs)
>                   :Void makes a call to
> System.Convert.ToInt32(System.String)
>                   that does not explicitly provide an IFormatProvider.
>                    This should be replaced with a call to
> System.Convert.ToInt32(
>                   System.String,System.IFormatProvider)."
>
> What does it mean that I should Provide an IFormatProvider.
>
> What is IFormatProvider
>
> How does this work
>
> Excuse me for my ignorance
>
> Thanks in Advance
>
> Regards
> AQ
>