PDA

View Full Version : Need help to count KM


Heiko1
13th April 2008, 16:32
Hey guys i got a Kilometer counter. (Thanks Sean)

And my problem is now:
How i can save the counted Kilometers?
Can anybody help me, please?
It would be very nice :)

Greetings Heiko1

Thanks again Sean(mcgas001) 4 helping me.

Heiko1
13th April 2008, 16:41
How i add a Bonus counter?
This Bonus problem is fixed now :)

wheel4hummer
13th April 2008, 18:18
And my problem is now:
How i can save the counted Kilometers?

Write them to a text file?

Heiko1
13th April 2008, 18:20
yes but how?

DarkTimes
13th April 2008, 22:59
In C#...

float km = 57465.0f;
string path = "file.txt";

// Write to file
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path))
{
sw.WriteLine(km);
}

// Read from file
using (System.IO.StreamReader sr = new System.IO.StreamReader(path))
{
km = float.Parse(sr.ReadLine());
}

Heiko1
14th April 2008, 11:53
thank you very much

Heiko1
14th April 2008, 13:12
erm got a problem.

It dont save the Counted Kilometer :( at every reconect it stand there Km: 0.00 :(

Please Help me!

DarkTimes
14th April 2008, 18:55
It's kind of impossible to say without seeing the relevant code to be honest. It's very difficult to guess what the possible problems might be in code you've never seen.

Anyway, you could open up the text file to see if the correct values are actually being stored. If not then you know it's a problem with the way your storing it. If they are then it's probably a problem with the way you're reading it out.

Robbo01
15th April 2008, 08:28
erm got a problem.

It dont save the Counted Kilometer :( at every reconect it stand there Km: 0.00 :(

Please Help me!

Have you put something in that saves it every so often? or just when they disconnect that might help if u havnt done that

dougie-lampkin
15th April 2008, 11:37
It's easiest if you add a new line into FileInfo.UpdateUserLeave that saves the KM, and make it take a new argument (specified in the bit in brackets at the top...)

I'm never too great at describing things, but I hope that helps :shy: