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
Loading

VulpesPosted Jan 23, 2013, 7:27 PM
TommyPosted Feb 6, 2013, 8:35 AM
VulpesPosted Jan 27, 2013, 6:33 PM
You can avoid such problems if you can get the user to enter the date in the format yyyy/mm/dd which always parses correctly whatever culture you're in. The trouble is that this is not a very natural format for most users.
TommyPosted Jan 27, 2013, 6:54 AM
Hi Vulpes,
Accept my apology for late replay. Thank you for the code, you really helped a lot :))
From what you've suggested earlier I've managed my code to work. Regarding jiggery time and that timer recall the function every second, I've came up with another solution. Basically, I've opened public string, which is being updated by the timer, since it starts. So it simply cleared previous problems.
Even I still have few issues due to DateTime, TimeSpan but overall it really is working well. Vulpes, I'd like to thank you one more time for your dedication to the community. Appreciate, how affective your help is. You really got me on the right direction.
Had few issues with DateTime but now all seems sorted. Just quick question, I've notices when for test I copied app to another pc with another region settings app kicks exception due to incorrect datetime format.
I've now used cultureinfo for that but still can't understand, why and when it is so important to use?
Greetings, Tommy
VulpesPosted Jan 24, 2013, 6:12 AM
TommyPosted Jan 23, 2013, 8:39 PM
Hi Vulpes,
Thank you and glad you turned again to help :))
I had no doubt that your code will turn me on the right direction. However, there's something I still cannot overcome. While I was still awaiting for replays to my query here, I was playing a bit with my versions of the code. Well, it was a bit longer (great word for that) but it was same outcome as your idea.
On a timer event I chose to use:
Record r = CompleteDateTime();
endTime = DateTime.Parse(r.FinalTime);
But, when it ticks the label.text and the countdown time is visually jiggery. Even my timer interval is set to 100.
I've got the feeling, when it's on Timer event, every second it recalls the whole function.
My idea of this is:
App starts, loadxml strings from the file (you helped me so much with that one), load "FullDate" onto public variable, timer starts and does the countdown till "FullDate" but DOES NOT relaod the whole functions that recall loadxml again. Not unless the timer hits 00:00:00
I just simply would like to keep fewer processes active every second. As it's not necessarily. I am sure it's possible somehow to do this way?? What do you think? Or I am trying to create something too unrealistic?
Thank you again for being so much helpful.