EFileTahi-A Posted June 25, 2005 Posted June 25, 2005 StreamWriter strWriter = new StreamWriter(Application.StartupPath + "\\" + "bla.txt", false, System.Text.Encoding.BigEndianUnicode); strWriter.WriteLine(textBox1.Text); strWriter.WriteLine(textBox2.Text); strWriter.WriteLine(textBox3.Text); strWriter.WriteLine(textBox4.Text); strWriter.WriteLine(textBox5.Text); strWriter.WriteLine(textBox6.Text); strWriter.WriteLine(textBox7.Text); strWriter.WriteLine(textBox8.Text); strWriter.Close(); This creates a text file with following input: 1 2 3 4 5 6 7 8 Ok, but I want to read every line to a specific string variable. Why the F. does this F. S. reads only a few lines? why is it skiping lines? string sTemp1 = strReader.ReadLine(); //Assigns value 2 string sTemp2 = strReader.ReadLine(); //Assigns value 4 string sTemp3 = strReader.ReadLine(); //Assigns value 6 string sTemp4 = strReader.ReadLine(); //Assigns value 8 string sTemp5 = strReader.ReadLine(); //Null! string sTemp6 = strReader.ReadLine(); //Null! string sTemp7 = strReader.ReadLine(); //Null! string sTemp8 = strReader.ReadLine(); //Null! ??? Strangely enough, this it reads the text file well if I assign the values to textboxes instead! this.textBox1.Text = strReader.ReadLine(); //Assigns value 1 this.textBox2.Text = strReader.ReadLine(); //Assigns value 2 this.textBox3.Text = strReader.ReadLine(); //Assigns value 3 this.textBox4.Text = strReader.ReadLine(); //Assigns value 4 this.textBox5.Text = strReader.ReadLine(); //Assigns value 5 this.textBox6.Text = strReader.ReadLine(); //Assigns value 6 this.textBox7.Text = strReader.ReadLine(); //Assigns value 7 this.textBox8.Text = strReader.ReadLine(); //Assigns value 8 WHY!? Well if needed it will be pleasure to upload the project... Quote
Administrators PlausiblyDamp Posted June 25, 2005 Administrators Posted June 25, 2005 I would upload the project if I was you - nothing in the posted sample should cause that kind of behaviour. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted June 26, 2005 Author Posted June 26, 2005 (edited) Ok, here is the project... There is already a breakpoint in the part to be examinated...SaveEvent.zip Edited June 26, 2005 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted June 26, 2005 Administrators Posted June 26, 2005 In your load method change StreamReader strReader = new StreamReader(fs); to StreamReader strReader = new StreamReader(fs, System.Text.Encoding.BigEndianUnicode); and it should work. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted June 27, 2005 Author Posted June 27, 2005 I does not work. It acts exactly the same way... :( Quote
Administrators PlausiblyDamp Posted June 27, 2005 Administrators Posted June 27, 2005 Are you sure - works just fine here. Have attached a copy I've tested here and there are no problems.SaveEvent.zip Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted June 28, 2005 Author Posted June 28, 2005 Er... It does not work. Here is a shot of what happens: http://img.photobucket.com/albums/v698/EFileTahi-A/SaveEvent.jpg sTemp4 var is reading "8" when it should be holding "4". The rest of the vars (sTemp5, 6, 7 and 8) become null just like I described in the thread's opening post... I did not change anything from the project you post... I truly don't know what to do next... Quote
Administrators PlausiblyDamp Posted June 28, 2005 Administrators Posted June 28, 2005 Just re-ran it here and used both the bla.txt contained in the zip and also got the code to generate a new file. See attached screen shot to see all variables loaded correctly. I really can't see why it should fail on your pc as I have tried it on both 1.0 and 1.1 frameworks. Are you doing anything with the text file before loading it? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted June 28, 2005 Author Posted June 28, 2005 Well, I'm truly pisst off with this **** it always advance 2 lines. When the code focus on the first break point at sTemp1 the Readline holds "1", then, when I press F11 sTemp1 turns to 2 and the Readline becomes "3", sTemp2 will then hold 4 and Readline will read "5"... I give up... Thanks for your effort though. Quote
IngisKahn Posted June 29, 2005 Posted June 29, 2005 lol :) Look at your watch window. Quote "Who is John Galt?"
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 (edited) IngisKahn *** lol Look at your watch window. bri189a *** Yup, that would do it. That is TOO funny! Too funny? And why is that? You mean the "Function strReader.ReadLine evaluted and returned null" message? Have you guys (just for statistics) read carefully my first post? If so then you will both realise that strReader.ReadLine will be null after assigning sTemp4 string var. Plus, why does it work OK if using "strReader.ReadLine()" directly on textboxes instead of string vars? Yet, why does the project work fine at PlausibleDump sys and not at mines? Have you also read my last post where I explain the strange behaviour of strReader.ReadLine() advancing 2 lines at the time? Also... I brough the project to my job's computer and it works just fine... I wonder why it does not work at home... Here at my Job's VS .NET I can see the "locals" tab, at home I can't see it anywhere. How do I make it appear? Now, I am truly looking forward to listening to your theories once more (IngisKahn and bri189a comments). Probably another "genuine" lol as an answer... And just to finish. When I drag with mouse the "next line to read" (yellow line) back and forth over the sTemp1, 2, 3, 4, 5, 6, 7 and 8 the strReader.ReadLine() will automaticaly be executed, that is, it will advance for the next line from "bla.txt". I can see it's value change on the "watch tab" without me pressing F11 or F10, hell, without me pressing any key at all. What do you make of this? Edited June 29, 2005 by EFileTahi-A Quote
Administrators PlausiblyDamp Posted June 29, 2005 Administrators Posted June 29, 2005 Could you attach a copy of the text file that isn't reading correctly? Also if you take a text file from home to work can you read it okay? How about the other way round? Do you have any additional language / keyboard support installed on your home PC? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
bri189a Posted June 29, 2005 Posted June 29, 2005 Sorry, it one of those things I've done myself, (and probably the other) guy, and I've wasted time looking for...because I wasn't thinking about what the debug commands were doing the variables; it wasn't meant to be a jab at you...sorry...more of a laugh of 'hey, I'm not the only one who does this!', and I think we both thought you would see the problem if we pointed your focus to the watch window, I again I appologize. It's advancing twice because once it advances in your code, but then the watch advances it one too because the reader in the watch is by reference...now if it's still doing it after you remove the watch, then then I humbly withdraw my comment, but that is what seems to be the obvious problem as it stands now. Quote
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 Could you attach a copy of the text file that isn't reading correctly? Also if you take a text file from home to work can you read it okay? How about the other way round? Do you have any additional language / keyboard support installed on your home PC? Well I will take my .txt which was made here (at my job) back to home and see what happens. At home I think I have only one keyboard installed (two at best, portuguese and enlgish keyboard maps. But I doubt I have the english one, I always delete it after installing the sys)... PS: Where can I add the "LOCALS" tab? I have it here, but not at home... Quote
IngisKahn Posted June 29, 2005 Posted June 29, 2005 Jeez, lighten up. :) = happy/fun/good/nice Have you read my post? You have a function call causing side effects in the watch window. (BTW, VS 2005 won't evaluate functions with side effects in the debug windows.) Debug->Windows lets you display all the debug windows. Quote "Who is John Galt?"
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 Sorry, it one of those things I've done myself, (and probably the other) guy, and I've wasted time looking for...because I wasn't thinking about what the debug commands were doing the variables; it wasn't meant to be a jab at you...sorry...more of a laugh of 'hey, I'm not the only one who does this!', and I think we both thought you would see the problem if we pointed your focus to the watch window, I again I appologize. It's advancing twice because once it advances in your code, but then the watch advances it one too because the reader in the watch is by reference...now if it's still doing it after you remove the watch, then then I humbly withdraw my comment, but that is what seems to be the obvious problem as it stands now. Apologies accepted and that subject is already forgotten. Anyway, it does happen even after me removing the watch... What truly drives me mad is that everything works ok when I use textboxes to hold the RealLine() instead of string vars, even the watch will advance ok without skiping lines. Quote
thenerd Posted June 29, 2005 Posted June 29, 2005 Have you tried declaring the string variables BEFORE you assign values to them? string tempvar1; string tempvar2; string tempvar3; //... ... ... tempvar1 = strReader.ReadLine() tempvar2 = strReader.ReadLine() //... Quote
Administrators PlausiblyDamp Posted June 29, 2005 Administrators Posted June 29, 2005 If you put a watch on the variable rather than the .ReadLine() call does it work? It looks like the watch windows is calling the ReadLine method (which makes sense as that is the only way it can retrieve the data) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 Have you tried declaring the string variables BEFORE you assign values to them? string tempvar1; string tempvar2; string tempvar3; //... ... ... tempvar1 = strReader.ReadLine() tempvar2 = strReader.ReadLine() //... No, I did not, but even if this worked why should the other method work in all computers except mine? God damn... what is happening?. Here at my job it works JUST perfectly the minute I try it at home it will just act strange... Quote
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 If you put a watch on the variable rather than the .ReadLine() call does it work? It looks like the watch windows is calling the ReadLine method (which makes sense as that is the only way it can retrieve the data) I have had watch in both variables and .ReadLine() call which work all great... here, not at home. Does anyone think that I somehow managed to trigger a bug? Anyway, I will record my home desktop to some video format file for you guys to see it happen in real time. Quote
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 WOAH!!! This is heavy! Now is happening the same thing here at my computers job! LOL! I am going to record a video for you to see Quote
EFileTahi-A Posted June 29, 2005 Author Posted June 29, 2005 (edited) Ok, ok... I think I discovered the problem and I guess that bri189a is right after all: Originally posted by bri189a "It's advancing twice because once it advances in your code, but then the watch advances it one too because the reader in the watch is by reference...now if it's still doing it after you remove the watch, then then I humbly withdraw my comment, but that is what seems to be the obvious problem as it stands now." How the heck should I be able to debug this kind of code (reading line by line with streamReaders) having .NET plataform behaving this way whith active watchers? Here is a high quality movie showing the behaving of step-by-step and non-step-by-step watchers with StreamReader function...DotNET_Issue.zip Edited June 29, 2005 by EFileTahi-A Quote
bri189a Posted June 29, 2005 Posted June 29, 2005 Have the watch look at the variables being assigned rather than the output of the reader as PD mentioned. Quote
IngisKahn Posted June 29, 2005 Posted June 29, 2005 Also the Autos window is your friend. Quote "Who is John Galt?"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.