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

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

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

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

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

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)

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

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)

Be a part of the DaniWeb community

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