ASP Split syntax "type mismatch"

I have data in checkboes like the following

[]    123_ABC_01
[]    123_ABC_02
[]    123_ABC_03
[]    XYZX_ZZZ_01
[]    XYZX_ZZZ_02
[]    XYZX_ZZZ_04
[]    PTPR5_YYY_01
[]    PTPR5_YYY_02

I want to group them with a heading according to the string before the first  _(underscore)

Here is the code I used but I am getting a type mismatch
%>
<div align="center">
  <table border="1" width="18%" id="table1">
  <tr>
    <td width="97">
<%
             
            tmp = ""
               do while not objRS.EOF
                    if objRS("BldLabel") = strBuild then
                         strSelected = " Checked "
                    else
                         strSelected = ""
                    end if
                         
                         if Split(objRS("BldLabel"),"_", 1) <> tmp then
                              tmp = Split(objRS("BldLabel"),"_", 1)
                         %>
                         <tr><td><%=tmp%></td>
                         <%                                  
                         end if
 
%>
<tr><td><input type=checkbox name=BldLabel <%=strSelected%> value="<%=objRS("BldLabel")%>"></td>
<td><%=objRS("BldLabel")%></td>
</tr>
<%
                    objRS.MoveNext
               loop
          end if%>
          </table>
</div>
<%
tmurray22Asked:
Who is Participating?
 
Anthony PerkinsCommented:
Just change:
    if Split(objRS("BldLabel"),"_", 1) <> tmp then

To:
    if Split(objRS("BldLabel"),"_")(0) <> tmp then         ' Split is 0 based.

0
 
kevp75Commented:
there are only 2 parameters to the split function
 like this:

split("stuff_to_split","splitting by")

this will put everything into an array for you, then just group it by the 1st value of the array (which is 0)

for example

myArray = SPLIT("123_ABC_DEF","_")
response.write myArray(0) & "<br />" 'this will print out 123 and a line break
response.write myArray(1) & "<br />" 'this will print out ABC and a line break
response.write myArray(2) & "<br />" 'this will print out DEF and a line break
0
 
Anthony PerkinsCommented:
>>there are only 2 parameters to the split function<<
Actually there are 4 parameters and only one is required.

<quote>
Split(expression[, delimiter[, count[, compare]]])

Arguments
expression
Required. String expression containing substrings and delimiters. If expression is a zero-length string, Split returns an empty array, that is, an array with no elements and no data.

delimiter
Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.

count
Optional. Number of substrings to be returned; -1 indicates that all substrings are returned.

compare
Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.
</quote>
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
kevp75Commented:
ahh see.  I've never seen the last 2 being used, so I assumed there were only 2.

acperkins change should definatly work
0
 
tmurray22Author Commented:
I applied the chages but my data is strange (it gives a true above each check box and groups nothing)

Here is my original version which works fine, followed by my new version which doesnt.

 tmp = ""
               do while not objRS.EOF
                    if objRS("BldLabel") = strBuild then
                         strSelected = " Checked "
                    else
                         strSelected = ""
                    end if
                       if left("" & objRS("BldLabel"), 3) <> tmp then
                              tmp = left("" & objRS("BldLabel"), 3)
                         %>
                         <tr><td><%=tmp%></td>
                         <%                              
                         end if


Here is what I need to work

tmp = ""
               do while not objRS.EOF
                    if objRS("BldLabel") = strBuild then
                         strSelected = " Checked "
                    else
                         strSelected = ""
                    end if
                         
                         if Split(objRS("BldLabel"),"_")(0) <> tmp then
                              tmp = Split(objRS("BldLabel"),"_")(0) <> tmp
                         %>
                         <tr><td><%=tmp%></td>
                         <%                                  
                         end if

 
0
 
Anthony PerkinsCommented:
You are going to have to add a few Response.Write to see what is going on.

But at the very least I would say that you got carried away with your copy/paste.  This line:

tmp = Split(objRS("BldLabel"),"_")(0) <> tmp

Should work better this way:
tmp = Split(objRS("BldLabel"),"_")(0)
0
 
tmurray22Author Commented:
Holy Crap it worked. This morons going to bed!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.