Results 1 to 4 of 4

Thread: Help with opening a file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    canada
    Posts
    15

    Post

    If you are hard coding the document's location there shouldn't be any problem but if you can save the document in different places, you should use an .ini file that contains the path that should be read when you click that button. GOOD LUCK

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    How do you want to Open it?
    Into your own Text/RTF Box or In an External Program, like Notepad?

    External Program..
    Code:
    Private cmdOpen_Click()
        'sFileName is the Path and FileName of the Saved File you want to Open with Notepad.
        Shell "Notepad.exe " & sFileName
    End Sub
    Into a Text/RTF Box..
    Code:
    Private Sub cmdOpen_Click()
        Dim iFile As Integer
        Dim sData As String
        
        iFile = FreeFile
        Open "TheFile.txt" For Input As iFile
        sData = Input(LOF(iFile), iFile)
        Close iFile
        Text1 = sData
    End Sub
    If the File is too big for the Input() Function..
    Code:
    Private Sub cmdOpen_Click()
        Dim iFile As Integer
        Dim sData As String
        Dim sChunk As String
        Dim lChunk As Long
        Dim lFileLen As Long
    
        iFile = FreeFile
        Open "C:\TheFile.txt" For Binary Access Read As iFile
        lFileLen = LOF(iFile)
        lChunk = 64000
        While Loc(iFile) < lFileLen
            If Loc(iFile) + lChunk > lFileLen Then lChunk = lFileLen - Loc(iFile)
            sChunk = Space(lChunk)
            Get #iFile, , sChunk
            sData = sData & sChunk
        Wend
        Close iFile
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3
    Guest

    Post

    Hi

    At present I've got a programme that creates a file and then saves it (according to some name the user has created) on the desktop. What I want is to be able to open the document directly through a command button on the main form, I've tried a couple of different ways but each time I'm creating some sort of error! Any help with opening up the document would be great.
    Thanx.

  4. #4
    Guest

    Post

    Still can't get the document to open, I've inclosed the code that saves the document.


    Public Sub SaveFile(sOutputFile As String)

    Dim n As Long
    Dim hFile As Long


    hFile = FreeFile

    Open sOutputFile For Output As #hFile

    For n = 1 To UBound(sAllFiles)
    Print #hFile, sAllFiles(n)


    Next

    close hfile

    End Sub

    What am I doing wrong?

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