Page 204 - DCAP408_WEB_PROGRAMMING
P. 204

Web Programming




                    Notes          ASP Code:
                                   <%
                                   Dim myFixedArray(3) ‘Fixed size array
                                   Dim myDynArray() ‘Dynamic size array

                                   %>
                                   We are going to focus on fixed size arrays first and cover dynamic arrays later on in this lesson.
                                   Assigning values to an array
                                   Let’s fill up our fixed size array with values. Our fixed array  is going to store the names of
                                   famous people. To assign a value to an array you need to know three things:
                                      The name of the array

                                      The value you want to store
                                      The position in the array where you want to store the value.
                                   An array is a group of variables that you can access by specifying the position inside the array.
                                   Our array myFixedArray has four positions: 0, 1, 2 and 3. Let’s assign some values to our array.


                                          Example:
                                   ASP Code:

                                   <%
                                   Dim  myFixedArray(3)  ‘Fixed  size  array
                                   myFixedArray(0)  =  “Albert  Einstein”
                                   myFixedArray(1)  =  “Mother  Teresa”
                                   myFixedArray(2)  =  “Bill  Gates”
                                   myFixedArray(3)  =  “Martin  Luther  King  Jr.”
                                   %>
                                   ASP Arrays are Zero based!


                                   If  you’re a programmer  you  might look at that  above example  and thing “Hey, you  only
                                   allocated three elements for that array, but you assigned four values! Well, this can be done
                                   because arrays in ASP are zero based. This means when you declare fixed array of size X then
                                   you can assign values for each value from 0 through X.
                                   Below is perfectly functional ASP code that will go through our array and print out the contents
                                   of each element.


                                          Example:
                                   ASP Code:
                                   <%
                                   Dim  myFixedArray(3)  ‘Fixed  size  array
                                   myFixedArray(0)  =  “Albert  Einstein”






          198                               LOVELY PROFESSIONAL UNIVERSITY
   199   200   201   202   203   204   205   206   207   208   209