Thread: Modding Tools
View Single Post
  #19  
Old June 17th, 2004, 06:24 PM
Ed Kolis's Avatar

Ed Kolis Ed Kolis is offline
General
 
Join Date: Apr 2001
Location: Cincinnati, Ohio, USA
Posts: 4,547
Thanks: 1
Thanked 7 Times in 5 Posts
Ed Kolis is on a distinguished road
Default Re: Modding Tools

Well, my code's in C#, and while I could convert it to VB.NET, that wouldn't do much good as you're using VB6 which is radically different...

But basically, I have a structure called Field, which contains 2 strings, Name and Data.

Then to read the next field from a data file, I use this function:

code:
/// <summary>
/// Reads a data field from an SE4 text file and verifies its name if the
/// name parameter is not null.
/// </summary>
protected Field ReadFieldText(string name)
{
string line;
Field field;

// Read lines until a non-blank line is found
// Note that this is "nicer" than SE4's parser, in that
// extra newlines between lines are simply ignored, and the
// later entries are still read
// Find the first delimiter
int delimiterPosition;
do
{
// Read the next line from the data file
line = textReader.ReadLine();
delimiterPosition = line.IndexOf(delimiter);
} while (delimiterPosition < 0); // read until good line found

// Create the field
field = new Field(line.Substring(0, delimiterPosition).Trim(),
line.Substring(delimiterPosition + delimiter.Length).Trim());

// Verify if necessary
if (name != null && field.Name != name)
throw new ParserException("The field name \"" + field.Name + "\" was found where \"" + name + "\" was expected.", line);

return field;
}

The ParserException is just an exception class I created so I can tell a parser exception from any other type of exception.

This particular implementation will verify that the name of the field is some specific value, so you can make sure the fields are in the right order. Or, if you pass a null reference (does VB6 have those?), it won't verify and just return the next field no matter what.

Would you find everything I've worked on handy, even though it's in C#? I can post it on my website if you want...
__________________
The Ed draws near! What dost thou deaux?
Reply With Quote