Save listbox list


Posted by Ben on September 15, 2000 6:42 PM

How do I save a listbox list when the userform is closed? I tried to use a "Public lb as listbox" but it doesn't work like a regular listbox. The Public declaration seems to accept only single strings. How do I get it to accept a whole list?



Posted by Ben on September 15, 0100 8:45 PM

It ain't pretty but...

...it works:

Private Sub UserForm_Terminate()
Dim i As Integer
Dim tbpre As String
For i = 1 To ListBox1.ListCount
tbpre = ListBox1.List(i - 1)
Module1.lb1list = Module1.lb1list & tbpre & ","
Next
End Sub

Private Sub UserForm_Activate()
x = Len(Module1.lb1list)
For i = 1 To x
char = ","
n = InStr(i, Module1.lb1list, char)
If x > 0 Then
ListBox2.AddItem left(Module1.lb1list, n - 1)
Module1.lb1list = Right(Module1.lb1list, x - n)
x = Len(Module1.lb1list)
End If
Next
End Sub

It converts the listbox list to a single string & then converts it back again. Is there a better way?