Finding the End Of File
-
hey i have a project where i need to read from a text file but i will never know how long it is. It is basically a list of numbers. I read them in and store them in a collection but how do i know when the end of file is? this is in VB.Net
this should help , make sure to put your text file's location where it currently says C:\mytest.txt . VbCode:
Imports System.IO
'/// at the top of your form's code window ^^^^.
'/////////////////////////////////////////////
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim sReader As StreamReader = New StreamReader(New FileStream("C:\mytest.txt", FileMode.Open, FileAccess.Read))
Dim x As Integer = sReader.BaseStream.Length
MessageBox.Show("The Length of the text file is: " & x & " Characters")
While Not sReader.Peek
Console.WriteLine(sReader.ReadLine)
End While
sReader.Close()
End Sub
hope that helps:) Vb:
Public Function TwinsOnWay(ByVal twins As String) As String
Select Case twins
Case "Gender"
Return "Two Girls"
End Select
End Function