Multi-dimensional arrays - (I think!)

B

ben.r.wood

I am not entirely sure, but after scanning the web believe I need to
use multi-dimensional arrays for my problem - although I have not seen
any examples of what I am trying to achieve.

I have a form with one field, for which a user will submit a lump of
delimited data. The data will always be in the same format, ie. 5
fields per record, each field has a delimeter and a new row starts a
new record.

for example:
field1record1 , field2record1 , field3record1 , field4record1 ,
field5record1
field1record2 , field2record2 , field3record2 , field4record2 ,
field5record2
......

There are an unknown number of records on submission.

As I know the number of fields per record (5) can I determine the
number of records by using ubound(myarray) / 5?

I ultimately want to loop through each field of each record and so I
can update the database. I have read about:
- using the split function to seperate the 5 fields
- determining the number of records using ubound function
- creating multi-dimension arrays

but I am not sure how to put them together. Any direction would be
appreciated
 
A

Anthony Jones

I am not entirely sure, but after scanning the web believe I need to
use multi-dimensional arrays for my problem - although I have not seen
any examples of what I am trying to achieve.

I have a form with one field, for which a user will submit a lump of
delimited data. The data will always be in the same format, ie. 5
fields per record, each field has a delimeter and a new row starts a
new record.

for example:
field1record1 , field2record1 , field3record1 , field4record1 ,
field5record1
field1record2 , field2record2 , field3record2 , field4record2 ,
field5record2
.....

There are an unknown number of records on submission.

As I know the number of fields per record (5) can I determine the
number of records by using ubound(myarray) / 5?

I ultimately want to loop through each field of each record and so I
can update the database. I have read about:
- using the split function to seperate the 5 fields
- determining the number of records using ubound function
- creating multi-dimension arrays

but I am not sure how to put them together. Any direction would be
appreciated

Split by vbCrLf first. This gives you an array of strings containing each
record.

Loop the array and on each iteration split each element into another array
(based on your field delimiter) that you can use update your DB.
 
B

Bob Barrows [MVP]

I am not entirely sure, but after scanning the web believe I need to
use multi-dimensional arrays for my problem - although I have not seen
any examples of what I am trying to achieve.

I have a form with one field, for which a user will submit a lump of
delimited data. The data will always be in the same format, ie. 5
fields per record, each field has a delimeter and a new row starts a
new record.

for example:
field1record1 , field2record1 , field3record1 , field4record1 ,
field5record1
field1record2 , field2record2 , field3record2 , field4record2 ,
field5record2
.....

There are an unknown number of records on submission.

As I know the number of fields per record (5) can I determine the
number of records by using ubound(myarray) / 5?

No. Have you tried it?
I ultimately want to loop through each field of each record and so I
can update the database. I have read about:
- using the split function to seperate the 5 fields
- determining the number of records using ubound function
- creating multi-dimension arrays

No, you do not need multi-dimension arrays. You need to loop through the
array (call it records if you wish) created by splitting the raw data on
whatever character(s) is being used to cause the new lines: it could be
"<br>", vbcrlf, vbcr, or vblf. We have no way of knowing given what you
showed us above. You will have to discover it on your own. Anyways, adding 1
to the ubound of THIS array will tell you the number of records.

dim records, fields, newline, record, field
newline="whatever_character_causes_the_line_ breaks_ in_the_data"
records=split(request.form("data"), newline)
for record = 0 to ubound(records)
fields=split(records(record), ",")
if ubound(fields) <> 4 then
'either too few or too many commas
'up to you - quit now or move to next record
else
'loop through fields to pass data to db
end if
next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top