Results 1 to 5 of 5

Thread: **Calling a file open module

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    IRELAND
    Posts
    8

    Post

    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. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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
            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


  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    IRELAND
    Posts
    8

    Post

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

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    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. #5

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    IRELAND
    Posts
    8

    Post

    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
  •  



Click Here to Expand Forum to Full Width