Results 1 to 12 of 12

Thread: [2.0] Formatting Enabled?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

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


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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");

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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(...);
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2.0] Formatting Enabled?

    Yea it isn't working. I would of tried that. No intellisense is coming up or anything

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    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.

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2.0] Formatting Enabled?

    VS doesn't show intellisense prompts on expressions.

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Formatting Enabled?

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Formatting Enabled?

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width