homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam

The Geek Culture Forums


Post New Topic  New Poll  Post A Reply
my profile | directory login | | search | faq | forum home
  next oldest topic   next newest topic
» The Geek Culture Forums   » Other Geeky Stuff   » Ask a Geek!   » C #

 - UBBFriend: Email this page to someone!    
Author Topic: C #
stevenback7
SuperBlabberMouth!
Member # 5114

Member Rated:
4
Icon 1 posted January 17, 2009 14:41      Profile for stevenback7   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
Hey guys,

Okay, I'm trying to get the program to recognize the difference between a number being typed in and anything else being typed in. What is the simplest way to determine this. The program just needs to have a error message pop up if a word is typed in and just keep running with a number.

thanks

--------------------
Comic Book Guy: There is no emoticon for what i'm feeling.

Posts: 1199 | From: Canada eh? | Registered: May 2006  |  IP: Logged
Richard Wolf VI
SuperBlabberMouth!
Member # 4993

Icon 10 posted January 17, 2009 15:20      Profile for Richard Wolf VI   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
From what I know from Java, you may use a method as parseInt. In Java syntax, it would be:
code:
integer = Integer.parseInt(string);

Chacking in Wikipedia, the C# syntax is not so different:
code:
integer = int.Parse(string);

In Java, an invalid entry is treated with a NumberFormatException, so you may catch it like this:
code:
try{
integer = Integer.parseInt(string);
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(this,"Invalid value" ,"Error" ,JOptionPane.ERROR_MESSAGE)
}

In C# is almost just the same. Refer to your documentation to check for differences. Hope it helps [Smile]

--------------------
The same old iWanToUseaMac... Who am I fooling? I'm getting a Wii now, iWanToUseaMac isn't :P
Get Opera. The best web experience.
Contest. Group. Success.

Posts: 1356 | From: Bogotá, Colombia | Registered: Mar 2006  |  IP: Logged
GrumpySteen

Solid Nitrozanium SuperFan
Member # 170

Icon 1 posted January 17, 2009 17:21      Profile for GrumpySteen     Send New Private Message       Edit/Delete Post   Reply With Quote 
Assuming that you're working on a Windows platform...

http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx

--------------------
Worst. Celibate. Ever.

Posts: 6364 | From: Tennessee | Registered: Jan 2000  |  IP: Logged
stevenback7
SuperBlabberMouth!
Member # 5114

Member Rated:
4
Icon 1 posted January 17, 2009 18:34      Profile for stevenback7   Author's Homepage     Send New Private Message       Edit/Delete Post   Reply With Quote 
quote:
Originally posted by GrumpySteen:
Assuming that you're working on a Windows platform...

http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx

yeah, it is purely on a windows platform. I dunno if your suggestion is beyond the scope of the course though. I remember in the past with programming languages I just used a small trick to get past it.

--------------------
Comic Book Guy: There is no emoticon for what i'm feeling.

Posts: 1199 | From: Canada eh? | Registered: May 2006  |  IP: Logged


All times are Eastern Time  
Post New Topic  New Poll  Post A Reply Close Topic    Move Topic    Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:

Contact Us | Geek Culture Home Page

© 2015 Geek Culture

Powered by Infopop Corporation
UBB.classicTM 6.4.0



homeGeek CultureWebstoreeCards!Forums!Joy of Tech!AY2K!webcam