Jump to content
Xtreme .Net Talk

Recommended Posts

  • 1 month later...
Posted

Was yours anything like this?

 

Public Function PopulateComboFromFile(ByVal ListControl As ComboBox, ByVal FullPath As String, _

ByVal Blank As Boolean, 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)

 

ListControl.Items.Clear() 'Clear List Control.

ListControl.Items.AddRange(arrContents) 'Populate list control

If Blank = True Then

ListControl.Items.AddRange(New Object() {" "}) 'add blank rows to each combo

End If

 

PopulateComboFromFile = True

Catch ex As Exception

objTextStream = Nothing

objFso = Nothing

MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Load contract lists")

End Try

End Function

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...