• Do While Not End of File VB.NET
    10 replies, posted
Here's my code: [code] im Filename As String Dim Counter As Integer = 0 Filename = "records.mnz" Current = New FileStream(Filename, FileMode.Open) Reader = New BinaryReader(Current) Console.WriteLine("{0,15}{1,6}{2,12}{3,9}", "Item", "Type", "Date", "Price") Do While Not INSERT CODE HERE Records(Counter).Item = Reader.ReadString Records(Counter).TransType = Reader.ReadString Records(Counter).TDate = Reader.ReadString Records(Counter).Price = Reader.ReadDecimal Console.WriteLine("{0,15}{1,6}{2,12}{3,9}", Records(Counter).Item, Records(Counter).TransType, Records(Counter).TDate, Records(Counter).Price) Counter += 1 Loop [/code] Basically I want it to loop while it's not the end of the file. I haven't got a clue how to go about that. Anyone have any ideas?
Do While Not EOF(filePointerHere)
Sorry I'm not the best programmer in the world. What is a file pointer and how would I declare it etc?
For what you have, it looks like you're using "Current" for your file stream which is reading a file. You'd do this: [code] Dim Filename As String Dim Counter As Integer = 0 Filename = "records.mnz" Current = New FileStream(Filename, FileMode.Open) Reader = New BinaryReader(Current) Console.WriteLine("{0,15}{1,6}{2,12}{3,9}", "Item", "Type", "Date", "Price") Do While Not EOF(Current) Records(Counter).Item = Reader.ReadString Records(Counter).TransType = Reader.ReadString Records(Counter).TDate = Reader.ReadString Records(Counter).Price = Reader.ReadDecimal Console.WriteLine("{0,15}{1,6}{2,12}{3,9}", Records(Counter).Item, Records(Counter).TransType, Records(Counter).TDate, Records(Counter).Price) Counter += 1 Loop [/code] [editline]12:29PM[/editline] It's been a while since I've done VB, but [B][I]I believe[/I][/B] that that's right.
Yeah I tried that earlier coz that's what I thought it would be. It just returns with 'Value of type 'System.IO.FileStream' cannot be converted to 'Integer''
See if the filestream has an EOF property. I believe all streams in .net do
No it don't. This is bloody frustrating, why can't it just work how it's supposed to!
Did you try: Current.EOF()
Yeah, it just says, ''EOF' is not a member of 'System.IO.Filestream''
[url]http://msdn.microsoft.com/en-us/library/db5x7c0d(VS.100).aspx[/url]
Cool that really helped thanks! Only problem now is it doesn't want to read one of the records but i think its saved wrongly/
Sorry, you need to Log In to post a reply to this thread.