Dim fileName As String

Private Sub cmdSelect_Click()
Dim nom As String, phoneNum As String, x As String
Dim prompt As String, title As String, q As String
Open App.Path & "\Avail.txt" For Input As #1
a = "Choose from the following files:" & Chr$(10) & "" & _
Input(LOF(1), 1) & "or enter a new directory."
q = InputBox(a, "Choose a directory")
Close #1
If UCase(q) = "WORK NUMBERS" Then
x = App.Path & "\Aphone.txt"
ElseIf UCase(q) = "HOME NUMBERS" Then
x = App.Path & "\Bphone.txt"
ElseIf UCase(q) <> "WORK NUMBERS" Or _
UCase(q) <> "HOME NUMBERS" Then
title = "Directory Request"
prompt = "The directory you have requested does not " & _
"exist. Do you want this to be your new directory?"
response = MsgBox(prompt, vbYesNo, title)
If response = vbYes Then
x = App.Path & "\Cphone.txt"
Else
prompt = "You must choose a directory"
c = MsgBox(prompt, vbOKOnly, "Error")
End If
End If

Private Function NumberOfFiles(fileName As String) As Integer
Dim nom As String, phoneNum As String
Dim n As Integer
n = 0
Open fileName For Input As #1
Do While Not EOF(1)
Input #1, nom, phoneNum
n = n + 1
Loop
Close #1
NumberOfFiles = n
End Function

Private Sub cmdView_Click()
Dim numFiles As Integer, index As Integer
numFiles = NumberOfFiles(fileName)
ReDim nom(index) As String
ReDim phoneNum(index) As String
picDisplay.Cls
For index = 1 To numFiles
picDisplay.Print nom(index), phoneNum(index)
Next index
End Sub


VB6 learning edition