Author |
Message |
RealityFix
|
Posted: Tue Nov 17, 2009 9:11 am Post subject: Opening Files[C Sharp] |
|
|
What I basically want to do is open a file and make the program grab the files that are in the folder. Oh have some sort of way to use two files at once.
Im making a little program where a person makes a list of players and monsters and I hate using datafiles. I kinda suck at them >.>
So I just think it would be easier to use two seperate files then one file holding monsters and players.
Any tips? or Better ways to pull this off? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
rdrake

|
Posted: Tue Nov 17, 2009 10:23 am Post subject: RE:Opening Files[C Sharp] |
|
|
Check out the following static method.
C#: | System.IO.Directory.GetDirectories(string dir) | .
Personally I'd look into serialization in order to store your settings and states. It's pretty easy. |
|
|
|
|
 |
RealityFix
|
Posted: Wed Nov 18, 2009 5:27 pm Post subject: RE:Opening Files[C Sharp] |
|
|
Any links to that serialization? I just want the easiest way possible at doing this >.>
Me = crappy at datafiles ;_; |
|
|
|
|
 |
jbking
|
Posted: Wed Nov 18, 2009 5:41 pm Post subject: Re: Opening Files[C Sharp] |
|
|
RealityFix @ Tue Nov 17, 2009 7:11 am wrote: What I basically want to do is open a file and make the program grab the files that are in the folder. Oh have some sort of way to use two files at once.
Im making a little program where a person makes a list of players and monsters and I hate using datafiles. I kinda suck at them >.>
So I just think it would be easier to use two seperate files then one file holding monsters and players.
Any tips? or Better ways to pull this off?
Why not use a command line interface to input data? Under the command line interface you could ask how many players and monsters should be generated, name them and then build the lists from some simple input. You don't need no stinkin' no files, IOW. |
|
|
|
|
 |
rdrake

|
|
|
|
 |
RealityFix
|
Posted: Thu Nov 19, 2009 1:47 pm Post subject: RE:Opening Files[C Sharp] |
|
|
this program has to use datafiles. Its what the whole assignment is about. The user has to be able to save and open the files and such.
Thanks rdrake.
The site uses some functions we haven't been taught yet in C#.
Is there a slight possibility of a easier technique? |
|
|
|
|
 |
jbking
|
Posted: Thu Nov 19, 2009 2:15 pm Post subject: Re: RE:Opening Files[C Sharp] |
|
|
RealityFix @ Thu Nov 19, 2009 11:47 am wrote: this program has to use datafiles. Its what the whole assignment is about. The user has to be able to save and open the files and such.
Ah, that wasn't stated in the initial post. Some people do these kinds of things for fun.  |
|
|
|
|
 |
RealityFix
|
Posted: Sat Nov 21, 2009 3:59 pm Post subject: RE:Opening Files[C Sharp] |
|
|
Well I'm not having fun with this >.> To damn irritating. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
RealityFix
|
Posted: Mon Nov 23, 2009 3:59 pm Post subject: RE:Opening Files[C Sharp] |
|
|
Hate to double post but I get this weird error and i have no idea what to do with it >.>
Quote:
Error 1 Static member 'DungeonsAndDragons.SearchAndSort.Shell(string[], string[], int)' cannot be accessed with an instance reference; qualify it with a type name instead C:\Documents and Settings\Owner\Desktop\DungeonsAndDragons2\DungeonsAndDragons2\DungeonsAndDragons\DungeonsAndDragons\DungeonsAndDragons\Form1.cs 84 21 DungeonsAndDragons
I have no idea what this is T_T |
|
|
|
|
 |
rdrake

|
Posted: Mon Nov 23, 2009 4:04 pm Post subject: RE:Opening Files[C Sharp] |
|
|
You're accessing a static method on an instance variable instead of the type. Post the code that's giving you the error if you're still stuck. |
|
|
|
|
 |
RealityFix
|
Posted: Mon Nov 23, 2009 4:59 pm Post subject: RE:Opening Files[C Sharp] |
|
|
The code is a little confusing. I didn't write the search and sort thing I grabbed it off my teacher (Im a lazy bugger when it comes down to it)
but what I think your saying is that because my search thing is a static and my OpenFile method is just a public void that it will not work right?
C#: |
//(public void OpenFile)
try
{
openFileDialog1. Reset();
openFileDialog1. InitialDirectory = Application. ExecutablePath;
openFileDialog1. Filter = "Text files (*.txt)|*.txt|" + "All files|*.*";
openFileDialog1. FilterIndex = 1;
if (openFileDialog1. ShowDialog() == DialogResult. OK)
{
//string s = Application.StartupPath;
//string f = s + @"\albums.txt";
FileName = openFileDialog1. FileName;
r = new StreamReader (FileName );
string WholeLine;
while ((WholeLine = r. ReadLine()) != null)
{
c++;
lines = WholeLine. Split(',');
NameMon [c ] = lines [0];
borrower [c ] = lines [1];
}
//r.Close(); In finally statement below
//n = c;
//add filename to statusbar
toolStripStatusLabel1. Text = "File Loaded";
// Search.Shell(NameMon, borrower, n);
}
|
C#: |
public static void Shell(string[] albn, string[] borrown, int u)
{
int gap = u;
int maximum, iplusg, ex;
string temp = "";
do
{
gap = gap / 2;
maximum = u - gap;
do
{
ex = 0;
for (int i = 1; i <= maximum; i++)
{
iplusg = i + gap;
if (albn[i].CompareTo(albn[iplusg]) > 0)
{
temp = albn[i];
albn[i] = albn[iplusg];
albn[iplusg] = temp;
temp = borrown[i];
borrown[i] = borrown[iplusg];
borrown[iplusg] = temp;
ex = ex + 1;
}
}
}
while (ex != 0);
}
while (gap >= 1);
}
|
|
|
|
|
|
 |
rdrake

|
Posted: Mon Nov 23, 2009 5:06 pm Post subject: RE:Opening Files[C Sharp] |
|
|
C#: | Search.Shell(NameMon, borrower, n); | Is "Search" an object or the name of the class where Shell() is?
If it's an object then you're doing it wrong. Call this instead.
C#: | SearchAndSort.Shell() |
|
|
|
|
|
 |
RealityFix
|
Posted: Mon Nov 23, 2009 5:28 pm Post subject: RE:Opening Files[C Sharp] |
|
|
C#: |
SearchAndSort Search = new SearchAndSort ();
|
Sorry forgot to include the part above the try{}. |
|
|
|
|
 |
rdrake

|
Posted: Mon Nov 23, 2009 6:34 pm Post subject: RE:Opening Files[C Sharp] |
|
|
Yup, doing it wrong. The method is static, you absolutely have to call it as such.
C#: | SearchAndSort.Shell(NameMon, borrower, n); |
Notice how I'm calling the method on the class name, not an instance of that class. Try the above code and it should work just fine.
Also please in the future try to be a bit more careful when including bits of code in your post. Some of your questions are hard to understand due to missing code fragments. You're better off including too much than not enough. |
|
|
|
|
 |
RealityFix
|
Posted: Mon Nov 23, 2009 7:20 pm Post subject: RE:Opening Files[C Sharp] |
|
|
Thanks!
And I will put more data in my questions in the future. |
|
|
|
|
 |
|