Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


avelle

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

#4930577 need some help with code(noob)

Posted by avelle 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")

into:
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 avelle 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 avelle 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.


PARTNERS