Hi all,
I have a program that works I would just like it to be able to find the file with out me specifying the actual path. Because if it is on someone's computer other than mine the path might not be correct and it will not function properly. Here is the code I have done. The file it is looking for is of course names.txt. I have not been able to find much info on this.
The program as it stands, opens the file and reads each line of the file into an array and then sorts the array and outputs it to a text box.
Code:Imports System.IO Public Class SortFile Dim strArray() As String Private Sub SortFile_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim i As Integer = 0 Dim result As String = "" Try 'Check that file is in C:\ FileOpen(1, "c:\names.txt", OpenMode.Input) Do Until EOF(1) 'Run until the End Of File. If i = 0 Then ReDim strArray(0) Else 'Increase array size by 1 ReDim Preserve strArray(UBound(strArray) + 1) End If 'i = 0 Input(1, strArray(i)) 'Adding lines from the file to the array. i = i + 1 Loop Array.Sort(strArray) 'loop for output For i = 0 To UBound(strArray) result = result + strArray(i) & vbCrLf Next TextBox1.Text = result Catch 'If file not in C:\ display msgbox and end program. MsgBox("Error opening file. " & vbCrLf & "Names.txt must be in C:\") End End Try End Sub



Reply With Quote

