Publishing in vb.net
Hey, ive recently created a simple tetris game in vb.net. i want to publish it but after it finishes publishing and installing, when i run it, it gives me an error stating:
<br/>
Can anyone help me here?
It looks like you hard coded the path to your highscores file (which isn't wrong per se), and that you hard coded it as an absolute path, which only works on your computer. Try using a relative path instead.
How would i do that? sorry bout my limited understanding, this is the only way ive been taught to do this.
My current line of code for this is:
thanks
My current line of code for this is:
FileSystem.FileOpen(1, Application.StartupPath & "\Highscores.txt", OpenMode.Input)
thanks
Quote:Original post by AncientHunter
How would i do that? sorry bout my limited understanding, this is the only way ive been taught to do this.
My current line of code for this is:
*** Source Snippet Removed ***
thanks
Keep in mind that I am not very familiar with your environment (Mac user myself), but what if you try just using "highscores.txt" as the path? My rationale here is that the app should start with paths relative to the application, and if your code snippet is correct, Application.StartupPath is ending up in some temporary settings directory.
You should store such files in the user's own profile area, as you are not usually permitted to write back to the application's own directory unless you are running the application with administrative rights.
You can use the Environment class to work out where to store the data files. For example, this function:
...returns a filename in the form C:\Users\Ben\AppData\Roaming\AncientHunter\Tetris\Highscores.txt (the exact path depends on the username and version of Windows).
You may need to copy (IO.File.Copy()) a default file there the first time your app is run (use IO.File.Exists() to check first) which could come from the application's own directory. I strongly recommend you take a look at the System.IO namespace, rather than using features such as FileSystem.FileOpen which are provided for backwards compatibility with VB6.
You can use the Environment class to work out where to store the data files. For example, this function:
Private Function GetHighscorePath() As String ' Using IO.Path.Combine allows this code to work on platforms that don't use \ as a directory seperator. Dim RelativeName As String = IO.Path.Combine("AncientHunter", IO.Path.Combine("Tetris", "Highscores.txt")) ' This bit uses the application data "special folder", which is tied to the current user. Return IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), RelativeName) End Function
...returns a filename in the form C:\Users\Ben\AppData\Roaming\AncientHunter\Tetris\Highscores.txt (the exact path depends on the username and version of Windows).
You may need to copy (IO.File.Copy()) a default file there the first time your app is run (use IO.File.Exists() to check first) which could come from the application's own directory. I strongly recommend you take a look at the System.IO namespace, rather than using features such as FileSystem.FileOpen which are provided for backwards compatibility with VB6.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement