PDA

Click to See Complete Forum and Search --> : **Calling a file open module


SMDillon
Nov 20th, 1999, 03:02 PM
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

Serge
Nov 20th, 1999, 09:14 PM
You can create a generic function that will open a text file and return the complete text.


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

If Len(Dir(pstrFileName)) = 0 Then
MsgBox "File " & pstrFileName & " not found."
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 (http://www.icq.com/51055819)

SMDillon
Nov 21st, 1999, 12:59 AM
How do I call this type of code at the
Input #1 , temp....part of my programme

Serge
Nov 21st, 1999, 08:48 PM
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 (http://www.icq.com/51055819)

SMDillon
Nov 22nd, 1999, 12:32 AM
Bingo,
Just what I wanted......thx Serge