I’ve recently been rewriting “MechMaker”, my version of a BattleTech construction program which can do all the maths for making a Mech and then print out a record sheet. The previous version died due to an USB drive crash (for some reason, I didn’t have a recent back-up), and so after a year, I’ve almost finished the new version.
Why not use something like Heavy Metal Pro or Solaris Skunkworks? Well, in the first case you’re talking about obsolete, unsupported software; in the second, I’m running a Sword and Dragon campaign and I want to be sure that the Mechs built have all the options available in that game.
Plus, I enjoy coding. I don’t do it as often as I should.
In any case, my program is *almost* up and running. The main thing left was to include a picture of the Mech on the record sheet, and to save it to file. Seemed simple enough: PictureBox.Load(filename). That part worked. Then saving: PictureBox.Image.Save(filename). Error! Error! Error!
What was going on was entirely bizarre. When I *load* a file, what I expect is that the file will be read into memory, be closed, and stay there until I save it again. With images in VB.NET, that’s not what is happening. Well, it sort of is: it’s just that when the PictureBox Image wants to save, it tries to read the data from the original file. To get around this, you have to leave the original file open (Use PictureBox.Image = Image.FromFile(filename))… until the save is over.
It’s bizarre behaviour.
There’s probably some good behind-the-scenes reason why it works that way, but for those of us amateur coders (yes, I know I do get paid for programming in my job, but I spend a lot more time with databases and SQL), it’s completely obscure behaviour. Apparently it isn’t just me, either – there was plenty of advice online about the error.
The final code looks like a real kludge to me, but it should work. I guess I’ll see when we really get into the modifications of the mechs in the campaign.