Multi-dimensional arrays - (I think!)

Discussion in 'ASP General' started by ben.r.wood@gmail.com, Aug 23, 2007.

  1. Guest

    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
     
    , Aug 23, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > 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.



    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Aug 23, 2007
    #2
    1. Advertising

  3. wrote:
    > 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


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Aug 23, 2007
    #3
  4. Guest

    thanks guys - that was just the info I needed. Got it working fine
    now!
     
    , Aug 23, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    8,788
    Jim Lewis
    Mar 21, 2006
  2. Alf P. Steinbach
    Replies:
    0
    Views:
    450
    Alf P. Steinbach
    Aug 18, 2003
  3. John Harrison
    Replies:
    4
    Views:
    6,949
    Default User
    Aug 19, 2003
  4. Icosahedron
    Replies:
    8
    Views:
    677
    Vivek
    Aug 21, 2003
  5. Wirianto Djunaidi
    Replies:
    2
    Views:
    222
    Wirianto Djunaidi
    Apr 29, 2008
Loading...

Share This Page