B
blah
what i want to do is read in a .ged file and find all the names in the file
and then add them to a listbox. this is what i have and it works but what
can i do better?
thanks,
Rob
public class Gedcom
{
private string gedFile;
private StreamReader fstream;
public Gedcom()
{
//
// TODO: Add constructor logic here
//
}
public string[] GetIndex()
{
//
if (fstream == null)
{
MessageBox.Show("Error opening file stream.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
return null;
}
StreamReader fstreamCopy = fstream;
string textLine;
int index;
bool foundName = false;
ArrayList tmpIndex = new ArrayList();
while (fstreamCopy.BaseStream != null)
{
foundName = false;
try
{
textLine = fstreamCopy.ReadLine().Trim();
index = textLine.IndexOf("INDI");
if (index != -1)
{
while (!foundName)
{
textLine = fstreamCopy.ReadLine().Trim();
index = textLine.IndexOf("NAME");
if (index != -1)
{
tmpIndex.Add(textLine.Substring(index + 4).Trim());
foundName = true;
}
}
}
}
catch
{
fstreamCopy.Close();
}
}
string[] indIndex = new String[tmpIndex.Count];
for (int i = 0; i < tmpIndex.Count; i++)
{
indIndex = tmpIndex.ToString();
}
return (indIndex);
//
}
public string OpenGed( string FileName )
{
//
gedFile = FileName;
fstream = File.OpenText(gedFile);
return gedFile;
//
}
}
.....
private void mnuIndex_Click(object sender, System.EventArgs e)
{
frmIndex frmIndex = new frmIndex();
string[] index = ged.GetIndex();
frmIndex.Names = new string[index.Length];
index.CopyTo(frmIndex.Names, 0);
if (frmIndex.ShowDialog(this) == DialogResult.OK)
{
}
}
and then add them to a listbox. this is what i have and it works but what
can i do better?
thanks,
Rob
public class Gedcom
{
private string gedFile;
private StreamReader fstream;
public Gedcom()
{
//
// TODO: Add constructor logic here
//
}
public string[] GetIndex()
{
//
if (fstream == null)
{
MessageBox.Show("Error opening file stream.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
return null;
}
StreamReader fstreamCopy = fstream;
string textLine;
int index;
bool foundName = false;
ArrayList tmpIndex = new ArrayList();
while (fstreamCopy.BaseStream != null)
{
foundName = false;
try
{
textLine = fstreamCopy.ReadLine().Trim();
index = textLine.IndexOf("INDI");
if (index != -1)
{
while (!foundName)
{
textLine = fstreamCopy.ReadLine().Trim();
index = textLine.IndexOf("NAME");
if (index != -1)
{
tmpIndex.Add(textLine.Substring(index + 4).Trim());
foundName = true;
}
}
}
}
catch
{
fstreamCopy.Close();
}
}
string[] indIndex = new String[tmpIndex.Count];
for (int i = 0; i < tmpIndex.Count; i++)
{
indIndex = tmpIndex.ToString();
}
return (indIndex);
//
}
public string OpenGed( string FileName )
{
//
gedFile = FileName;
fstream = File.OpenText(gedFile);
return gedFile;
//
}
}
.....
private void mnuIndex_Click(object sender, System.EventArgs e)
{
frmIndex frmIndex = new frmIndex();
string[] index = ged.GetIndex();
frmIndex.Names = new string[index.Length];
index.CopyTo(frmIndex.Names, 0);
if (frmIndex.ShowDialog(this) == DialogResult.OK)
{
}
}