# Thread: **Calling a file open module

1. Guys,
I have a 'module' in my prgram that opens a text file;
while not eof(1)
Open "a:\text1.txt" for input as #1
input #1,textline
.
.
I want this module to be called in form2 of my project how do I do this

' I seem to have to put another open
' statement here
for i = 1 to 3
for j = 1 to 3
Input #1, temp ' getting an error here
Myarray(i,j) = temp
next j
next i

Any help would be great

2. You can create a generic function that will open a text file and return the complete text.

Code:
Public Function GetTextFromFile(pstrFileName As String) As String
Dim strBuffer As String
Dim intFFN As Integer

If Len(Dir(pstrFileName)) = 0 Then
Exit Function
End If
intFFN = FreeFile
Open pstrFileName For Input As intFFN
strBuffer = Space(LOF(intFFN))
strBuffer = Input(LOF(intFFN), #intFFN)
Close #intFFN
GetTextFromFile = strBuffer
End Function
Usage: GetTextFromFile TextFilename

Sample: Text1.Text = GetTextFromFile("A:\Text1.txt")

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819

3. How do I call this type of code at the
Input #1 , temp....part of my programme

4. No, just copy this function to a module. Then, whenever you want to retrieve the text from the file you will do it like this:

Dim strText As String

strText = GetTextFromFile("A:\MyText.txt")

strText now holds the text from the specified file.

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819

5. Bingo,
Just what I wanted......thx Serge

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•