Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 12th, 2008, 3:54 PM   #1
Jewel
Programmer
 
Join Date: Feb 2008
Posts: 32
Rep Power: 0 Jewel is on a distinguished road
declare Timer.Interval from Options

I want to declare Timer.Interval from Options menu but got one problem = Cannot implicitly convert type 'string' to 'int'

Thanks.
__________________
C#
Jewel is offline   Reply With Quote
Old Jun 13th, 2008, 6:44 AM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: declare Timer.Interval from Options

I'm not sure what you're trying to ask, here. If it's simply that you have a string like "500", and you want to set an interval of 500, then you can parse the string into an integer. I like using the TryParse() method, because it returns a boolean (true/false) value indicating success, and if it's successful, it will 'fill in' the variable you give it. Here's a quick example:
string intervalString = "500";
int intervalInt;

if( int.TryParse(intervalString, out intervalInt) )
  MessageBox.Show("Value: " + intervalInt.ToString(), "Success");
else
  MessageBox.Show("String did not contain a text representation of an integer", "Error");
See how this works? You pass TryParse() a string, and a reference to the value to be filled in. The out keyword is necessary here; this tells the compiler that you're passing a reference to a value, and that the method you're calling will fill in the value using this reference. It's similar to the ref keyword, except with ref, you have to have the value initialized before the call (note we don't initialize it before calling TryParse()).

Another thing you should know is that all the fundamental types have a TryParse() method. You can use int.TryParse(), double.TryParse(), and so on. They all work in the same manner, with the only difference being the data type. Likewise, there is a Parse() method for built-in types, but I don't much like it, as it throws an exception if the string cannot be converted. I'd rather receive a simple success/failure indication, and handle things that way.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jun 13th, 2008, 7:58 AM   #3
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Re: declare Timer.Interval from Options

lectricpharaoh is so detailed when he explains his answers in his posts.... very well understood
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Install options for published applications Jabo Visual Basic .NET 0 May 13th, 2008 1:47 PM
java options asynchronous garbage collection secrecy230 Java 1 Mar 17th, 2008 1:54 PM
howto declare function in perl baldy1324 Perl 2 Nov 6th, 2006 9:22 AM
Defining and handling command-line options Jessehk Python 6 Mar 3rd, 2006 10:30 PM
Declare array of chars some1 C++ 1 Apr 28th, 2005 2:14 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC