|Greetings. This is the first time I've ever posted here, so I supposed introductions are in order. The name is SawmillTurtle. Sawmill because I used to live on a street with that name, and Turtle because my friends used to say I look like Franklin the Turtle. I don't see the resemblance, but it makes for a good screen name.
For the past few months, I've been writing a program in C# for my landlord that keeps track of her rental properties, accounting and maintenance issues. It's an all-in-one kind of thing. I've been using SharpDevelop because of my intense hatred for any and all things Microsoft. I actively avoid using anything they make, so that means I don't use Visual Studio. A good alternative, some say, would be MonoDevelop but Microsoft owns that, too.
Up until I started on this project, I'd only tinkered with C# while playing with Unity. My IDE of choice was Game Maker because of the ease of use and the speed at which a program can be written using it. You can go ahead and laugh. It's funny. Game Maker is a good tool for learning programming concepts, but once you have it down it is really best to leave it behind you. I thought I could take everything that GM taught me and use it when I made the transition to C#.
Keep laughing. It's still pretty funny.
What I thought I knew going into this project and what I actually knew are two very different things. I've learned so much over the past few months. Looking back at the early sections of the code is like looking at a car with square wheels. Looking over it, I keep going, "Now why did I do that" and "What in the world was I thinking". One of my biggest mistakes-- and I just figured this one out yesterday-- was creating classes and then creating separate forms for those classes. It never occurred to me to make them one and the same.
Take this, for instance:
public void edit(BindingList h)
foreach(HouseHold house in h)
What you are looking at is part of the "Household" class. What this does is take all the necessary variables and pass them as arguments to HouseholdForm. If the user clicks the "Save" button, it passes back "saveMe" as true, which makes the class retrieve the edited values from the form. Then it switches its own "saved" flag, which MainForm uses to determine if it needs to update something.
Do you see how stupid that is?
Would it not have been easier to build the "Household" class as PART of "HouseholdForm"? Then I wouldn't have had to pass a bunch of variables and then retrieve them. Chalk that one up to inexperience. I'm planning a major overhaul where I correct this error, but that is going to be a tedious process. Since the program is functional-- albeit sloppy-- the way it is, my priority is getting my landlord the program she's been waiting for. The first update will include the cleaned up code.
Going into this, I had no idea what I was getting myself into. I've had to ask Google a LOT of questions, and most of those have pointed me to Stack Overflow. There have been days I've wanted to rip my hair out, and there have been days where I've had a lot of fun. Today was NOT one of the fun ones. I spent the better part of three hours trying to eliminate a bug that didn't seem to exist at the first, second, third... and hundredth glance.
I found it here, in this section of code:
foreach(bool paid in h.account.payment)
See, I was creating a DataGridView that displays all households that owe rent. The "HouseHolds" class has a class called "Account", which has several Binding Lists. Like this:
public BindingList<datetime> dateOf=new BindingList<datetime>();
public BindingList<double> amountOf=new BindingList<double>();
public BindingList<string> description=new BindingList<string>();
public BindingList<string> displayName=new BindingList<string>();
public BindingList<bool> payment=new BindingList<bool>();
These lists are all created, edited or erased at the same time. The "payment" Binding List is used to determine is someone OWES rent or is PAYING rent. So in the Switch statement at the top, I was using IndexOf and passing the number. It kept double or triple charging things. Sometimes it wouldn't charge them at all. I figured out that using IndexOf this way was wrong, because it was looking for the first Boolean value that it found in "amountOf" that matched what it received from "payment". Obviously, not a good idea. At one point, the program reported a household as owing over 1800 dollars in back rent. Oops.
So it's been an interesting journey. I think after I finish this, I'm going to try my hand at MonoGame. Eventually I'd like to work my way up to Unity. Maybe next time I'll actually be able to use it without having it go haywire.
First, though, I really need to figure out what casting is, because I have no idea what people are talking about when they mention that.
Thanks for listening.
Hope to talk to all of you very soon.