I am trying to code frogger (yes still) and For the highscore... when the user first runs the application there is no text file for the highscores. How would I go about making it? or an If statement like:
In PsuedoCode:

If File Does not Exist Then
Create HighScore.txt
Else
open highscore.txt
variables = highscore.txt information
EndIf

Any suggestions?

Something like

On Error GoTo FileError
    Open FILENAME For Input As #1
    '' if the file did not open you will jump to FileError below

    Exit Sub  '' you are done, so you don't want to fall into 
              '' the error section

    
FileError:
    On Error GoTo 0
    '' do what you need to do if the file did not open
    '' which includes checking what the error was and 
    '' processing accordingly
End Sub

Hi,

You could also check to see if the file exists:

isFile = Dir(FILENAME)

isFile will be blank if the file is missing or contain the filename if it is there.


pG

mkdir directoryname will make the directory

open filename as #1 for output will create the file or overwrite an existing one.

ok... I keep getting error 75 "Path/File Access Error"... any suggestions? my code is as follows:

On Error GoTo FileError:
    Open "C:\t3hfr3akGames\Frogger\Data.FRG" For Input As #2
    Do While Not EOF(2)
    Input #2, StrName, intHighScore
    lblHigh.Caption = "High" & vbCrLf & StrName & " " & intHighScore
    Loop
    Close #2
    GoTo Worked:
    
FileError:
Close #2
ChDrive "C"
MkDir "C:\t3hfr3akGames"
MkDir "C:\t3hfr3akGames\Frogger"
lblHigh.Caption = "High" & vbCrLf & "CLD 3000"
    
Worked:

ok... I keep getting error 75 "Path/File Access Error"... any suggestions? my code is as follows:

On Error GoTo FileError:
    Open "C:\t3hfr3akGames\Frogger\Data.FRG" For Input As #2
    Do While Not EOF(2)
    Input #2, StrName, intHighScore
    lblHigh.Caption = "High" & vbCrLf & StrName & " " & intHighScore
    Loop
    Close #2
    GoTo Worked:
    
FileError:
Close #2
ChDrive "C"
MkDir "C:\t3hfr3akGames"
MkDir "C:\t3hfr3akGames\Frogger"
lblHigh.Caption = "High" & vbCrLf & "CLD 3000"
    
Worked:

Since you never create the file 'Data.FRG', you end up in FileError where it tries to remake the same dir. Thats where the error is coming from.

Try this
After: MkDir "C:\t3hfr3akGames\Frogger" add:

' Create empty file
Open "C:\t3hfr3akGames\Frogger\Data.FRG" For output As #1
close #1

Here ***attached*** is an RTF Editor i made for tutorial reasons it includes some functions like:

  • Spell Check
  • Word Count
  • Find and Replace

Then some basic functions you seem to need like the saving and opening of files ;)

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