- Home
·
- Miscellaneous
·
- Populates a list control (listbox, combobox, etc) from the contents of a text file.
Populates a list control (listbox, combobox, etc) from the contents of a text file.
Populates a list control (listbox, combobox, etc) from the contents of a text file.
Rate Populates a list control (listbox, combobox, etc) from the contents of a text file.
(2(2 Vote))
ByVal FullPath As String, Optional ByVal Delimiter As String = vbCrLf) As Boolean
Dim objFso As New Scripting.FileSystemObject()
Dim objTextStream As Scripting.TextStream
Dim strContents As String
Dim arrContents() As String
Dim lCtr As Long, lCount As Long
Try
'Ensure file exists
If Dir(FullPath) = "" Then
MsgBox("The file " & FullPath & " does not exist", MsgBoxStyle.OKOnly, "Load contract lists")
Exit Function
End If
'Get file contents
objTextStream = objFso.OpenTextFile(FullPath, Scripting.IOMode.ForReading)
strContents = objTextStream.ReadAll
objTextStream.Close()
'Split file contents based on delimiter
arrContents = Split(strContents, Delimiter)
lCount = UBound(arrContents)
'Clear List Control.
ListControl.Items.Clear()
'Populate list control
ListControl.Items.AddRange(arrContents)
PopulateListControlFromFile = True
Catch ex As Exception
objTextStream = Nothing
objFso = Nothing
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Load contract lists")
End Try
End Function
Populates a list control (listbox, combobox, etc) from the contents of a text file. Comments
No comments yet — be the first to post one!
Post a Comment