Advertisement
4_2005-2006 Custom Controls/ Forms/ Menus #150104

ListVieW/ListBox Print, Save, Load from File

This code lets you to Print, Save to file, Load data from file to/from ListBox or ListView object.

AI

Podsumowanie AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kod źródłowy
original-source
'Example: Call SaveListBox(list1, "C:\Temp\MyList.dat")
Public Sub SaveListBox(TheList As ListBox, Directory As String)
 Dim SaveList As Long
 On Error Resume Next
 Open Directory$ For Output As #1
 For SaveList& = 0 To TheList.ListCount - 1
  Print #1, TheList.List(SaveList&)
 Next SaveList&
 Close #1
End Sub
'Example: Call LoadListBox(list1, "C:\Temp\MyList.dat")
Public Sub LoadListBox(TheList As ListBox, Directory As String)
 Dim MyString As String
 On Error Resume Next
 Open Directory$ For Input As #1
 While Not EOF(1)
  Input #1, MyString$
   DoEvents
    TheList.AddItem MyString$
 Wend
 Close #1
 
End Sub
Public Sub PrintListBox(TheList As ListBox)
 Dim SaveList As Long
 On Error Resume Next
 Printer.FontSize = 12
 For SaveList& = 0 To TheList.ListCount - 1
  Printer.Print TheList.List(SaveList&)
 Next SaveList&
 Printer.EndDoc
End Sub
Public Function PrintLV(lv As ListView, Subs As Integer)
 
 Printer.FontSize = 12
 Dim subit As Variant
 Dim i As Integer
 Dim x As Integer
 For i = 1 To lv.ListItems.Count
  subit = lv.ListItems(i).Text & vbTab
  For x = 1 To Subs
   subit = subit & lv.ListItems(i).SubItems(x) & vbTab
  Next
  Printer.Print subit
  subit = ""
 Next
 Printer.EndDoc
End Function
Public Function SaveLV(lv As ListView, Subs As Integer, sPath As String)
 
 Dim subit As Variant
 Dim F As Integer
 Dim i As Integer
 Dim x As Integer
 F = FreeFile
 On Error Resume Next
 Open sPath For Output As #F
 For i = 1 To lv.ListItems.Count
  subit = lv.ListItems(i).Text & vbTab
  For x = 1 To Subs
   subit = subit & lv.ListItems(i).SubItems(x) & vbTab
  Next
  Print #F, subit
  subit = ""
 Next
 Close #F
End Function
Oryginalne komentarze (3)
Odzyskane z Wayback Machine