Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Small Problem With Streamwriter...


  • Please log in to reply
9 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:12:21 AM

Posted 30 September 2008 - 02:32 PM

Im still making a small basic game whein there is a 5x5 grid (Already done :thumbsup:) and you kill things etc but when i write the exp money lvl i have to write it in an int not a string so i can add and + and -... heres my code for the login form...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FlumpRPG
{
	public partial class Login : Form
	{
		public Login()
		{
			InitializeComponent();
		}
		string[] login;
		string[] stats;

		private void button1_Click(object sender, EventArgs e)
		{
			login = new string[1];
			Town Town = new Town();
			TextReader tr = new StreamReader("account.txt");
			login[0] = tr.ReadLine();
			if (textBox1.Text == login[0])
				Town.Show();
			stats = new string[3];
			TextReader sr = new StreamReader("stats.txt");
			stats[0] = sr.ReadLine();
			stats[1] = sr.ReadLine();
			stats[2] = sr.ReadLine();
			if (Town.Visible == true)
				this.Close();
		}

		private void button2_Click(object sender, EventArgs e)
		{
			TextWriter tw = new StreamWriter("account.txt");
			tw.WriteLine(textBox3.Text);   
			tw.Close();
			TextWriter tw2 = new StreamWriter("stats.txt");
			tw2.WriteLine("1");
			tw2.WriteLine("0");
			tw2.WriteLine("0");
			tw2.Close();
		}
	}
}

Instead of tw2 writing in string i need it to be written in an int and loaded into an array (Already done) as an int...at the moment the array is still a string because i couldnt debug it when it was a int because it could not use the string from the .txt in the array.
Can you see a way around this?

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:21 PM

Posted 30 September 2008 - 02:35 PM

SomeIntObject.ToString();

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:12:21 AM

Posted 30 September 2008 - 03:13 PM

So...
[code=auto:0]
private void button1_click(object sender.EventArgs e)
{
int[] someint;
someint = new int[1];
//23 may be inside "", im not sure but easy to check.
someint[0] = 23;
TextWriter tw = new StreamWriter("someint.txt")
tw.Writeline.ToString(someint[0])
tw.Close();
}
[code/]

But this still dosent explain how to read as int. Would i use ToInt? I get the feeling ToInt dose not exist though.
Many thanks,
Wolfy87.

Edited by Wolfy87, 30 September 2008 - 03:22 PM.


#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:05:21 PM

Posted 30 September 2008 - 03:15 PM

No, it would be WriteLine(Someint.ToString);

To go back the other way you'd want
Someint = Integer.Parse(Somestream.ReadLine());

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:12:21 AM

Posted 30 September 2008 - 03:25 PM

ahh, i see but just to clarifi that i actually know what im writing, what dose parce do or mean?

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:21 PM

Posted 30 September 2008 - 03:46 PM

Parse is a function defined inside of the Integer class, and it is used to convert a string representation of a digit to a numerical data type.

#7 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:12:21 AM

Posted 30 September 2008 - 03:53 PM

Ok then thankyou for the definition, now i know whats going on in that line a bit more.

#8 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:12:21 AM

Posted 30 September 2008 - 03:58 PM

Am i right in saying that onece converted to an integer tha i can perform + or - etc on them? For i will need to do this to add onto the players Xp etc.

#9 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:21 PM

Posted 30 September 2008 - 04:06 PM

yes.

#10 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:12:21 AM

Posted 30 September 2008 - 05:07 PM

Thats all i needed to know, thankyou Billy3 and Groovicus.
Thankyou for your time,
Wolfy87




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users