Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Dimensional Array

Status
Not open for further replies.

SWarrior

MIS
Dec 19, 2003
111
US
I'm trying to write and read to/from a two dimensional array, but not having any luck. Can I get a few tips on this ?? I have a project that I MUST have done today... I hate being under the GUN!!!

Code:
arrayObj = Array(10,5)

arrayObj(1,1) = "\\machine01\c$"
arrayObj(2,1) = "\\machine02\c$"

arrayObj(1,2) = "Copy Failed"
arrayObj(2,2) = "Successful Copy"

I will have processes writing to the array, and then after it's all done, I want to read the entire array as:
1,1
1,2
1,3...
2,1
2,2
2,3...

I'll be generating a report after. I can manage the processing part, but the darn reading and writting to the array so far is not working for me... :(

Thanks in advance!
-SWarrior
 
Hello SWarrior!

Is there anything hindering you from simply doing this:
Code:
Dim arrayObj(10,5)
Otherwise, your assignment statements look fine.

Good luck!
 
Thanks snotmare!

I did have it in DIM, but as Dim arrayObj instead of Dim arrayObj(10,5)

I was trying to set the size within the script.


One quick last question though.... Let's say the array is 10,5, and I run the array through a loop, and there is only data in 8,5. 9,5 & 10,5 are all empty. How would I setup a Do Loop to exit if 8 or 9 of the array is blank ??

Thanks again!
-SWarrior
 
Good questions.

Since you dim the array as 10,5 (as opposed to a dynamic array), then all elements are initialized to "" (empty string).

If you can guarentee that you won't have a scenerio where 8,5 is populated, 9.5 is empty, but 10,5 is populated, then you could use the example below. This example also assumes that for each X element (the 1 - 10 deminsion), there will always be 5 Y elements (the 1 - 5 deminsion).
Code:
dim i1, i2, blnDone

blnDone = False
i1 = 0
Do until i1 >= 10 _
or blnDone = True
    i2 = 0
    Do until i2 >= 5 _
    or blnDone = True
        If arrayObj(i1, i2) = "" Then
            blnDone = True
        Else
        'Do your stuff
        End If
        i2 = i2 + 1
    Loop
    i1 = i1 + 1
Loop
There are lots of possibilites for coding a loop like this. If you use the "Exit Do" statement, be careful because if you are in your inner loop, it will only exit from there and not from the outter loop also.

You could do something simpler and elimenate the blnDone logic if you don't care if you continue to execute the loop even if the strings are blanks. Like this:
Code:
For i1 = 1 To 10
    For i2 = 1 To 5
        If arrayObj(i1, i2) > "" Then
            'Do your stuff
        End If
    Next
Next
With this example, you would loop through each element no matter what, but only execute your code if the element is populated.

Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top