Check if user inserted value in a TextBox is a float

This is a discussion on Check if user inserted value in a TextBox is a float within the Windows Programming forums, part of the Platform Specific Boards category; How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Check if user inserted value in a TextBox is a float

    How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank you.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by jmarcos View Post
    How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank you.
    In what language?

    In C# you can use Parse or TryParse static method of Double
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Quote Originally Posted by jmarcos View Post
    How can I check if a user inserted value in a TextBox is a float value as I'm expecting. Thank you.
    In Windows programing, you can get the text from the textbox and later parse to see if there's a decimal dot inserted.
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Thank for your replys. I'm programming in C++. The IDE is M. Visual Studio .NET 2008
    Joelito, do you suggest me to parse all the text inside the textbox and check if each character is a digit or the decimal character ("." or "," - depending on my Windows configurations)? I could only accept one decimal character. There is no other solution? Thanks. Joao

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by jmarcos View Post
    Thank for your replys. I'm programming in C++. The IDE is M. Visual Studio .NET 2008
    Joelito, do you suggest me to parse all the text inside the textbox and check if each character is a digit or the decimal character ("." or "," - depending on my Windows configurations)? I could only accept one decimal character. There is no other solution? Thanks. Joao
    you can use streamstream to convert the string to float and see the state and buffer of the stream after the operation
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    My IDE is Microsoft Visual Studio .NET and I'm programming in C++.

    I have solved my problem, as you can see below:

    Code:
    using namespace System;
    
    bool good_parsing = Double::TryParse(TextBox->Text, my_double_result_value);

  7. #7
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Quote Originally Posted by jmarcos View Post
    My IDE is Microsoft Visual Studio .NET and I'm programming in C++.

    I have solved my problem, as you can see below:

    Code:
    using namespace System;
    
    bool good_parsing = Double::TryParse(TextBox->Text, my_double_result_value);
    Ow, in C++ .NET...lolz
    I hate .NET, :P
    I though you mean in pure Win32 API
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to read a txt file into an array
    By Hitsugaya_KK in forum C Programming
    Replies: 49
    Last Post: 08-22-2009, 03:22 PM
  2. Not working in linux...
    By mramazing in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2009, 02:18 AM
  3. Need help with program
    By HAssan in forum C Programming
    Replies: 8
    Last Post: 06-10-2007, 09:05 PM
  4. Multidimensional String
    By Beast() in forum C Programming
    Replies: 14
    Last Post: 07-03-2004, 01:47 AM
  5. Why does it work in Visual Studio and Not Borland
    By MonteMan in forum C++ Programming
    Replies: 14
    Last Post: 10-20-2002, 10:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21