Visual Basic Projects

By Merle Nicholson, President, Tampa PC Users Group


As all our members know, we have a Visual Basic SIG that’s doing well. It’s well attended and interesting. I’d like to mention something to some of the members of that group and anyone else who is just beginning to have an interest in programming. Here it is, and you can quote me on this. "You have to do it to learn anything about it". It isn’t like going to a history class where more study improves your performance. It’s more like learning to drive. You can study it forever, but as we all know, 99.9% of the skills you learn is doing the driving.

I’d like to present two very recent projects I’ve done by way of illustrating some of the useful things you can accomplish with programming. One is an Address Book, and the other is a picture re-size calculator. I’m not going to give you any programmer-type language here, just what it does and why I did the projects, so read on.

Address Book

What this world does NOT need is another address book. Definitely. But I have this project as an aid for the VB classes I teach. Also the address books I’ve looked at don’t quite fit what Valerie and I use one for. We have this small brown book by the telephone downstairs that has, yes, names and addresses, but also things like peoples’ birthdays, and when their children graduated from school, and things like what kind of illness their mother has. This way Valerie and I can kind of know what each other knows about people we talk to and send cards to. One thing that it doesn’t have though that we need is say the phone number to Ho Ho’s so we can order carryout, things like that, that would definitely make that little book too complicated.

Also, it’s downstairs. My part of the house is in an upstairs "office". Valerie’s computer is downstairs, and both are networked to the server, an ideal place to keep a central database. So why not? I revamped the fields some, and added a search field. Note in the picture, the example has "wildflower florist" in it so you can search for either word. Also simply typing in a "w" got to the first record that has a "w" in the first word. The search works just about instantaneously, and the upper right navigation buttons allow you to page through all qualifying entries. In this case all records that start with a "w" in the search field.

I deliberately do not search through Last Name, First Name as you would expect. Instead, you must enter some category words in the search field. In the case of personal friends, perhaps starting with the last name, but if you normally refer to a person as "Dan", that’s all you’d put there. Maybe Ho Ho’s would be "Ho Chinese food". Notice that there are four telephone entries and two email addresses. Valerie and I have four telephone numbers between us, not counting the modem phone, so for version 2, I’m considering just a free-form box for telephone numbers.

We’ve just begun putting all the "little book" entries in, and by the time we’re done, I may have changed the appearance completely. Also I may give it a way to address envelopes and also some way to go through and check off about thirty entries to do Christmas envelopes. It may just be a Word Basic program instead that accesses the database independently. We’ll see. In my household a program is never done.

address.jpg (33122 bytes)

PixCalc

This is one that I really had fun with. It took about three or four hours to program, and it takes a bit of explaining. When I got Paint Shop Pro 5, I discovered a new (for version 5) feature. It shows any picture with a ruler on it, showing the size of the picture in inches. And I’m REALLY interested in this, because I want to place these pictures on the printed page. I want to print a picture out say as a 5 by 7 or 8 by 10, or I may want to place six small pictures on a single page. If you "scale" a picture you must maintain an "aspect ratio" to keep the picture from being elongated or distorted. So how does a picture that is 5.389 by 2.750 at 72 pixels per inch fit into a 5 by 7, or 7 by 5? Probably not too well unless you do some accurate calculations. I’ve been doing this with a calculator for a while. And it’s just a simple matter of proportions, some straightforward algebra. But it’s tedious, and many times you must do it a number of times to decide what to do. As you increase the size, one dimension or the other will meet the target dimension, but the other won’t if you maintain the original aspect ratio. So you need to know the final dimension, and sometimes you want to know how may pixels to add left and right or top and bottom, so you can sometimes add a border to fill out to the required dimensions.

Some experimentation shows that the initial size in inches is determined by the resolution in pixels, at 72 pixels per inch. Now let’s say if it’s high resolution you don’t just want to scale the picture and maintain 72 pixels per inch. What you really want to do is increase the pixels per inch to reduce the physical size so that either the width or height meet the target printed size.

And this little baby does all that all by typing in the initial size in inches and the pixels in inches. Paint Shop Pro gives you this on the Image, Resize panel. That automatically fills in the Initial Pixels. Sometimes because of round off error, those two pixel numbers may need changing by one or two, and you can do that.

Then you fill in the Target Width and Height and automatically, the new (Final) Pixels/In and the Final Width and Height are calculated. Internally, a judgement must be made about which dimension is reached first. In the example shown, the height target was met, and the width was not. It’s short of meeting that target by .73 inches. And if you were to add 73 pixels on the left and 74 pixels on the right, the picture will be exactly 7 by 5. In Paint Shop Pro, you can add borders like this in any color you like. Doing it in white just makes it easier to center the 7 by 5 on the printed page. All you need to do is plug the Final Resolution number in PSP’s Image, Resize panel, and it’ll print exactly the correct size.

pixcalc.jpg (32347 bytes)
That’s it! Except for the About panel, which I’m showing here also. The System Info is interesting, I think. It’s the same one that you see on the About panel in MS Word. This About panel was made from a Wizard in Visual Basic, with some modifications. If you’re interested in this program, I’ll be happy to send it to you by email. The only catch is if you have the Visual Basic 5 product, you don’t want this. It’s written in VB 6, and the files play havoc with a VB 5 compiler product. As do ALL VB 6 programs. There’s no problem otherwise to everyone else. Send me email at merlenic@tampabay.rr.com and indicate if you want the source code also. u pixcalc2.jpg (19021 bytes)