Posted on March 27th, 2007
4407 views
prerequisites: For loop, general controls
arrays are like lists, like a grocery list. arrays are an easy way to hold lots of data and load it. Before we start i want to cover soem code we will be using so you dont get scared or discouraged from the code. Below are some functions i will be using today, they all deal with arrays. I will not be covering multi-dimensional arrays in this tutorial. 1. load a new standard exe project. we are going to add some controls to the form, a command button and a listbox. It does not matter where you place these controls, just get them on the form. the names of the controls are listed below.
2. make your way to the code... Private Sub Form_Load() we are going to load some arrays into the listbox using a for loop. First let's see how to use an array in code. names = Array("george", "john", "paul", "another", "name") this code will add paul to the listbox, list1. When arrays are use the way i have used it there, each data in the array is given an id starting with 0. so george is 0, john = 1, paul = 2... get it? good. We want to load all the values without having to do a .additem for each item in the array. we will acheive this by using the FOR loop. 3. we can find the "upper" and "lower" number of an array, as in how many peices of data its holding. we do this with ubound and lbound. lbound and ubound are functions that are used with arrays to help you keep track of and order arrays. Hopefully you can tell which one is the upper and which one is the lower. You may know this process as "bounds checking" lowest = LBound(names) now that we have the numbers for our FOR loop we can set it up... Private Sub Form_Load() 4. now that we can use our array listing, without unnecessary list1.additems galore, let's do soem more array checking. this time we will check to see if an array is an actual array. we do this ith, you guess it, ISarray. lol how easy eh? IsArray() returns true is an array is an array, or False if its not. MsgBox IsArray(names) 5. here is my final code. there are a couple more things about arrays but this should be more than enough to get you started. if you need more, there is always the MSDN webpage, and google. Private Sub Command1_Click() |