As a practice exercise at my college we have to make a simple room booking system, complete with its own config file. We’re not allowed to use the one built into VB.NET (the professor wants us to adapt to not relying on things like that) so I’ve made my own. This is a sample:
// Config file.
// First column is the variable name that will be used to
// reference the value in the second column. Seperate each
// setting with a new line.
MasterUser Chris
DatabasePath C:\Users\Chris\Desktop\Project.mdb
Comments in the file are pretty self-explanatory. I can parse the file fine, but what I’m having trouble with is making a variable the same name as whats in the first column. For example I need to make a variable called MasterUser and one called DatabasePath that holds Chris and C:\Users\Chris\Desktop\Project.mdb as values respectively. But I have no idea how to make a variable called that.
Any help would be cool, thanks. 🙂
EDIT: You can’t see it from the code view here, but the variable name and value in the config file are separated by a tab 🙂
You might want to consider using a better format for your configuration file, like XML. This will give you a lot more library support for parsing and searching within the file… that said, in this simple case, it looks like you just need a simple
Dictionary(Of String, String)which probably won’t make a lot of sense if you haven’t learned about Generics yet 🙂Basically you can load values in like this:
Then when you want to retrieve a value based on the key in the dictionary, you can do it like this:
I hope that helps clear things up.