Minggu, 14 Oktober 2012

Menyimpan Data dalam ListBox dan Membukanya di waktu lain - (Kontrol)

Menyimpan Data dalam ListBox dan Membukanya di waktu lain - (Kontrol)

         
Private Sub Command1_Click()
Dim i As String
i = InputBox("enter string")
List1.AddItem i
End Sub

Private Sub Command2_Click()   
OpenList List1
End Sub

Private Sub Command3_Click()   
  SaveList List1
End Sub

Private Sub SaveList(lst As ListBox)
Dim a As Integer
Dim ff As Integer
Dim Header As String
Dim LCount As Long
Dim numbyte As Byte
ff = FreeFile
Open "C:list.lst" For Binary As #1
Header = "SavedList"
Put ff, 1, Header
LCount = lst.ListCount
Put ff, , LCount
For a = 0 To lst.ListCount - 1
    numbyte = Len(lst.List(a))
    Put ff, , numbyte
    Put ff, , lst.List(a)
Next a
Close ff
End Sub

Private Sub OpenList(lst As ListBox)
Dim a As Integer
Dim ff As Integer
Dim LCount As Long
Dim data As String
Dim numbyte As Byte
ff = FreeFile
Open "C:list.lst" For Binary As #1
    data = "SavedList"
    Get ff, 1, data
    Get ff, , LCount
    If data = "SavedList" Then
        For a = 0 To LCount - 1
            Get ff, , numbyte
            data = String(numbyte, " ")
            Get ff, , data
            lst.AddItem (data)
        Next a
    Else
        MsgBox "Error loading list: Bad file"
    End If
Close ff
End Sub

0 komentar:

Posting Komentar

 

© 2011 e - Tutorial | by Moeh Fitrah