List_Load + List_Save

Loads/Saves items from/to text file to/from listbox
Also has simple adding and removing items from listbox
Some old functions used a lot in my old days. Did not wanted them to be forgotten.

Sub List_Add(List As ListBox, txt As String)
 List.AddItem txt
End Sub
Sub List_Load(TheList As ListBox, FileName As String)
 ' Loads a file to a list box
 On Error Resume Next
 Dim TheContents As String
 Dim fFile As Integer
 fFile = FreeFile
 Open FileName For Input As fFile
 Do
  Line Input #fFile, TheContents$
  Call List_Add(TheList, TheContents$)
 Loop Until EOF(fFile)
 Close fFile
End Sub
Sub List_Save(TheList As ListBox, FileName As String)
 ' Save a listbox as FileName
 On Error Resume Next
 Dim Save As Long
 Dim fFile As Integer
 fFile = FreeFile
 Open FileName For Output As fFile
 For Save = 0 To TheList.ListCount - 1
  Print #fFile, TheList.List(Save)
 Next Save
 Close fFile
End Sub
Sub List_Remove(List As ListBox)
 On Error Resume Next
 If List.ListCount < 0 Then Exit Sub
 List.RemoveItem List.ListIndex
End Sub

List As ListBox, txt As String
TheList As ListBox, FileName As String
TheList As ListBox, FileName As String
List As ListBox

Used in YaShFin

Views 451 Downloads 130

'Listbox', 'file', 'read', 'listcount', 'listindex', 'controls'

ANmarAmdeen
323
Components VBA
Revisions

v1.0