Text problem

T

Trond

First i must say i am sorry for the repost. I noticed to late that i forgot
to add text in the subject field.

I made a class that has one purpose. That is to read a log file into an
array and provide methods to get a random line. In the code below I am using
GetHeaderFromFiles to build up the array. In getDateStart i am picking out
line 2 from the array. When i in some form try to set a textbox.text like
this it does not work :
-----------------------------------------
LogHead test = new LogHead();
txtDate.Text = test.getDateStart();
-------------------------------------------
Here is the class LogHead

public static string GetHeaderFromFile(string filename, int linenr)
{
StreamReader f = new StreamReader(filename);
ArrayList lines = new ArrayList();
string line;
while ((line = f.ReadLine()) != null)
lines.Add(line);
return lines[linenr].ToString();
}
public static string getDateStart()
{
string theDate=GetHeaderFromFile(@"C:\Log\log.dat", 2);
return theDate;
}

As a newbee i am wondering why this does not work and if someone has some
tip that can help
me.
Best regards
 
J

Justin Rogers

Your methods are static, but you are creating an instance when calling
getDateStart()...
I'm not even sure how in the heck that is working for you.

txtDate.Text = LogHead.getDateStart(); // This is how you call statics.

Unless GetHeaderFromFile is caching, then you should be reading lines only up to
the
line you actually want. That way you don't run the risk of accessing an index
outside of
the lines buffer, and you don't wind up reading in lines you simply don't need.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top