0

As I mentioned before, I am hardly a programmer, so I once again need the expertise of those that are...

I am working on a program that will help me manage some data for a volunteer emergency communications group. In this program I currently have multiple different structures built for multiple different objects (if I am using the term correctly). I have a structure for Site Personnel, a structure for Members (yes they are different), a structure for Operation Info (considered its own object), and a structure for Facility. This was all fine and well, even having each element of the structure defined with <VBFixedString(nameOfConstant)> to ensure an equal record length.

And that is where I hit my problem. Each object (again I hope I'm not butchering this term as I am calling the Facility or the Site Personnel etc the 'object') is a set of fields for a random access file (I abandoned the Excel file idea, way too much headache and nothing but failures on that front, I'll use an in-house system). And, certainly to all of your dismays, I did finally decide to go with FileOpen, FileGet, FilePut, etc for my random access file management (I can already hear your teeth grinding and your skulls crackling to epic facepalms, but believe me I NEED to go simple for this presentation version and for the Version 1 Release which will be beta tested at a National Disaster Medical System exercise in May). The problem I encountered is that each file will need its own filenumber, its own position, and so on, and each one will need a Dim Temp as <structure> where <structure> is SitePersonnel, OpInfo, MemberData, or other relevant structure. Each file will also need its own file handling controls, such as GetRecord, PutRecord, DeleteRecord, NextRecord, PreviousRecord, AddRecord, and so on, and each file will need its own functions for file opening and finding the last record. The reason each structure will need its own copies of this code is that I cannot find a way to pass in a variable to a module-level function such as Public Function FileOpener(ByVal FileNum as Integer, ByVal StructureName as String, ByVal FileName as String, ByVal AccessType as String) and in the code define Dim Temp as (StructureName) where StructureName would be a String value for the actual name of the structure. And finally, I decided to have the redundant file handlers in each object since at any time there can be two or more of these file open, reading, writing, and seeking. Last thing I need during an emergency is for a module-level function to get confused and return the wrong data.

Now that you have the background, this is where I really need some advice. I am aware that structures can have Functions, so I could code each of these functions into the structure. However, I have also started thinking that an object this complex and that can do so many different things may just belong in a class instead of a structure. I am not familiar with classes in Visual Basic, but I am familiar with Classes from Java, if there is any similarity between the two on the OOP level. So my question is this: Would this example be better (and more reliably) handled in a Structure, or in a Class? And if in a class, would I be best off with each Class in its own file, or should I combine all of these classes into one Module (mainly for clarity and ease of maintenance)?

I apologize again for any permanent damage I have caused anyone here by my sub-newbieness and painful choice of code, and I thank you ahead of time for helping a sorta-noob get back into the swing of things (last Visual Basic program I wrote was when Visual Basic 4 was hot off the press, yep, that long...).

Michael Tant
  • 25
  • 1
  • 5
  • Sorry, this is not a design consultation service. You apparently already know what most professionals would advise: dont use flat files. Its 2016 and Access is bloody simple to use – Ňɏssa Pøngjǣrdenlarp Feb 08 '16 at 17:28
  • I apologize you're right I need a different forum for this question. And in the spirit of honesty I can assure you I don't know anything the professionals know, my knowledge amounts to about a sliver of what a professional has forgotten :) I will google the interaction between VB.net and Access, but if it's anything like Excel then my brain cells are already mourning the death of at least 10,000 of their friends lol. Another reason for not using Office bindings is that the program needs to run very lean and not require any additional software such as Office, it needs to be standalone. – Michael Tant Feb 08 '16 at 17:36
  • Using an Access database doesnt require Office. It is ultimately just a file to hold related data for your app. If every aspect of the project seems over your head, it might be better handled by a consultant. I spent a great deal of time in the late 90s redoing apps that otherwise bright biz types started in Access-vba but eventually their "design" ran out of stream. Sometimes very quickly. – Ňɏssa Pøngjǣrdenlarp Feb 08 '16 at 17:45
  • 1
    What Plutonix said. You've spent an awful lot of that big paragraph essentially saying 'I need to re-invent Access' – peterG Feb 08 '16 at 18:50
  • You are right, I will not disagree with that. I will do this though. Can you provide me with a few links to give me some examples of creating, modifying, reading from, and writing to, an Access database file from within a vb.net program? Again I do need to keep the entire solution encapsulated and not require that any users, even administrators maintaining the databases, need any additional software. From the operations side, the computers this is installed on will not have Office at all. For DB Admin, they should be able to work from within this program and not need Office installed. – Michael Tant Feb 08 '16 at 19:41
  • Plutonix, you are right, this project is mostly over my head, but that was my point all along. Truth is we already have an old-school solution we use (pen/paper) and it is still accepted. I took on this project to A) provide a modern solution, and B) learn vb.net programming. I don't have to do this, I am doing this so I have a project to learn with and will produce something a bit more useful and challenging than "Hello World". In that regard, can you perhaps recommend a forum for inexperienced yet determined newbies? Thanks for your suggestions on Access as well, I'll check it out :) – Michael Tant Feb 08 '16 at 19:44
  • It is hard **not** to find VB-Access related questions here...like [this one](http://stackoverflow.com/q/29186317/1070452). The system need not require Access/Office for admin; most apps I've had which use Access (very few of late in favor of MySQL) are configured to keep users out. I dont need their "help". The app takes care of things like backing up, compacting etc. – Ňɏssa Pøngjǣrdenlarp Feb 08 '16 at 20:07

1 Answers1

0

For a system like yours, to manage users and other objects, I recommend the use of classes. They usually get used for management system as they offer the abbility of hierachical variables and functions, so you don't accidentaly call an internal function or access a variable you shouldn't. Also, classes are more flexible than structurs, so you should preferable use them when you aren't sure wether a class or a structure is the better way.

As Plutonix pointed out before, this is not a platform for recommendations, it is for problems with code. So next time, please go to a VB.Net forum. The text written above is my opinion based on my knowledge about the difference between classes and structures and this msdn-article. Further internetresearch is still something you should do, maybe ask in forum or friends / other programmers you know.

Tgrelka
  • 31
  • 5
  • I was unable to upvote this due to my limited reputation since I've only been here a short time, but UPVOTE :) Thank you so much, that is what I needed to know. In Java this would have screamed Class so I had a feeling here as well. I will be making the conversion today, and since I did classes in Java I'll at least be minimally familiar with it. I do have one regarding code. In `Dim Temp as New Facility` whether `Facility` is a structure or a class, how do I destroy Temp? There are times when I need to read a file into a combobox or array and then kill it to reclaim memory. – Michael Tant Feb 08 '16 at 20:32
  • 2
    You don't need to manage memory in that way in VB.Net. Once it goes out of scope, the garbage collector will deal with it. Look, I think you need to just bite the bullet and buy a book or two ( I recommend Programming Visual Basic 2005 by Balena, even though it's a version or two behind, it's very accessible) - you can't teach yourself VB.Net one SO question at a time ;-) – peterG Feb 08 '16 at 20:46
  • A possibility of disposing a variable, which is not needed though, es there is the garbage collector, is (I think) by setting it to `Nothing` with `myVar = Nothing`. This can be done with arrays and single variables, as well as classes (If I remember correctly, I've been using C# since 2014). For connections with databases and streamreaders, you should use `.Dispose()` after closing them. – Tgrelka Feb 08 '16 at 21:01
  • Thanks everyone for the input on this, you've all been great. peterG I will hunt that book down and add it to my library, if you have any other book suggestions I'm open to all of them. Like I said earlier I won't lie or pretend to be a programmer. I have written a few (maybe around a dozen) programs between 1994 and now (with the exception of the two Java courses I had to take in college for networking) and none of them were advanced at all. I'm very much a newbie and still learning the stuff you consider easy. I'll get there eventually, it'll just take time and experience. – Michael Tant Feb 08 '16 at 23:26
  • If I still may ask a question, I understand that you are a newbie, still learning .Net languages, but why you don't start experimenting with small and simple programms, get experienced and then put them all together to one big programm? – Tgrelka Feb 08 '16 at 23:30
  • Tgrelka thanks for your suggestion on the garbage collector, something I am somewhat familiar with from Java. The main reason I was asking is that at the time I was dealing with a temporary structure object that may not have gone out of scope right away. I will also need this with the class object since it may not go out of scope right away but its usefulness will, so I wanted to know how to dispose of it when its work is done even if the variable is still within scope to maintain the lightest memory footprint for the program at all times. Awesome response and thank you :) – Michael Tant Feb 08 '16 at 23:45
  • I had thought about doing that Tgrelka, but my big problem is that it's hard for me to just come up with generic non-useful programs for learning; I have to have a definitive end goal with something that has a useful purpose once it's done. This helps me learn by forcing me to think about the program and the code rather than just doing some copy/paste examples which teaches me nothing, and it gives me an end product that is unique, challenging, and can be tested real-world to see if my product meets the design specs. I agree with your idea, it's just that I learn differently than others. – Michael Tant Feb 08 '16 at 23:50
  • I did learn in a similar way, just wanted to help as many other people have problems with big projects right at the beginning. Of you want, we can get in touch as I am a quite experienced programmer and can help with some workflow and other small optimizations. Just go to my profile and see my email – Tgrelka Feb 08 '16 at 23:54
  • I will definitely do that, and thank you :) I just have a different way of learning. I could sit and copy code all day long from a book and watch how it reacts, but I won't learn the underlying theory and syntax nuances. By coming up with an original idea, I can still use examples out there but I am forced to think through them and change them to suit my goals. Also, if the program I am writing has no use beyond the learning I have trouble focusing the code in a direction and I get bored of it and abandon it. With this program having a real world application, I will feel obligated to finish ;) – Michael Tant Feb 09 '16 at 12:24