473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

IFormatProvider

Que
Hi

The I wrote the following Code

If Not txtInvoice.Text = "" Then

txtInvoice.Text =
Convert.ToInt32(txtInvoice.Text()).ToString("00000 0")

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

Sep 18 '06 #1
3 5538
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.

http://msdn.microsoft.com/library/de...lasstopic.aspI hope this helps,Cor"Que" <aq********@gmail.comschreef in berichtnews:11**********************@i3g2000cwc.go oglegroups.com...Hi>The I wrote the following Code> If Not txtInvoice.Text = "" Then> txtInvoice.Text =Convert.ToInt32(txtInvoice.Text()).ToString("0000 00")> End If>txtInvoice is a TextBox>I use FxCop and it says I should rewrite the code with the followingresolution>"frmInvoiceDetail.txtInvoice_L eave(Object, EventArgs) :Void makes a call toSystem.Convert.ToInt32(System.String) that does not explicitly provide an IFormatProvider. This should be replaced with a call toSystem.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>RegardsAQ>

Sep 18 '06 #2
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

Sep 18 '06 #3
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

"Que" <aq********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi

The I wrote the following Code

If Not txtInvoice.Text = "" Then

txtInvoice.Text =
Convert.ToInt32(txtInvoice.Text()).ToString("00000 0")

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

Sep 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: XmlAdoNewbie | last post by:
Hello All, I am trying to bind a date in the form of "20031218" to a datetime object. I first try to convert the string using Convert.ToDateTime("20031218") but i get an invalid date time...
0
by: Kolmi | last post by:
Has anyone come across a solution to this ? To format a value into an Sql Server sql string, I want to use the call Convert.ToString( value, new MyFormatProvider() ); Why I have to do this...
1
by: vooose | last post by:
Consider an application which has *many* references to DateTime.Parse(string); Is there a way, say when the application first starts up to force this method to use a specific IFormatProvider,...
1
by: Eric Gofoth | last post by:
Hello There doesn't appear to be an iformatprovider for to specify the format to convert a boolean to. i.e. MyBool.ToString("YES/NO") does not work Any workarounds?
3
by: Rich Robinson | last post by:
Hi, I have a web service method which takes a DateTime type as a parameter. The service is UK based, and the dates are passed in to the service in the UK format dd/MM/yyyy. On a recent...
5
by: Greg | last post by:
I can see there is no simple way to define a type like just a simple C++ typedef, such as typdef signaltype double; Using #define seems like a bad idea if it works atall. Using a struct...
5
by: shofu_au | last post by:
Hi Readers, I am Pascal programmer who is converting a program to C#. I would like know how to define the following data types in C#. Q1. A data type that can have a range 1..13 Q2. A...
6
by: Andy B | last post by:
I need to take the value of a textbox and format it in a more readable date. How do you do this? I tried textbox.text.tostring("date format string") but the compiler doesnt like that idea... any...
4
by: 0to60 | last post by:
I have to write to a fixed field file, and I have to format my numbers in a particular way. I have to front pad them with 0's, and I have to write the decimal value 3.14 as "314". So for example,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.