urgent..pzzz!!
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
I can't see where anything would be written twice, unless you have something in your arraylist_points array twice.. How do you separate the start and end points when you read them in since they've been concatenated? Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
I can't see where anything would be written twice, unless you have something in your arraylist_points array twice.. How do you separate the start and end points when you read them in since they've been concatenated? Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
heloo my friend..okie my for loop like that : for (int j=0; j < arraylist_points.Count; j++){...} so lets say i draw squar then line ..it will be saved in text file as..: Line {X=83,Y=58}{X=257,Y=172} Line {X=165,Y=55}{X=71,Y=251} its should write squar then line..not line twice..!!:confused:
-
heloo my friend..okie my for loop like that : for (int j=0; j < arraylist_points.Count; j++){...} so lets say i draw squar then line ..it will be saved in text file as..: Line {X=83,Y=58}{X=257,Y=172} Line {X=165,Y=55}{X=71,Y=251} its should write squar then line..not line twice..!!:confused:
Cool but the code you posted doesn't show anything except looping through an existing array. If DrawWhat==1 it writes a bunch of lines (in a loop) If DrawWhat==2 it writes a bunch of squares (in a loop) If you want them written in a different order than that you'll need to code it that way :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
mr jets wrote:
for(int j=0;j {
Check 'Ignore HTML tags in this message' to make your code render properly. Have you stepped through the code ? Have you made sure the last item isn't actually in the list twice ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
helloo guys..okie iam creating acode that can draw different shapes(lines, squar,..etc)thats done then save their info in text file ..(like the start point ,end point,..etc)..thats cool too ; BUTT the problem is its writting the last thing i draw ..(if i draw line then squar ..it writes squar twice):confused: // save the file string str_Line; System.IO.FileStream fs = new System.IO.FileStream("c:\\graphics.txt", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite); StreamWriter streamWriter=new StreamWriter(fs); if(drawwhat==1) { for(int j=0;j less than arraylist_points.Count;j++) streamWriter.WriteLine("Line"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } else if(drawwhat==2) { for(int j=0;j { streamWriter.WriteLine("squar"); start=(Point)arraylist_points[j]; end=(Point)arraylist_points[j+1]; str_Line=start.ToString()+end.ToString(); streamWriter.WriteLine(str_Line); j++; } } streamWriter.Flush(); streamWriter.Close(); fs.Close(); } //plzz brothers iam stuck !
mr jets wrote:
BUTT the problem is its writting the last thing i draw
As I tell my team. When faced with a bug/issue you cannot explain, start verifying your assumptions. Step through the code with a debugger, generate a smaller sample to easily step through. If the bug is consistant, then you can reduce it to 2 or 3 shapes and still get the extra item, so single step through inspecting values. Debugging isn't magic, its just research into how the computer is dealing with your code, and finding where what you told it is inconsistant with what it is doing. If you don't have a debugger, message boxes, print displays and other items have been an age-old custom to watching computer activity as it happens.
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)