Parsing with join and split

Results 1 to 5 of 5

Thread: Parsing with join and split

  1. #1
    Anne-Marie Guest

    Default Parsing with join and split

    I&#039ve just been reading "Parsing with join and split" on the 4guysfromrolla website and was trying to implement it in the following code but I&#039m getting a type mismatch error on the totalarray=split(total, ",") line. Can anybody help me out??<BR><BR>Thanks <BR><BR>Anne-Marie<BR>------<BR>Dim totalarray()<BR>Dim total, numbelem, count<BR>total=request.form("year")<BR> numbelem=request.form("yearcount")<BR> Redim totalarray(numbelem)<BR> totalarray=split(total, ",")<BR> if numbelem > 0 then<BR> for count=0 to numbelem<BR> response.write"&#060;OPTION SELECTED>" & totalarray(count)<BR> next<BR> else<BR> response.write"&#060;OPTION SELECTED>" & totalarray(0)<BR> end if

  2. #2
    John Harvey Guest

    Default RE: Parsing with join and split

    What is the actual error you&#039re getting? If it&#039s a subscript out of range error, then this is the problem: I would remove the Redim totalarray(numbelem) line. The split function will take care of this for you. If you want control over the number of values the split returns, use this<BR>totalarray = split(total, ",", numbelem)<BR>Hope it Helps!<BR>John

  3. #3
    Anne-Marie Guest

    Default RE: Parsing with join and split

    Thanks for the suggestion but I&#039m afraid that it hasn&#039t made much difference. The actual error that I&#039m getting is:<BR> <BR>"Microsoft VBScript runtime error &#039 800a000d&#039 <BR><BR>Type mismatch <BR><BR>/a-mnewfiles/searchtest.asp, line 47" <BR><BR>Line 47 is totalarray=split(total, ",") in the code below:<BR><BR> Dim totalarray()<BR> Dim total, numbelem, count<BR> total=request.form("year")<BR> numbelem=request.form("yearcount")<BR> Redim totalarray(numbelem)<BR> totalarray=split(total, ",")<BR> if numbelem > 0 then<BR> for count=0 to numbelem<BR> response.write"&#060;OPTION SELECTED>" & totalarray(count)<BR> next<BR> else<BR> response.write"&#060;OPTION SELECTED>" & totalarray(0)<BR> end if<BR><BR>I think that the problem must be to do with the array but I haven&#039t got much experience in using arrays so don&#039t really know where to look for mistakes.<BR><BR>Anne-Marie

  4. #4
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: Parsing with join and split

    Where you have:<BR>Dim totalarray()<BR><BR>Try:<BR>Dim totalarray<BR><BR>Let me know if that change works!<BR>


  5. #5
    Anne-Marie Guest

    Default RE: Parsing with join and split

    Thanks for the suggestion.Unfortunately it didn&#039t make any difference to the error message.<BR><BR>Any more suggestions would be really welcome<BR><BR>Anne-Marie

Posting Permissions

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