Public Group

# Publishing in vb.net

This topic is 3721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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:

FileSystem.FileOpen(1, Application.StartupPath & "\Highscores.txt", OpenMode.Input)

thanks

##### Share on other sites
Quote:
 Original post by AncientHunterHow 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.

##### Share on other sites
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:

    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.

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632168
• Total Posts
3004544

×