-
I've got two questions which (I hope) will be simple.
1) I made a program that loads a highscore file when it starts. The only thing is, If the highscore file isnt there, it give me a runtime error. Can I make it either create the file or have a message saying "you must have the highscore file"?
2) Can I put some kind of code into the exit button at the top right of the form?
Thanks,
Spie
-
1) Use the Dir() function to check if it exists.
Code:
Private Sub Form_Load()
If Dir("HighScoreFile.txt") <> "" Then
'Hi score file exists
Else
'Hi score file does not exist so display a MsgBox
MsgBox "Make sure you have a high score table"
End If
End Sub
2) The QueryUnload event
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'If the X is pressed then
If UnloadMode = 0 Then
MsgBox "Quitting..."
End If
End Sub
-
Code:
'in declarations
private Type Highscores
Names(9) as string * 20
SCore(9) as long
End Type
private hs as highscores
'To save
Open file for binary as 1
put#1,,hs
Close 1
'To load
Open file for binary as 1
get#1,,hs
Close 1
This way it won't show you any errors, it creates a file whenever there's not and reads empty scores in such case.
-
Ok, I'll try that. Thanks