VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



ListVieW/ListBox Print, Save, Load from File

by Markku Strömberg (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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

Inputs
Listbox related functions: LoadListBox -Inputs: ListBox object, Directory from where to load SaveListBox -Inputs: ListBox object, Directory where to save PrintListBox -Inputs: ListBox object ListView related: SaveLV -Inputs: ListView object, Subitems amount in that object, Directory where to save PrintLV -Inputs: Listview object, Subitems amount in that object
Assumes
I fogot to say that those ListView functions assumes that ListView viewmode is lvwReport and you should have one or more subitems in that object, Sorry ;)
Side Effects
None.

Rate ListVieW/ListBox Print, Save, Load from File

'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

Download this snippet    Add to My Saved Code

ListVieW/ListBox Print, Save, Load from File Comments

No comments have been posted about ListVieW/ListBox Print, Save, Load from File. Why not be the first to post a comment about ListVieW/ListBox Print, Save, Load from File.

Post your comment

Subject:
Message:
0/1000 characters