Question Reading from a textfile

QnA

New member
Joined
Dec 13, 2010
Messages
2
Programming Experience
Beginner
Alright guys, I'm a new coder and new to this forum..

At the moment, I'm making a personal program (So it doesn't have to look nice or be super sleek) that is basically an alarm clock. I set the time and date, it writes it to a text document then it reads it from the text document back into another textbox that is hidden and compares it to label1.text which is my system time and date.

the problem is, I have it so that I can add multiple dates in one document so when I enter one it'll do as so :

i.e.

8:30:00 PM 12/13/2010

8:35:00 PM 12/13/2010

The problem is, if I add more than 1 it adds the entire document to the textbox and then doesn't work because it comes out like so..

8:30:00 PM 12/13/20108:35:00 PM 12/13/2010

^ Which as you might've guessed does not equal

Alright guys, I'm a new coder and new to this forum..

At the moment, I'm making a personal program (So it doesn't have to look nice or be super sleek) that is basically an alarm clock. I set the time and date, it writes it to a text document then it reads it from the text document back into another textbox that is hidden and compares it to label1.text which is my system time and date.

the problem is, I have it so that I can add multiple dates in one document so when I enter one it'll do as so :

i.e.

8:30:00 PM 12/13/2010
or
8:35:00 PM 12/13/2010

So my question to you guys is, how can I make the program read 1 line, wait for it to match the label, (I already make it display a message box) and then after that is all done, go to the next line and wait for it to match. etc etc.

Please help guys, I have been fighting with this thing all day and I do believe this is my last bit before I can use it to help me during the day.
 
First up, there's no point using a hidden TextBox. A TextBox exists to display a String to the user and allow the user to enter and edit a String. You're doing neither, so don;t use a TextBox. All you need is a String so just use a String. If you load the data into a TextBox then you just have to get a String back from its Text property, so just use a String in the first place.

Secondly, you shouldn't be comparing anything to a Label. The Label is displaying the current time so you have to have the current time in the first place. It's that that you should be comparing to.

As for your text file issue, call IO.File.ReadAllLines to read a text file into a String array, where each element is a line from the file. You can then loop through that array or whatever.
 
First up, there's no point using a hidden TextBox. A TextBox exists to display a String to the user and allow the user to enter and edit a String. You're doing neither, so don;t use a TextBox. All you need is a String so just use a String. If you load the data into a TextBox then you just have to get a String back from its Text property, so just use a String in the first place.

Secondly, you shouldn't be comparing anything to a Label. The Label is displaying the current time so you have to have the current time in the first place. It's that that you should be comparing to.

As for your text file issue, call IO.File.ReadAllLines to read a text file into a String array, where each element is a line from the file. You can then loop through that array or whatever.

Like I said, I'm pretty new to coding and I actually just now figured out how to write to the file and read back (even though its not what I want)

so if there is a way you could dumb down what you said for me lol That'd be awesome..

Or if you have an MSN or something I could get help over. I could also post the source if you would like.
 
Back
Top