Re: How to define the input type in TextBox?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



RickyChan wrote:
Dear David,

Thanks for you reply! I have following the book to write the program, it is show follow;

-----------------------------------------------------------------------------------------------------------------------------------

private: System::Void txtQty_TextChanged(System::Object^ sender, System::EventArgs^ e) {
int n500, n100, n50, n10, n1, amt, change;
try
{
amt=txtPrice->Text->ToInt32(0)*txtQty->Text->Text->ToInt32(0);
txtSum->Text=amt.ToString();
txtChange->Text=(txtPay->Text->ToInt32(0)-amt).ToString();
change=txtChange->Text->ToInt32(0);
n500=change/500;
change%=500;
n100=change/100;
change%=100;
n50=change/50;
change%=50;
n10=change/10;
change%=10;
lbl500->Text=n500.ToString();
lbl100->Text=n100.ToString();
lbl50->Text=n50.ToString();
lbl10->Text=n10.ToString();
lbl1->Text=n1.ToString();
}
catch(Exception *err)
{
return;
}
}
-----------------------------------------------------------------------------------------------------------------------------------


ToInt32(0)<------ From book explain, it is a 32-bit Integer when I input the number, but I can not run it on my computer.

The book is Visual C++ 2003. Can it running on Visual C++ 2008? If no, please give my any suggestion!

Ricky:

this is a question on managed C++ (.NET framework) so you would be better to ask it in the

microsoft.public.dotnet.languages.vc

newsgroup, or in the MSDN VC forum at

<http://forums.msdn.microsoft.com/en-US/vcgeneral/threads/>

You say your book in Visual Studio 2003, but you are using VS2008. The syntax for managed C++ was changed in VC2005, and your code appears to use that syntax (which is called C++/CLI). So your VS2003 book will not help you.

I would certainly recommend that you get a book on C++/CLI if you want to use it However I would also recommend that you consider carefully whether C++/CLI is the way you want to go; for most people using C# is a much better way to target the .NET framework.

As to your question, I am not an expert on managed coding, but it seems to me that you are not using the ToInt32() method correctly.

What do you mean by "but I can not run it on my computer"? When you have a problem, you need to describe exactly what happened, and what you had expected to see.

--
David Wilkinson
Visual C++ MVP
.



Relevant Pages

  • Re: How to define the input type in TextBox?
    ... Because my English is not good, ... The syntax for managed C++ was changed in VC2005, and your code appears to use that syntax. ... I would certainly recommend that you get a book on C++/CLI if you want to use it However I would also recommend that you consider carefully whether C++/CLI is the way you want to go; for most people using C# is a much better way to target the .NET framework. ...
    (microsoft.public.vc.language)
  • Re: VB.NET Product Lifecycle
    ... Another good thing about VB syntax is that when I need a variable, I first think about variable name and then about its type. ... And in these days, with powerful hardware and the great MSFT .NET framework, I think that the domain of use of VB can be greatly extended (while in the past VB6 could have been considered sometimes a good option to develop just fast tools, and e.g. C++/MFC the platform for professional applications, I belive that things have changed a lot in these modern days). ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Total newbie (experienced C++ dev) looking for C# with ASP.Net
    ... If you're starting out i'd recommend the following books for ASP.NET, ... the .NET framework in general: ... >>> I've got Java EJB experience as well, I assume that there are session>>> contexts of some sort for state persistance betwixt pages. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: 2 ways to close a connection
    ... and the most respected .NET Framework technical authors such ... > as Jeffrey Richter - you may choose to use Dispose only where it helps. ... > recommend using Dispose on every .NET Framework object. ... > This is not my recommendation to expert programmers who know "where it ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A newbie question
    ... I recommend against using such a rule. ... What I recommend is that you think about what precision is appropriate ... If you think of it as being part of the syntax ... In your case the meaning is the precision. ...
    (comp.lang.fortran)