This is exactly what you want. It will allow you to choose a file and read it into an array in memory. Then optionall clear the array contents. The array is accessible from any procedure in your form for other use.
VB Code:
Option Explicit 'Add a CommonDialog Control to your toolbox and add to your form. 'Project > Components > Controls tab > select "MS Common Dialog Control" > click OK. Private arArray() As String Private Sub Command1_Click() On Error GoTo My_Error Dim strFilePath As String Dim strBuff As String With CommonDialog1 .CancelError = True .DialogTitle = "Select a file" .InitDir = App.Path .ShowOpen strFilePath = .FileTitle End With Open strFilePath For Input As #1 strBuff = Input(LOF(1), 1) Close #1 arArray() = Split(strBuff, vbNewLine) 'File contents remail in the array in memory until erased If MsgBox("Do you want to clear the array contents?", vbYesNo + vbQuestion) = vbYes Then Erase arArray End If Exit Sub My_Error: If Err.Number = cdlCancel Then MsgBox "File Open Canceled", vbOKOnly + vbExclamation Else MsgBox Err.Number & " - " & Err.Description, vbOKOnly + vbExclamation End If End Sub





Reply With Quote