I know this is a dumb question, but I must be missing something simple and just can't figure it out. My program has a logfile to track things done with it. I'm trying to figure out what I am missing with creating the file if it does not exist. Am I missing something so simple? Or should I be writing this in respect to a True/False method?

Imports System.IO

Public LOGFILENAME As String = "C:\PFC Xpress\Logfile.txt")

Private Sub Form1_Load......

If File.Exists("C:\PFC Xpress\Logfile.txt") Then
    'Do Nothing
Else
    File.Create("C:\PFC Xpress\Logfile.txt")
End If

End Sub

I personally never check for existance of the file since at least the languages I use (C/C++/Java/Python) create the file as soon as you issue "writre" to stream. If you want to keep the content of the file and add to it, then use append. Append also creates the file if it doesn't exists. Other than that, what would you want to check for existence of the file?

Right now at form load, the file size is checked and if it is over the designated size, the file is deleted. This is the main reason for checking if the file exists. Also, in the case that someone finds where the file is and deletes it, is another reason. Not sure if just deleting the file over the size limit is the best approach. It was just all I could think of doing at this time since I'm so new to .net and programming in general.

maybe you should change shlash into double slash. In many popular C-like and Java-like programming languages, it's defined that \ in string means expressing some special charcode in regular charcode.

I don't mean to sound stupid, but I actually know nothing about VB.

Dannyniu... It's been over 10 years since I've written program in VB (basically VB 6 if I'm not mistaken) but if I remember correctly, you didn't need to have 2 backslashes.. Although some specific languages like Python require 2 backslashes. However it wouldn't harm if you try that and see if it works.

Gus, if you could post your actualy code, it might make a difference for us to take a look at it.

This article has been dead for over six months. Start a new discussion instead.