Using elements from a split function

Results 1 to 5 of 5

Thread: Using elements from a split function

  1. #1
    Jason B Guest

    Default Using elements from a split function

    After using the split function at the top of my page I want to insert the elements of the newly formed array into a database. <BR>For example, my array contains John,1,Mary,2,Bob,3. I want to insert the Values John, Mary and Bob into the "Name" field and I want 1,2,3 inserted into the ID field. <BR>How do I reference those items that I want to insert into the table as I am looping through my array? Below is a bit of my code if it clarifies anything.<BR><BR>_________________________________ ___________________________<BR>Item = Request("NamesID")<BR>Array = Split (Item, "&#124")<BR><BR>For each Element in Array <BR>&#039??????<BR>_______________________________ _____________________________<BR><BR><BR><BR> <BR><BR>For each Item in Array

  2. #2
    Steve Cimino Guest

    Default RE: Using elements from a split function

    Don&#039t use array as your variable name.. it is a reserved word. I don&#039t see your &#124 anywhere, so I&#039ll assume everything is already in the array.<BR><BR><BR>i = 0<BR>Do Until i &#062; UBound(myArray)<BR>&#039Insert your name here with myArray(i)<BR>i = i + 1<BR>&#039Insert your number field here with myArray(i)<BR>i = i + 1<BR>Loop<BR><BR>OR<BR><BR>For i = 0 To UBound(myArray) Step 2<BR>&#039Insert both at the same time, using<BR>&#039myArray(i) and myArray(i + 1)<BR>Next<BR><BR>Try either/or, but I think the latter is easier to read.

  3. #3
    Jason B Guest

    Default Thanks Steve, I'll give it a try!(EOM)


  4. #4
    Steve Cimino Guest

    Default A fix

    If you use the For loop and your array UBound is an even number, you&#039ll get a subscript out of range. Do this instead:<BR><BR>For i = 1 to UBound(myArray) + 1 Step 2<BR>&#039Insert both at the same time using<BR>&#039myArray(i) and myArray(i - 1)<BR>Next

  5. #5
    Steve Cimino Guest

    Default I Quit

    Get rid of the step 2. That will give a subscript out of range also. Do it one at a time<BR><BR>For i = 0 To UBound(myArray)<BR>&#039Insert your stuff here<BR>Next<BR><BR>Ahhh well. Too much Halloween candy sitting in me to think straight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts