Saving configuration of current form/opening multiple others.

DanielB33

Active member
Joined
Mar 29, 2013
Messages
40
Programming Experience
1-3
Thanks for peaking at my post - and for letting me post numerous questions here! Its been a great help.

I have a form with a bunch of text boxes, buttons, modes, etc. I need the user to be able to click "save as" and "save" and save a file (where ever they want) and after opening the main desktop icon, open these files and go back to there original settings. This being said, they need to save them where ever they want to.

So far, everything I have done with vb.net has been a cake walk, but I seem to be missing something here? The open-dialog and save-dialog don't seem to be the way to go.

I would love to use the My.Settings.Subject to save settings, but the problem here is when I change these, I over right my core applications settings (the settings in the icon on the desktop)

Is it difficult to make files that the user can double click that will automatically launch my application with the configurations they were using when they saved the file?

If I am opening pandoras box I can just have them copy and paste the main application and change the name of the icon...but this is a pretty crude method.

Thoughts?
 
So far, everything I have done with vb.net has been a cake walk, but I seem to be missing something here? The open-dialog and save-dialog don't seem to be the way to go.
The OpenFielDialog and SaveFileDialog are absolutely the way to go if you want the user to select files to open and save.

Implementing Save & Save As
Is it difficult to make files that the user can double click that will automatically launch my application with the configurations they were using when they saved the file?
It's very easy to do that. It's done in two stages that are independent but work together.

First of all, you have to map the specific file extension to your application. This is done in the OS and the exact details will vary depending on the version of Windows. In Windows 8 (and Windows 7, if I remember correctly) it is done via the Default Programs applet in the Control Panel. Associating your application with a file extension will cause your app to open when a file of that type is executed. The path of the file that was executed will be passed to your app as a commandline argument.

The second step is to get your app to act on the commandline argument. Note that this can be done whether your app is associated with a file extension or not. It's still possible to pass a file path as a commandline argument from a console window or a shortcut. There are three main ways to get the commandline arguments passed to your app:

1. Via the 'e' parameter in the Startup event handler of the application.
2. Calling Environment.GetCommandlineArgs.
3. Via the My.Application.CommandLineArgs property.

2 and 3 can be used anywhere but would usually go in the Load event handler of the main form. Once you have the file path from the commandline, you treat it as you would any other file path, opening the file the exact same way.
 
Thanks for the reply - I am having trouble with one part though.

Mapping an extension makes sense, but how can I make a file unique to my program. I don't want all .txt files opening with my program, but I want to export a .txt file or similar? Is there a way to do this? I need to make only the files that the user saves open to my application.

Thanks
 
I have the save as...save and open stuff working great. But I still am unsure about the command line things. How can I use these to read the text file at launch? I need the user to be able to do the "open with" from the text file and open my app with saved settings.

Ideas?
 
Got it! Code was as simple as follows:

Dim s() As String = System.Environment.GetCommandLineArgs()
GlobalVariables.File_Opened = s(1)

GlobalVariables.File_Opened holds the file name and now I can open it and see settings.
 
Thanks for the reply - I am having trouble with one part though.

Mapping an extension makes sense, but how can I make a file unique to my program. I don't want all .txt files opening with my program, but I want to export a .txt file or similar? Is there a way to do this? I need to make only the files that the user saves open to my application.

Thanks

The OS doesn't distinguish files other than by file extension. If you want a file type specific to your app then you need a file extension specific to your app. Make one up that is appropriate. The characters for the extension is preferable but not required. Keep in mind that the file extension is just a label and, while it is intended to indicate the type of content the file has, it doesn't control that content. Think of a jar with a label on it that says "Sugar". Does that stop you putting salt in the jar? You can put any content you want in any file with any extension. If the content doesn't match the type of content expected for the file extension though, you'll have some problems when it comes time to use the file.

If you want your own file type then it's up to you to decide what the file extension will be and what the content format will be. Just try to pick and extension that isn't already commonly in use. It can be a good idea to provide two extensions so that users who have some other app that uses one that is the same can still use your app with the second.
 
Back
Top