Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 03 Apr 2011
Offline Last Active Apr 15 2012 03:01 PM

#4930577 need some help with code(noob)

Posted by on 12 April 2012 - 08:26 AM

Hi Scrap, I just wanted to mention something that would hopefully make your life easier in the future. When comparing characters such as y, Y, n, and N, you can force the comparison to be either all lower case or all upper case which would be useful in this instance.

You could turn the following:
if (again1 == "n" || again1 == "N")

if (again.ToUpper() == "N")

and it would take whatever was in the variable 'again' and capitalize it for the comparison. It's important to note that it wouldn't save it as upper case beyond this statement. For that you would need to do
again = again.ToUpper()

I hope that's helpful.

#4849961 [.net] .NET in .exe?

Posted by on 16 August 2011 - 12:26 PM

The PC(s) you intend to execute the program on need to have the .NET framework version (1.1, 2.0, 3.5, etc) you used to compile the program.

#4794044 Problem writing string array's to text file.

Posted by on 03 April 2011 - 09:56 PM

Well set it to loop but now I'm having a problem with the File.WriteAllText line. The problem is that when debugging I get the NotSupportedException pop up. I can't see what I'm doing wrong Posted Image

Here's the new code

Fixed now :)

I think there's a few things you can improve on here.

for (int i = 0; i < 5; i++)
   	SheetWriter = contents[i] + "\r\n";

For this loop, SheetWriter is just a string right? If you want to keep appending contents[i] with the carriage return, you need to use += or you'll just keep rewriting the data every iteration. Though it's not super important in this example, you can also use contents.Length for your loop and if you ever need to change the size of your array someday you won't have to worry about hardcoding the iterations.

Lastly for writing the data to file, you can just use a string array, but I believe you need to use File.WriteAllLines. It takes the same arguments as WriteAllText but it should write the contents of an array.

File.WriteAllLines( file_name, contents ); 

Here's the example on msdn: http://msdn.microsof...y/92e05ft3.aspx

That should work, but I'm going off memory right now so my syntax might be off. Hope that helps.