0

Hi
I want to know how to know if user is running the program for first time?
I have a .txt file which will be loaded on start, but it is the first time and there is no such file.
If anybody contributes, I will be happy
Thanks in advance
Yuvjeeth

6
Contributors
6
Replies
42
Views
3 Years
Discussion Span
Last Post by mridul.ahuja
Featured Replies
  • If you add a reference(Project menu) to Microsoft Scripting Runtime, you'll have access to the FilesystemObject which has a FileExists method. Using that should give you what you want. btw joshl_1995 that's .net code Read More

  • 1

    You can use this following code : Private Sub Form_Load() If Dir$("D:\dani.txt", vbNormal) = "" Then MsgBox "This is your first time" Else ' Do anything if text file exist End If End Sub Read More

  • This should work : Private Sub Form_Load() If Dir$(file_path, vbNormal) = "" Then ' <--- file doesn't exist ' Create the text file Else ' Continue with the execution End If End Sub where **file_path** is the *relative* or *complete* path of the file ( along with extention .txt) Read More

  • try this :- Dim fso As New FileSystemObject If Not fso.FileExists("FileName.txt") Then MsgBox "this is first time" End If before adding above code , you have to add reference for it (Goto Project Menu , Select References and then Select Microsoft Scripting Runtime) hope this helps you to solve the … Read More

  • why use **FileSystemObject** when it can be done without it ?? this should do the work :- Private Sub Form_Load() If Dir$(file_path, vbNormal) = "" Then ' <--- file doesn't exist ' Create the text file Else ' Continue with the execution End If End Sub where **file_path** is the … Read More

0

You could use an if statement: (like the following)

If System.IO.File.Exist(".txt location") Then
    'Proceed
Else
    'Don't Exist
End If
1

If you add a reference(Project menu) to Microsoft Scripting Runtime, you'll have access to the FilesystemObject which has a FileExists method. Using that should give you what you want.

btw joshl_1995 that's .net code

Edited by tinstaafl

1

You can use this following code :

Private Sub Form_Load()
    If Dir$("D:\dani.txt", vbNormal) = "" Then
        MsgBox "This is your first time"
    Else
        ' Do anything if text file exist
    End If
End Sub
1

This should work :

Private Sub Form_Load()

   If Dir$(file_path, vbNormal) = "" Then ' <--- file doesn't exist
      ' Create the text file
   Else
      ' Continue with the execution
   End If

End Sub

where file_path is the relative or complete path of the file ( along with extention .txt)

Edited by mridul.ahuja: modification

1

try this :-

Dim fso As New FileSystemObject
If Not fso.FileExists("FileName.txt") Then
MsgBox "this is first time"
End If

before adding above code , you have to add reference for it (Goto Project Menu , Select References and then Select Microsoft Scripting Runtime)

hope this helps you to solve the issue

Edited by rishif2

1

why use FileSystemObject when it can be done without it ??

this should do the work :-

Private Sub Form_Load()
   If Dir$(file_path, vbNormal) = "" Then ' <--- file doesn't exist
      ' Create the text file
   Else
      ' Continue with the execution
   End If
End Sub

where file_path is the relative or complete path of the file ( along with extention .txt)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.