Well, careful there. Remember that writing good code doesn't necessarily mean writing
short code. Arrays are much easier to maintain, for one, and because they are collections, every object in the array can be referenced through the common array name.
A few notes about your sample code. First of all, never in
any language name an object
month. Now, depending on the language you're using, you can declare and dimension arrays in several ways. Of course, you can always dimension arrays as you did--explicitly assigning each index a value. However, every language with which I'm familiar has a "short-hand" method. In VBA, for example (a language with which I think you're familiar), that array could be dimensioned like so:
Code:
Dim saMonth() As String
saMonth = Split("January,February,March,April," & _
"May,June,July,August," & _
"September,October,November,December", ",")
And that's just one way to do it.
One neat thing about arrays is that, because the indices are integer numbers, you can use mathematical calculations to reference an index. So, for example, if you wanted every fourth month, you could do something like this:
Code:
Dim i As Integer
For i = 0 To UBound(saMonth)
If i Mod 4 = 0 Then Debug.Print saMonth(i)
Next i
This is just a really limited example. Most of the time, once you really start using arrays correctly, you won't necessarily know what object is at a specific index, nor will you have to. That's the beauty of collections like arrays: because they're all hooked to one reference (the array name in this case), you can perform an action on the reference and loop through its objects instead of explicitly performing the action on each object.
In your example of having a separate variable for each month, if you wanted to perform an action on each month--say, adding
-MM to the end of each name (where
MM represents the month's count, 01-12)--you'd have to do it literally twelve times. With an array, you could just loop through the indices and add the iterated value to the end of each object.
Arrays are almost intrinsically bound to
control blocks (think: loops). If you don't need a control block, you probably don't need an array, either.
Does this make more sense?
chris.