Option Explicit
Private Sub Command1_Click()
' Call the Save List Routine
Call SaveList
End Sub
Private Sub Form_Load()
Dim intCtr As Integer
' Populate the listbox with test
' data
For intCtr = 0 To 10
With List1
.AddItem "Item " & intCtr
End With
Next intCtr
End Sub
Private Sub SaveList()
Dim iHandle As Integer
' Handle to the next available file
Dim iCtr As Integer
' Loop Counter
' get the next available file
iHandle = FreeFile()
' Open the file for output.
' Note that if the file does not exist then it will
' be created automatically
Open "C:\List Contents.txt"
For Output As iHandle
For iCtr = 0 To List1.ListCount
' Iterate over each item in the list
' and write the value to the file
Print #iHandle, List1.List(iCtr)
Next iCtr
Close iHandle
End Sub