home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- BorderStyle = 3 'Fixed Dialog
- Caption = "Open & Save Data "
- ClientHeight = 2820
- ClientLeft = 6240
- ClientTop = 3840
- ClientWidth = 2655
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 2820
- ScaleWidth = 2655
- ShowInTaskbar = 0 'False
- Begin VB.CommandButton Command4
- Caption = "EXIT"
- Height = 255
- Left = 1920
- TabIndex = 5
- Top = 2520
- Width = 675
- End
- Begin VB.CommandButton Command3
- Caption = "AddITem"
- Height = 2055
- Left = 2400
- TabIndex = 3
- Top = 360
- Width = 195
- End
- Begin VB.ListBox List1
- Height = 2010
- ItemData = "ListBox.frx":0000
- Left = 0
- List = "ListBox.frx":0010
- TabIndex = 2
- Top = 360
- Width = 2295
- End
- Begin VB.CommandButton Command2
- Caption = "Load"
- Height = 255
- Left = 960
- MousePointer = 10 'Up Arrow
- TabIndex = 1
- Top = 2520
- Width = 855
- End
- Begin VB.CommandButton Command1
- Caption = "Save"
- Height = 255
- Left = 0
- MousePointer = 10 'Up Arrow
- TabIndex = 0
- Top = 2520
- Width = 855
- End
- Begin VB.Label Label1
- Height = 255
- Left = 0
- TabIndex = 4
- Top = 0
- Width = 2655
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Private Sub Command1_Click()
- On Error GoTo here 'if error skip it all and goto here:
- Dim lFile As Long, Item As Integer 'Dims
- lFile = FreeFile 'Open as
- Open App.Path & "\TestFile.txt" For Output As lFile 'open a file to save the items to
- For Item = 0 To List1.ListCount - 1 'find out how many items substract 1 (empty)
- Print #lFile, List1.List(Item) 'save the items
- Next Item 'finish For function
- Close #lFile 'close the file
- Exit Sub 'done
- here: MsgBox Error 'shows error if any
- End Sub
- Private Sub Command2_Click()
- On Error Resume Next
- Dim Item As Integer, ListItem As String 'Dims
- Open App.Path & "\TestFile.txt" For Input As #1 'opens the file to get items
- List1.Clear 'clear ListBox
- Do While Not EOF(1) 'Do until it reaches the end of the file
- Input #1, ListItem 'put the items in
- Item = Item + 1 'gets each item after item
- List1.AddItem ListItem 'add the items
- Loop 'do infinite times until it reaches the end of the file
- Close #1 'close the file
- Label1.Caption = "Entries: " & List1.ListCount 'display how many items are in the listbox
- End Sub
- Private Sub Command3_Click()
- List1.AddItem "Data to save" 'add a item
- Label1.Caption = "Entries: " & List1.ListCount 'added it again to refresh it
- End Sub
- Private Sub Command4_Click()
- Unload Me 'closes the program
- End Sub
- Private Sub Form_Load()
- Label1.Caption = "Entries: " & List1.ListCount 'displays amout of items in listbox when form loads
- MsgBox "Try using the Common Dialong control to let the user specify a file to open/save"
- End Sub
-