Tuesday, September 6, 2011

array discussion

Now let's discuss about arrays

An array is a group of elements
It can have many dimensions
It can be displayed in a table, that is limited to 2 dimensions

The problem when you generate a table from an array is you don't know if there is 1 or 2 dimension(s)
An array with one line will have 1 dimension (one y (line) with many x (columns))
An array with 2 line, with 5 columns each will have 2 dimensions (the y and the x)
Y is the line (vertical dimension)
X is the column (horizontal dimension)

example:



Select S/N S/N 2 Symptom Problem Probability Confirmation
9 1 The carrier moves only in one direction One coil of the proportional valve is not well connected 0,65 2
67 1 FAULT HYDRAULIC OIL LOW LEVEL Cumulative of minor leaks of oil during maintenance 0,4 2
41 1 Hydraulic oil level in tank too low Cumulative of minor leaks of oil during maintenance 0,4 2







We do not count the first column, because it's just a selection column (will see later)
We do not count the first line, because it's a title

Here is the array:
model: ara01( Y line, X column )

ara01(0,0)="9"
ara01(0.1)="1"
ara01(0,2)="The carrier moves only in one direction"
...
ara(2,2)="Hydraulic oil level in tank too low"
etc.

Now let's not forget we are always using Y first (line) and X second (column)

PROBLEM:
The problem is when the array only have one dimension, Y become X:
(ths first digit of the dimensions, is now the column, not the line)

Hello, how are you?

model: ara01(X column)
ara01(0)="hello"
ara01(1)="how"
etc.

We can also represent the array like in our precedent code:
ara01 = array( _
"Hello,", _
"how", _
"are", _
"you?")
Or without the vbscript line separator aka " _ " (space, _, space)

dynamic definition: (the elements will fill automatically each numbered element of the array, starting at 0)
ara01 = array("Hello,", "how", "are", "you?")

Fixed definition: (we put each elements in a part of the array, telling the right number ourselves, but we cannot insert a new element without changing all numbers)
ara01(0) = "Hello,"
ara01(1) = "how"
ara01(2) = "are"
ara01(3) = "you?"

Back to the single dimension array problem
So the first digit is now X and Y vanish (never existed in fact)
Because we do not have lines (Y), only columns (X)
Now that is a problem when we generate a HTML table
Because we do not know how many dimension the array have

We do not decide how many dimensions we have, because we will fill the array with data from a table, and the table might have only one line...

Since our data is not know, it can have one line or many, one dimension or many

If we ask how many elements there is in the second dimension and there is only one dimension, the script will generate an error

NEXT:
We will see how to generate an html table with an array that can have 1 or 2 dimension(s)

Because it's late and i'll go to bed, good night!

No comments:

Post a Comment