6
Reply

How to set countdown to time from public string function?

Ask a question
Tommy

Tommy

11y
1.4k
1
Hi again,
This time I'm trying to work out on something possibly very simple but it's complete nightmare to understand, what am I doing wrong.

I have public string function which does some calculations and etc. Here's my function:
public string CompleteDateTime()
{
// Here's some info load from xml
string DisplayName = "Tommy";
string FinalTime = totaltime;
return FinalTime // At the moment it works well, return value is full date and time "12-01-2013 18:23:56";
}
PS Also, I would like to use other variables from this function globally. Example: call it from other functions and etc. Basically, I'm looking, if I can make function return multiple strings. What are the best methods for that?
Then I have the Timer where I'd like to do the countdown till the time returned from the function from above. My countdown code's here:
DateTime endTime = new DateTime(CompleteDateTime()); // <- THIS IS WHERE I GET THE ERRORS, AS I USE FUNCTION INSIDE THE BRACKETS BUT IT CAN'T BE FOUND EVEN IT'S PUBLIC. NOTE, IT IS FOUND IF I USE "CompleteDateTime()" INSIDE ANOTHER FUNCTION.
private void timer_Tick(object sender, EventArgs e)
{
TimeSpan ts = endTime.Subtract(DateTime.Now); // Subtracts time Now till the time returned in CompleteDateTime()

label1.Text = ts.ToString("'Time Remain' h':'m':'s"); // Returned value shall be counting down in this format "Time Remain 02:12:35"
}
After Timer counts down and is == "00:00:00" I'd like to recall my function "CompleteDateTime()" again so it retrieves the new Date and Time.
Please, if somebody has any idea for the code? What is best possible way to get it work? Searched online for samples, ideas but the ones I found work with other strings except DateTime.
Can somebody help me? Thank you in advance.

Tommy



Answers (6)