Advertisement

05.11.2006 at 09:59PM PDT, ID: 21847875
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Making TextBox handle Numeric values? [Visual C++]

Tags: textbox, visual, numeric
Hello,

Ok, here I am asking the same question again! I was thinking it is so basic an I would have no problem finding an answer in no time. But after searching and asking for days, I got nothing!

Here is the question:
 
A textbox control can handle  data of Text type only. For example, if I have a form with a TextBox named textBox1, and I have the following code under a button:

         int x;

         x = textBox1->text;

I woul get the following error when compiling:

      error C2440: '=' : cannot convert from 'System::String ^' to 'int'


The same applies to reading numeric values from a textbox.

Now, how can I change the data type of a textbox to integer or float so that it can handle numirec values?

Would appreciate any input.

Thank you in advance,

Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: Mahmoodaman
Solution Provided By: AlexFM
Participating Experts: 2
Solution Grade: A
Views: 200
Translate:
Loading Advertisement...
05.12.2006 at 01:44AM PDT, ID: 16665608

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 04:31AM PDT, ID: 16666495

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 05:44AM PDT, ID: 16666976

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 05:49AM PDT, ID: 16667023

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 06:07AM PDT, ID: 16667178

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 06:09AM PDT, ID: 16667209

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 08:26AM PDT, ID: 16668364

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 09:02AM PDT, ID: 16668713

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 10:11AM PDT, ID: 16669325

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 10:16AM PDT, ID: 16669354

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 10:41AM PDT, ID: 16669550

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.12.2006 at 10:52AM PDT, ID: 16669643

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.13.2006 at 07:04AM PDT, ID: 16673841

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.13.2006 at 07:12AM PDT, ID: 16673864

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.13.2006 at 10:45AM PDT, ID: 16674566

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.12.2006 at 01:44AM PDT, ID: 16665608

Rank: Master

convert string to int using function like atoi()

int x;
x = atoi(textBox1->text);

to convert to float you may use atof()

float x;
x  = atof(textBox1->text);

-MAHESH
 
05.12.2006 at 04:31AM PDT, ID: 16666495

Rank: Wizard

int x;

try
{
     x = Int32::Parse(textBox1->text);
}
catch (FormatException^ e)
{
   // handle error
}
catch (OverflowException ^ e)
{
   // handle error
}

Take a look also at MaskedTextBox class.
 
05.12.2006 at 05:44AM PDT, ID: 16666976
Thank you for your respones MAHESH,

I am getting this error:
  error C3861: 'atoi': identifier not found

Any idea what might be wrong?


 
05.12.2006 at 05:49AM PDT, ID: 16667023
Thank you for your response AlexFM,

I am gettin the following error when trying your code:

error C2248: 'System::Windows::Forms::Control::text' : cannot access private member declared in class 'System::Windows::Forms::Control  

Any idea what might be wrong?      
 
05.12.2006 at 06:07AM PDT, ID: 16667178

Rank: Wizard

Should be: textBox1->Text

I just copied your code, this was mistake.
 
05.12.2006 at 06:09AM PDT, ID: 16667209

Rank: Wizard

About atoi - you need to add appropriate include line: <stdlib.h>
But it is not good idea to use CRT functions in C++/CLI application. .NET contains all required functions and replaces CRT for managed code.
 
05.12.2006 at 08:26AM PDT, ID: 16668364
Thank you AlexFM,

I really appreciate your help.

I added #include<stdlib.h> and changed "text" to "Text". I am now getting the following error:

error C2664: 'atoi' : cannot convert parameter 1 from 'System::String ^' to 'const char *'

Would you please suggest a reason for this error?
 
05.12.2006 at 09:02AM PDT, ID: 16668713

Rank: Wizard

Please show your code. Where did you find char* in managed application? Do you use my suggestion with Int32::Parse or atoi function?
Again: you don't need atoi and stdlib.h, you need Int32::Parse.

General advice for everybody who starts working in C++/CLI: try C# first. There is no need to make Windows Forms application in C++/CLI. C# is much better for this purpose. C++/CLI should be used for interoperability, accessing unmanaged resources and legacy C++ code.
 
05.12.2006 at 10:11AM PDT, ID: 16669325
I am trying this on a form with just a textbox (named textBox1) and a button. Here is the code of the button:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
      int x;
      x = Int32::Parse(textBox1->text);
            
       }

This produces the following error:
error C2248: 'System::Windows::Forms::Control::text' : cannot access private member declared in class 'System::Windows::Forms::Control'

As for C#, is it of the same processing speed as C++? Actually, I have written a program in VB (where life is much easier!). But I am having a problem with its speed. I decided to convert it into C++ as it is the fastes programming language ,as far as I know.

So, how is the speed of C# copmared to C++?

Many Thanks
 
05.12.2006 at 10:16AM PDT, ID: 16669354
Sorry!
it is my mistake. I wrote "text", instead of "Text" here (it is the VB effect!)

Now how to deal with a float? and how is the speed of C#?

Sorry once again. . .
 
05.12.2006 at 10:41AM PDT, ID: 16669550

Rank: Wizard

Use Convert.ToSingle Method (String) method. It parses string and converts it to float value.
Convert class contains set of function for parsing all basic types.

float f;

try
{  
    f = Convert::ToSingle(textBox1->Text);
}
catch (FormatException^ e)
{
   // handle error
}
catch (OverflowException ^ e)
{
   // handle error
}

 
05.12.2006 at 10:52AM PDT, ID: 16669643

Rank: Wizard

About C++/CLI vs C#.
.NET contains number of languages: C#, VB .NET, C++/CLI etc. C# is better choice for programmer with C++ experience. VB is a good choice for VB6 programmer, though it looks like VB6, this means, not like "real" programming language. Microsoft encourages developers to work in C#, and gives better IDE support for this language. Some advanced language features of C# are not available in VB. C++/CLI has the same strength as C#, but it's syntax is more complicated and less readable. Create C# Windows Forms application and C++/CLI application, and you can see that C# looks much better.
All .NET languages are translated to the same intermediate langaage: MSIL. Different compilers (C#, BV, C++) convert source code to the same language. Performance of all .NET languages is absolutely the same.

So, why we need C++/CLI at all? It's strength is in interoperability. This language allows to call unmanaged code directly, which is impossible in C#. This allows to use legacy C++ code, access low-level API, write real time applications with hardware access, make time critical operations in unmanaged code. Here is the strength of C++/CLI. I beleive that we don't need C++/CLI unless we must do some unmanaged tasks.
 
05.13.2006 at 07:04AM PDT, ID: 16673841
Thank you for your reply AlexFM,

"Performance of all .NET languages is absolutely the same."

Does it mean that the running speed of a program built in C++ is the same as one built in VB?

Regards,
 
05.13.2006 at 07:12AM PDT, ID: 16673864

Rank: Wizard

Yes. To be presize: performance of programs written in C++/CLI, VB .NET and C# is absolutely the same.
I am not talking about: unmanaged C++, VB6 - these are different languages.
Accepted Solution
 
05.13.2006 at 10:45AM PDT, ID: 16674566

I find this really strange! If I knew this, I would have gone for VB.NET inctead of C++!

I will look into this.

Thanks a lot AlexFM
 
 
20080236-EE-VQP-29