Results 1 to 4 of 4

Thread: open as readonly

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    77

    Unhappy

    how would i open .txt file as open readonly so user can't change data.

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Dullawhere
    Posts
    100
    you can't control that, yur best bet would be to make a text box in your program and lock it so no one can edit it

    just make a new form with it in it or somehthing
    I am stupid..but I AM 15 !
    *a line from a song i wrote*
    """"""""""""""""""""""""""""""""""""""""
    so i came to say life bites away
    whats done is done the past is gone
    i cant believe the sh*t I know
    i always wish it would just go
    """"""""""""""""""""""""""""""""""""""""
    "remember you Ps And Qs Boy !"

  3. #3
    Guest
    Check the "Open" command and just open it for "read". Then don't allow it to be saved. You tell the user as he opens the file that he will not be able to save changes.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'if you want the file to be read only you can set
    'the attributes and it would go like this.
    
    Option Explicit
    
    Public myFile As String
    
    Private Sub Command1_Click()
    
    myFile = "C:\my documents\myfile.txt"
    SetAttr myFile, vbReadOnly
    
    Shell "C:\WINDOWS\NOTEPAD.EXE " & myFile, 1
    'now you can make changes and try to save the file
    'and you won't be able to.
    'you must reset the attributes when you close your app
    'or the file will remain read only.
    End Sub
    
    
    'OR
    '
    'if you wish to use the textbox it goes like this
    '
    Private Sub Form_Load()
    'add a textbox, set it to multiline and scrollbars
    'Open a file in binary mode and read into a textbox or string
    'this opens your file and dumps it into a textbox
    'the user can do what they want but since it is only a textbox
    'none of the changes will reflect inside the file
    
        Dim sHolder As String
        Dim intNum As Integer
        Dim sFileName As String
        
        'open for binary and read
        sFileName = "C:\My Documents\MyFile.txt"
        intNum = FreeFile
        
        Open sFileName For Binary As intNum
          sHolder = Space(LOF(1))
          Get #1, , sHolder
        Close intNum
        
        'assign the text to a textbox
         Text1 = sHolder  ' for a string (strString = sholder)
    
    End Sub
    
    'this sets the file back to normal
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        SetAttr myFile, vbNormal
    End Sub
    
    Private Sub Form_Terminate()
        SetAttr myFile, vbNormal
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        SetAttr myFile, vbNormal
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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