
To comma, or not to comma. That is the question.
I'm not quite sure how to explain this but I'll do the best I can. I'll just explain the scenario...<BR><BR>With the code below, if a user has all four If's = 1 then the output looks like OT, R, SC, SS<BR><BR>However, suppose the user only has the top two If's = 1 then the output looks like OT, R, <Notice the trailing comma? How do I do this type of thing with the commas when they're needed and no comma if not needed? Thank you lots for the help! :)<BR><BR><%<BR>If rs1("usrPropOT") = "1" Then Response.Write "OT, "<BR>If rs1("usrPropR") = "1" Then Response.Write "R, "<BR>If rs1("usrPropSC") = "1" Then Response.Write "SC, "<BR>If rs1("usrPropSS") = "1" Then Response.Write "SS"<BR>%><BR><BR>:) again

RE: To comma, or not to comma. That is the questio
<%<BR>Dim first<BR> first = True<BR>If rs1("usrPropOT") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "OT"<BR>End If<BR>If rs1("usrPropR") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "R, "<BR>End If<BR>If rs1("usrPropSC") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "SC, "<BR>End If<BR>If rs1("usrPropSS") = "1" Then<BR> If Not bFirst Then Response.Write ", "<BR> Response.Write "SS"<BR>End If<BR>%><BR>

Or even...
<% <BR>Dim prop<BR>If rs1("usrPropOT") = "1" Then prop = prop & "OT, " <BR>If rs1("usrPropR") = "1" Then prop = prop & "R, " <BR>If rs1("usrPropSC") = "1" Then prop = prop & "SC, " <BR>If rs1("usrPropSS") = "1" Then prop = prop & "SS, " <BR><BR>If prop <> "" Then<BR> prop = Left(prop, Len(prop)  2)<BR>End If<BR>Response.Write prop<BR>%> <BR>

RE: To comma, or not to comma. That is the questio
<%<BR>If rs1("usrPropOT") = "1" Then strOutput = strOutPut & "OT, "<BR>If rs1("usrPropR") = "1" Then strOutput = strOutPut & "R, "<BR>If rs1("usrPropSC") = "1" Then strOutput = strOutPut & "SC, "<BR>If rs1("usrPropSS") = "1" Then strOutput = strOutPut & "SS"<BR>if left(strOuput, 1) = "," then<BR> strOutput = left(strOutPut, len(strOutput)1)<BR>end if<BR>Response.Write StrOutput<BR><BR>%><BR><BR>HTH.<BR>D.

2 problems.
It's a comma+space (need to do  2).<BR><BR>The last one doesn't have it, so you'll take off one of the "S".

sorry,
didn't notice the space after each comma<BR><BR> <% <BR>If rs1("usrPropOT") = "1" Then strOutput = strOutPut & "OT, " <BR>If rs1("usrPropR") = "1" Then strOutput = strOutPut & "R, " <BR>If rs1("usrPropSC") = "1" Then strOutput = strOutPut & "SC, " <BR>If rs1("usrPropSS") = "1" Then strOutput = strOutPut & "SS" <BR>if left(strOuput, 2) = "," then <BR> strOutput = left(strOutPut, len(strOutput)2) <BR>end if <BR>Response.Write StrOutput <BR><BR>%>

RE: 2 problems.
I noticed the comma issue, abit late admittedly, But it won't take off the S, as its doing, <BR><BR>if left(strOutput, 2) = ", " then<BR> blah blah<BR>end if<BR>

Didn't see that.
You're right about the not lopping off the "S".

Stripping Function
try this:<BR><BR>
Code:
<BR>Function NoLeadingTrailing(DataString,TargetChar)<BR>'This function is designed to strip leading and<BR>' trailing instantiations of TargetChar from<BR>' DataString. Note that only 1 instantiation<BR>' of TargetChar will be taken from the front and<BR>' back.<BR><BR> Dim intTemp0,intTemp1<BR> Dim bolTemp0,bolTemp1<BR> Dim strTemp0,strTemp1<BR> Dim strTemp2,strTemp3<BR> <BR><BR> strTemp0=DataString<BR><BR> strTemp0=Replace(strTemp0,TargetChar & TargetChar,TargetChar) <BR> if right(strTemp0,1)=TargetChar then<BR> if len(strTemp0)=1 then<BR> strTemp0=""<BR> else <BR> strTemp0 = left(strTemp0,len(strTemp0)1)<BR> end if<BR> end if<BR> <BR> if left(strTemp0,1)=TargetChar then<BR> if len(strTemp0)=1 then<BR> strTemp0=""<BR> else <BR> strTemp0 = mid(strTemp0,2,len(strTemp0))<BR> end if<BR> end if <BR> <BR> NoLeadingTrailing = strTemp0<BR>end Function<BR>
<BR>

Same kind of function..
.. 2 more ways:<BR>http://www.27seconds.com/kb/article_view.asp?id=18
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

