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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Access 1

Status
Not open for further replies.

ogri

Programmer
Joined
Sep 26, 2000
Messages
74
Location
GB
Hi

I m trying to modify a program which has a large 2 dimensional array. This dimensions are the records and then the fields on the records (a CSV file is read into this array).

I can refer to the complete array as vArray() and a single element as vArray(5,5) (for example).

Is there any way I can refer to all the elements of one dimension of the array. Something like vArray(5,*)

All the best

Keith
 
'This will load all the elements of the second dimension into the text1.text

dim i as integer
for i = 0 to ubound(vArray, 2) 'the 2 refers to the 2nd element
Text1.text = Text1.text & vArray(5,i) & vbcrlf
Next i
 
easier / better to maks a recordset of the CSV array and just refer to the field by whatever methods. ADO does a simple job of this.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Hi

Thanks. Unfortunatly I dont think I explained it sufficiently.

Basically I want to move data from one array into another. The from array is a 2 dimensional array, with the first dimension being the record number, and the second dimension being the field (they are read in from a CSV file).

What I am currently doing is :-

For I=lbound(fred) to ubound(fred)
fred(I)=Burt(x,I)
Next

What I really wanted was a way to do this without having to manually loop through the array assigning individual fields across

All the best

Keith
 
You can assign an array to a dynamic array of the same type but the dynamic array will also become multi dimensional. What's happening is the first array is pointed to the memory location of the second array, so it's fast. The problem is you are not accomplishing your goal.

Dim arTest1() As String
Dim arTest2(5, 5) As String
Dim i as integer
For i = 0 To 4
arTest2(0, i) = i
Next i
arTest1 = arTest2
MsgBox arTest1(0, 1)
 
I thought I had a neat SAFEARRAY solution, but VB doesn't store the actual contents the right way round for the idea to work...
 
Hi

Oh well, thanks for trying.

The problem is that the program (not written by me) is processing a file, with each record loaded into an array (first dimension the record number, second dimension the field, with element 0 being the complete record). When they pass validation the "record" was transferred into another area, but it was passing across the array containing ALL records for each record, and the application started to eat memory (double the number of records meant 4 times the amount of storage).

All the best

Keith
 
I guess I'm totally confused. You note " ... (a CSV file is read into this array). '''", yet more or less ignore the suggestion of creating the ADO recordset directly from the file and manipulating the content through standard SQL methods. I do not understand the reluctance to this (obvious) approach.


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Hi

This is a large app, which I certainly havent got time to rewrite to a large extent. The file is read in and initially validated, put on one table. Once the file has passed validation each record is validated.

The arrays are used all over the place, and are passed around for the rejection records.

Once all the records have gone through validation, some of the records which have failed are presented to the user to allow them to select which ones are dealt with

Sorry, the whole thing is rather complicated and difficult to read in areas due to the very strange validation that was included when the application was written. To add to the fun half the processing is dumped out into about 20 DLLs.

All the best

Keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top