Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / July 2007

Tip: Looking for answers? Try searching our database.

Read and write to Console or a file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allen Maki - 21 Jul 2007 00:19 GMT
How come line 1 will output garbage to the screen, but line 2 will output a
good number to a file?

How can I make line 1 out put a good number to the screen

String* dayStr = System::DateTime::Now.ToString("dd");

Int32 dayInt = System::Int32::Parse(dayStr);

Console::WriteLine("the day is {0}", __box(dayInt) );     // Line 1

                                     .

                                      .

                                      .

String* path = new String("_1D.txt");  // will read the time from a file

FileStream * fs = new FileStream(path, FileMode::Open);

BinaryReade* br = new BinaryReader(fs);

Int32 day    = br->ReadInt32();

fs = new FileStream(S"_1k.txt", FileMode::Create); //will write the time to
another file

BinaryWriter* bw = new BinaryWriter(fs);

Br->Write( day);
//Line  2
Göran Andersson - 21 Jul 2007 18:25 GMT
> How come line 1 will output garbage to the screen, but line 2 will output a
> good number to a file?

What kind of "garbage"? The wrong number? Random characters? An exception?

> How can I make line 1 out put a good number to the screen
>
> String* dayStr = System::DateTime::Now.ToString("dd");
>
> Int32 dayInt = System::Int32::Parse(dayStr);

Why do you create a string and parse it? Why not simply:

Int32 dayInt = System::DateTime::Now::Day;

> Console::WriteLine("the day is {0}", __box(dayInt) );     // Line 1
>
[quoted text clipped - 5 lines]
>
> Int32 day    = br->ReadInt32();

You forgot to close the stream here.

> fs = new FileStream(S"_1k.txt", FileMode::Create); //will write the time to
> another file
[quoted text clipped - 3 lines]
> Br->Write( day);
> //Line  2

Signature

Göran Andersson
_____
http://www.guffa.com

Allen Maki - 22 Jul 2007 06:23 GMT
Hi Göran,

I really appreciate your help.  I learn a new way to deal with DateTime
which is (Int32 CurHour = System::DateTime::Now.Hour), but now I have a
problem.

Format1(your format):  Int32 dayInt = System::DateTime::Now.Day;

Format 2 (The one I use before):  Int32 dayInt = System::Int32::Parse(dd);

                                                                       Int32
CurHour = System::DateTime::Now.Hour;

Now, after I use format 2 instead of format 1, the things went to the
opposite, which is I get garbage (random character) when I write to files
and get good numbers when writing to the screen.

To answer your questions:

Why do you create a string and parse it?

The answer is, that was the only way for me to get good number into the
file.

What kind of "garbage"? The wrong number? Random characters? An exception?

The answer is Before I was getting wrong numbers.

>> How come line 1 will output garbage to the screen, but line 2 will output
>> a good number to a file?
[quoted text clipped - 29 lines]
>>
>> Br->Write( day); //Line  2

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.