If it works do not change it, always says my teacher. ;)
Maybe I can suggest another way to get that, but only for discussion. This has not been tested:
Public Class Form1
'
' Do you really want to have only 5 files?
' I will suggest to work with FileInfo instead, because you can have more control on what is happening with the file
'
' Dim strFile() As FileInfo ' But really we need no array
Const strPath As String = "C:\Definition Data" ' declaring as a constant will not waste time nor memory on each new assignement
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' strPath = "C:\Definition Data\"
' Dim i As Integer
' Dim strFile(5) As String
' For i = 0 To 3
' I will suggest to change this in a for each loop
For each existingFile as FileInfo in My.Computer.FileSystem.GetFiles(strPath)
' strFileName(i) = strFile(i).Remove(0, strFile(i).LastIndexOf("\"))
' cmbDefnTerms.Items.Add(strFileName(i))
' add it directly as object in the combo.
' The file names will be OK as the default ToString for a FileInfo
' obtained using GetFiles is the file name, not the full path
cmbDefnTerms.Items.Add(existingFile)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbDefnTerms.SelectedIndexChanged
' strPath = "C:\Definition Data"
Dim FiletoShow as FileInfo = Ctype(cmbDefnTerms.SelectedItem, FileInfo) ' this will retrieve the selecte Item
If Filetoshow.Exists then ' you will verify that the file exists before showing it
try
txtDefinition.Text = My.Computer.FileSystem.ReadAllText(FiletoShow.FullName) ' here will use the full path
catch e as Exception
' in case of error clear the textDefinfition
txtDefinition.Text = ""
End try
End If
End Sub
End Class
See see here for the explanation on how works the ToString for the FileInfo class.
Well, this is only anoter approach.
Hope this helps
lolafuertes
Practically a Posting Shark
895 posts since Oct 2008
Reputation Points: 164
Solved Threads: 189
Skill Endorsements: 5
Question Answered as of 1 Year Ago by
lolafuertes