I am using this code

Public Function Get_Settings(filename As String) As Boolean
    Dim recordlength As Integer
    recordlength = LenB(Settings)
On Error GoTo erroropeningsettingsfile
    Open filename For Random Access Read As #1 Len = recordlength
        Get #1, 1, Settings
    Close #1
    Get_Settings = True
    Exit Function
    Get_Settings = False
End Function

if the file doesn't exists supposedly an error will be occurred and the error handler will execute, the code doesn't do what it supposed to do. why does it create a text file?

Recommended Answers

All 2 Replies

' Return True if a file exists

Function FileExists(FileName As String) As Boolean
    On Error GoTo ErrorHandler
    ' get the attributes and ensure that it isn't a directory
    FileExists = (GetAttr(FileName) And vbDirectory) = 0
    ' if an error occurs, this function returns False
End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.