Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
if (Convert.ToInt32(Txtfrst.Text) > Convert.ToInt32(Txtsecnd.Text))
                Txtresult.Text = Convert.ToString(Convert.ToInt32(Txtfrst.Text) - Convert.ToInt32(Txtsecnd.Text));
            else
            {
                MessageBox.Show("please enter frstno greater than second number");
                alert("frst no shd be greatr than secnd");
            }


What I have tried:

i tried to print message in message box or as an alert
Posted
Updated 29-May-17 21:43pm
v2
Comments
Richard MacCutchan 30-May-17 3:25am    
Use proper value types for your converted numbers so you can see exactly why your code does not work. And use proper words in your messages not childish txtspk.
Suvendu Shekhar Giri 30-May-17 3:36am    
Are you getting any error?

1 solution

"MessageBox" and "alert" are incompatible: they are used in different environments.
MessageBox is only applicable to Windows applications - if you try to use them in web projects, they will not work.
Alert is only applicable to web projects - they can't be used in Windows projects.
And probably, your problem is that Convert.ToInt32 is a bad idea. If the value you try to convert is not a valid integer, it throws an exception - and your Windows application (or thread) will crash unless you catch it, or your web application will fail and probably show no response.
Trying to use them both is a recipe for disaster, as MessageBox is modal and will do nothing until the user - who can't see it - clicks a button.

Instead of Convert, always use TryParse, and report problems properly:
C#
int first;
if (!int.TryParse(txtfrst.Text, out first))
   {
   ... report problem to user ...
   return;
   }
You can then use converted values in your validity tests without risk of your app crashing.
And work out what system you are working on, and look for the appropriate communication method!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900