creating a custom class

KPAdmiral

New member
Joined
Mar 29, 2006
Messages
1
Programming Experience
5-10
I'm a pretty intermediate programmer, and have never really needed to delve into making classes, as when I worked with previous versions of VB, you could simply make a module with simple functions to do most of what I neded. With VB.NET it seems because of the intrinsic OOP nature, everything is an object, and to do anything easily or to manipulate it, you need a class, either native or of your own coding.

My perdicament is, I'm reading ini file data from a legacy program, yes I know I can use the registry, or XML, but I am working with pre-existing data that must be read as an INI, and written as an INI.

I came up with a simple regexp to extract all of the sections out of the string data from reading the entire ini file, and then extracting all of the entry key/value pairs from that. So obtaining the data is no problem, parsing it, is also of no serious consequence, my problem is accessing it in a simplistic manner, as well as for code reuse.

I tried making a class that looks something like this.
clsConfigurationFile
Properties: Count as Integer
Methods: Clear
Fields: Sections() as clsSection
clsSection
Properties: Count as Integer, Name as String
Fields: Entries() as clsEntry
clsEntry
Properties: Key as String, Value as String

basically what I want the class to do is, after create a named instance of the class, perhaps populating it through the New constructor, I can simply type something along the lines of this to get my values.

VB.NET:
Dim SomeConfigFile as New clsConfigurationFile(strContents)
 
strKey = SomeConfigFile.Sections(1).Entries(1).Key
strValue = SomeConfigFile.Sections(1).Entries(1).Value

Given that the index supplied in the brackets is the index of the section, and the entry within the respected arrays in the class, but when I run my program, and supply the information, when I query I don't get any value back, but empty variables.

I don't know, I'd post my code, but it really is as simple as what I described above, any suggestions on any alternative ways about the approach I am using, or perhaps a more structured way of simplifying the querying of the information I need from the ini would be great.
btw, I know there are API calls and methods I can use within the .NET enviro, but I want to stick to managed code and memory, or a pure vb code way of doing this.
 
I havent read your whole post, just briefly glanced at the bottom of it where you mentioned that you want to stick to managed code. Well just FYI even if you do make an API call in vb.net it is still managed code and i dont believe there is any perfomance hit for using an API call. So you don't need to worry to much about that.
 
Back
Top