StreamWriter.WriteLine and ConsoleWriter.WriteLine Question tia sal22

  • Thread starter ratullloch_delthis
  • Start date
R

ratullloch_delthis

StreamWriter.WriteLine and ConsoleWriter.WriteLine Question tia sal22

Greetings All
I have two lines that work seperatly but I'm having trouble
mergeing the togther to export the combined version to a text file

Example:
Console.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff", ci));
gives me: 12:04:2010:07:27:15.018

please note: this only shows up on the Console I'm not sure how
to export this out to a text file correctly


StreamWriter.WriteLine(String.Format("{0}{1},{2}", SampleCount * SamplePeriod, "\t\t", CurrentValue));
gives me: 1 78.9098

I would like the data to be exported to a text file like
12:04:2010:07:27:15.018, 78.9098

I tried combining them like
StreamWriter.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff, {0}", ci,CurrentValue));
hopeing this would give me
12:04:2010:07:27:15.018, 78.9098

but it doesn't I think it's because the CurrentValue variable is a double but I thought the toString would convert it.
Any ideas

tia sal22
 
A

Arne Vajhøj

StreamWriter.WriteLine and ConsoleWriter.WriteLine Question tia sal22

Greetings All
I have two lines that work seperatly but I'm having trouble
mergeing the togther to export the combined version to a text file

Example:
Console.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff", ci));
gives me: 12:04:2010:07:27:15.018

please note: this only shows up on the Console I'm not sure how
to export this out to a text file correctly

StreamWriter sw = new StreamWriter(yourfilename);
sw.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff", ci));
sw.Close();
StreamWriter.WriteLine(String.Format("{0}{1},{2}", SampleCount * SamplePeriod, "\t\t", CurrentValue));
gives me: 1 78.9098

I would like the data to be exported to a text file like
12:04:2010:07:27:15.018, 78.9098

I tried combining them like
StreamWriter.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff, {0}", ci,CurrentValue));
hopeing this would give me
12:04:2010:07:27:15.018, 78.9098

but it doesn't I think it's because the CurrentValue variable is a double but I thought the toString would convert it.
Any ideas

Try:

sw.WriteLine("{0}, {1}", now.ToString("MM:dd:yyyy:hh:mm:ss.fff", ci),
CurrentValue);

Arne
 
J

JK

W dniu 2010-12-04 22:27, ratullloch_delthis pisze:
StreamWriter.WriteLine and ConsoleWriter.WriteLine Question tia sal22

Greetings All
I have two lines that work seperatly but I'm having trouble
mergeing the togther to export the combined version to a text file

Example:
Console.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff", ci));
gives me: 12:04:2010:07:27:15.018

please note: this only shows up on the Console I'm not sure how
to export this out to a text file correctly


StreamWriter.WriteLine(String.Format("{0}{1},{2}", SampleCount * SamplePeriod, "\t\t", CurrentValue));
gives me: 1 78.9098

I would like the data to be exported to a text file like
12:04:2010:07:27:15.018, 78.9098

I tried combining them like
StreamWriter.WriteLine(now.ToString("MM:dd:yyyy:hh:mm:ss.fff, {0}", ci,CurrentValue));
hopeing this would give me
12:04:2010:07:27:15.018, 78.9098

but it doesn't I think it's because the CurrentValue variable is a double but I thought the toString would convert it.
Any ideas

tia sal22

You try use CurrentValue as TimeSpan;

JK
 
Top