Now, I would like to share some tips on how to make array manipulation easy for you. Believe it or not, I just realized it when I started working as a programmer.
What Is An Array?
An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier.
As I am creating programs, I seldom use arrays. Or let us say, I am not using it most of the times. I’d rather declare more variables instead of memorizing array indexes. And there’s a thing I realized. As long as you move away from using array, the more you will know the importance and ease of using it.
Tip #1: Use arrays often.
Instead of declaring the usual variable, declare them as arrays. You might call me crazy or over acting for it. But I promise you, it will work. The more you became familiar of using it, the more you can understand the use of it. I am not that good in using array, I admit that. But I improved already using it.
Let me cite an example. Have you ever used command buttons in VB? Yeah, I know. That was a fool question because I know you love command buttons in calling an event. Okay, my example is a simple (SIS) Student Information System. That was my last VB project in the Computer Programming 2 course.
In that simple system, you are going to use few buttons – ADD, EDIT, DELETE, SAVE/UPDATE, and EXIT. So, that would be 5 buttons. This means, you have 5 objects. Isn’t it? Yeah! You are good in counting huh!
Now instead of having 5 objects, why don’t just having only one? I mean five objects in one module.
Create your modules for each event, one module for “ADD”, another for “EDIT”, and so on. So you will have a total of five modules.
On your form, put a command button. Name it as CommandButton. Then, copy it and paste it in the same form. When you do that, VB will ask you if you want to make it a control array or not. Choose “YES” so you have a CommandButton array. You will now notice that the name of the original CommandButton is now CommandButton(0) and the new one is CommandButton(1). The numbers are what we call the index. Now, do this step until you have 5 buttons (up to index 4).
I am a little distracted when it comes to index because it started with zero (0). So, if you feel the same, paste again another button – CommandButton(5) – and then, delete the one with index zero – CommandButton(0).
You now have five buttons – from CommandButton(1) up to CommandButton(5). Actually, with that step, you only have one CommandButton with five indexes which is good in saving space in computer’s memory.
Change the caption of the buttons with “ADD”, “EDIT”, “DELETE”, and so on. Then double-click any button. That will prove that the five buttons are actually just one button.
Use SELECT Case statement like this.
Select Case Index
And that’s it! See how it works.
Now, let’s go to next tip.
Practice Tip #1 often. And you will just realize that you’re slowly getting rid of Ouch brought by array.
That’s all. I hope you learned.