|
-
Nov 25th, 2006, 04:28 PM
#1
Thread Starter
Frenzied Member
[2.0] Formatting Enabled?
Alright, let's cut to the chase. In Windows Applications, there is a Formatting Enabled field for the combobox. This would make this line of code work:
Code:
double calculation = Math.Round((Convert.ToSingle(cmbOutsideDiameter.Text) - (.01299 * Convert.ToSingle(txtPercentOfThread.Text) / Convert.ToSingle(txtThreadsPerInch.Text))), 3);
HOWEVER, I am now duplicating this program in a hand-held device and the compact framework doesn't have the Formatting Enabled field. The error I am getting because I cannot turn the Formatting Enabled thing on is, Format Exception is unhandled.
-
Nov 25th, 2006, 07:39 PM
#2
Re: [2.0] Formatting Enabled?
So are you saying that trying to convert the Text property of cmbOutsideDiameter to a Single fails?
The FormattingEnabled property of the ComboBox class indicates whether formatting is applied to the DisplayMember. For that to have any relevance to you it would have to mean that your ComboBox is bound to a data source. If that's the case then you don't need to convert anything to a Single because your data source must contain Single objects already.
-
Nov 25th, 2006, 09:22 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] Formatting Enabled?
Yup.. I should have looked at it more before posting. One thing went wrong, and as usual, before trying to even think about it, I just posted and wasted the whole day waiting for replys. I just looked at it now and realized I forgot to incorporate 2 methods in a seperate event handler to change the values of the combobox. I am so used to everything working so swimmingly that when one thing goes wrong, I instanly go and post about it isntead of thinking about it. I gotta break this habit X_X
-
Nov 25th, 2006, 09:23 PM
#4
Thread Starter
Frenzied Member
Re: [2.0] Formatting Enabled?
Well, while I still have a topic open, is it possible to combine these 2 lines into one?
Code:
double calculation = Math.Round((Convert.ToSingle(cmbOutsideDiameter.Text) - (.01299 * Convert.ToSingle(txtPercentOfThread.Text) / Convert.ToSingle(txtThreadsPerInch.Text))), 3);
txtHoleSize.Text = calculation.ToString("#.0000");
-
Nov 25th, 2006, 10:53 PM
#5
Re: [2.0] Formatting Enabled?
The result of Math.Round is the Double value that you want to turn into a string, so just tack the ToString onto Math.Round, i.e.:
Code:
txtHoleSize.Text = Math.Round(...).ToString(...);
-
Nov 26th, 2006, 12:45 AM
#6
Thread Starter
Frenzied Member
Re: [2.0] Formatting Enabled?
Yea it isn't working. I would of tried that. No intellisense is coming up or anything
-
Nov 26th, 2006, 06:15 PM
#7
Re: [2.0] Formatting Enabled?
I'm not quite sure why Intellisense doesn't kick in there but it is possible to write code without Intellisense. I just tried it by typing '.ToString("#.000")' myself and it worked exactly as expected. C# is case-sensitive so, of course, you have to use the correct character casing.
Also, it is preferable to use standard format strings rather than custom. If you want a value with four decimal places then you should use "n4" or "f4" as your format string. You'll generally find that "n4" will use thousand separators while "f4" will not.
Finally, you may have a reason but it seems odd to me that you're rounding the number to three decimal places and then showing it with four. That gives an inaccurate representation of the actual value.
-
Nov 26th, 2006, 11:54 PM
#8
Thread Starter
Frenzied Member
Re: [2.0] Formatting Enabled?
This program is for my dad, and it is EXACTLY how he wants it. I don't know his reasoning, but he just wants it that way. Lemme check typing it in without intellisense.
Wow.. Sunuva ***** VS didn't show intelisense. GRAR! What else isn't it showing me? *darting eyes*
Last edited by Fromethius; Nov 26th, 2006 at 11:58 PM.
-
Nov 27th, 2006, 01:59 AM
#9
Re: [2.0] Formatting Enabled?
VS doesn't show intellisense prompts on expressions.
-
Nov 27th, 2006, 02:44 AM
#10
Re: [2.0] Formatting Enabled?
 Originally Posted by penagate
VS doesn't show intellisense prompts on expressions.
The Intellisense in C# is better than in VB in several situations but this is one case where it's not because VB would list the members of the Double type in that situation while C# won't.
-
Nov 27th, 2006, 03:36 AM
#11
Re: [2.0] Formatting Enabled?
Yeah, I don't use VB so I couldn't compare. But, as far as my experience goes, VC# won't display the prompt on expressions, which leads me to suspect the type binding might be done at compile-time.
-
Nov 27th, 2006, 03:56 AM
#12
Re: [2.0] Formatting Enabled?
 Originally Posted by penagate
Yeah, I don't use VB so I couldn't compare. But, as far as my experience goes, VC# won't display the prompt on expressions, which leads me to suspect the type binding might be done at compile-time.
You are almost certainly correct about that because VB does perform background compilation (or whatever it's proper name is) which is how VB can flag compilation errors without requiring a build. The VB code IS compiled so Intellisense knows the type of the expression.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|