Okay, i need 2 make a list of winners. First, i would like to check if a certain file, (lstwinners.txt) exists. If it exists, it would add a certain string to the end of it. If it doesn't it would create it then add a string to the end. Please help!
Printable View
Okay, i need 2 make a list of winners. First, i would like to check if a certain file, (lstwinners.txt) exists. If it exists, it would add a certain string to the end of it. If it doesn't it would create it then add a string to the end. Please help!
bump - please help me!
With all respect, do a little reading. This is basic file i/o and is covered in books, MSDN, google searches etc.
But to help out, why don't you just open the file in append mode and then write to it?
i have a crappy textbook that doesnt tell me ****, and i would appreciate it if you could give me the exact code.. thanksQuote:
Originally posted by Mike Hildner
With all respect, do a little reading. This is basic file i/o and is covered in books, MSDN, google searches etc.
But to help out, why don't you just open the file in append mode and then write to it?
Well, that might be cheating. MSDN is a great resource, and it's on your machine/the web. Search for "File.Open Method", try out some examples, and if you still have troubles post the code you've tried and you'll get help.
cheating? lol this is a program im making for fun! its for a game im making - a high score list if you will. please help. thanks
Dim strPath As String = "C:\d.txt"
Dim SW As StreamWriter
Dim FS As FileStream
If File.Exists(strPath) = True Then
MsgBox("True")
FS = New FileStream(strPath, FileMode.Open)
SW = New StreamWriter(FS)
SW.WriteLine("True")
Else
MsgBox("False")
FS = New FileStream(strPath, FileMode.Create)
SW = New StreamWriter(FS)
SW.WriteLine("False")
End If
SW.Close()
FS.Close()
works great xcept if it doesnt exist, i want it to create it AND write a line to it...
VB Code:
Dim sw As StreamWriter = New StreamWriter("c:\temp\myfile.txt", True) sw.WriteLine("This is a simple example - MSDN is your friend!") sw.Close()
how do i load items from a txt file into a listbox? then im done!
Dim strPath As String = "C:\Items.txt"
Dim SR As StreamReader
Dim FS As FileStream
FS = New FileStream(strPath, FileMode.Open)
SR = New StreamReader(FS)
Dim itm As Object
itm = SR.ReadLine()
While Not itm = Nothing
Listbox1.Items.Add(itm)
itm = SR.ReadLine()
End While
SR.Close()
FS.Close()