Parse File Contents Method
The Parse File Contents method reads data from a sequential file, and then saves this data to different variables. It does not return a value.
Format
Input [#]filenumber, variable[, variable]...
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
filenumber |
The file number that the Open statement uses to open the file. |
variable |
One or more variables to contain the values that this method reads from the file. A comma separates each variable. |
Example
The following example does the following work:
Prompts a user for an account number.
Opens a file.
Searches the file for the account number.
Displays the matching letter for that number.
This example uses the Input statement to increase the value of x and at the same time to get the letter associated with each value. The CreateFile subroutine creates the c:\temp001 file that the main subroutine uses:
(general) (declarations)
Option Explicit
Declare Sub CreateFile
Global x as Integer
Global y(100) as String
Sub CreateFile
' Put the numbers 1-10 and letters A-J into a file
Dim startletter
Open "c:\temp001" for Output as #1
startletter = 65
For x = 1 to 10
y(x) = Chr(startletter)
startletter = startletter + 1
Next x
For x = 1 to 10
Write #1, x,y(x)
Next x
Close #1
End Sub
Sub Button2_Click
Dim acctno as Integer
Dim msgtext
Call CreateFile
start: acctno = 2
If acctno<1 Or acctno>10 then
Goto start:
End if
x = 1
Open "c:\temp001" for Input as #1
Do Until x = acctno
Input #1, x,y(x)
Loop
msgtext = "The letter for account number " & x & " is: " _
& y(x)
Close #1
Kill "C:\TEMP001"
End Sub