Results 1 to 3 of 3

Thread: Binary Files - easy question !(resolved)

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Uk
    Posts
    10

    Binary Files - easy question !(resolved)

    Hi again,

    I am currently learning how to use binary files.

    I have been given an example which is a basic text editor which works fine.

    What i don't understand is "How does the program know where to store the saved file on my pc and where will that be ?"

    Code is below

    Private Sub mnuFileNew_Click()
    txtDoc = ""
    End Sub

    Private Sub mnuFileOpen_Click()
    Dim sText As String, sFileName As String
    Dim iFileNum As Integer

    'Get the filename to open
    sFileName = InputBox("File name", "Open")
    iFileNum = FreeFile 'Get the next free file number

    Open sFileName For Binary As iFileNum
    sText = Space(LOF(iFileNum)) 'Create a dummy string to hold the text
    Get iFileNum, , sText 'Load the text from the file
    txtDoc = sText
    Close iFileNum

    End Sub

    Private Sub mnuFileSaveAs_Click()
    Dim sText As String, sFileName As String
    Dim iFileNum As Integer

    sFileName = InputBox("File name", "Save")
    iFileNum = FreeFile

    Open sFileName For Binary As iFileNum
    sText = txtDoc
    Put iFileNum, , sText 'Save the text to the file
    Close iFileNum

    End Sub
    Last edited by NewbAl; Oct 15th, 2002 at 10:15 AM.

  2. #2
    Addicted Member Cimperiali's Avatar
    Join Date
    Oct 2002
    Location
    Milan, Italy, Europe
    Posts
    188

    Working dir if not specified

    'Trick is here:
    'this to read
    sFileName = InputBox("File name", "Open")
    'this to write
    sFileName = InputBox("File name", "Save")
    'if you answer to the input box
    ' "c:\temp\myfile.txt"
    'it will be opened (or saved) in c:\temp
    'If you answer only "myfile.txt"
    'it will be saved in the working directory
    'which may be the one where exe is, but also
    'the one where a shortcut is...or somewhere
    'else - the working (=current) dir
    'Matter is: I did not see the code to take care oof non-existing
    folders. Thus you may be forced to answer with a correct path, if you do not want to let it use the default (eworking) folder....
    Special thanks to some wonderful people,
    such as Lothar the Great Haensler, Aaron Young,
    dr_Michael, Chris Eastwood, TheOnlyOne ClearCode....

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    Uk
    Posts
    10
    Thankyou very much Cimperiali

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