Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need expert knowledge with Spit and/or Replace Fuction

Status
Not open for further replies.

ecugrad

MIS
Apr 17, 2001
191
US
I have the below batch process page utilizing the Split Function. The problem is if I have a string with a comma the function splits the string into two different records. It looks at the comma as the beginning of a new record I tried to use an addtional Replace Function, but it does not seem to work with commas. Ex: Namearray(i) = Replace(BPCommentsArray(i)= , ","," ") will not work. Any suggestions of how to strip out the commas in my strings before they are processed, or how to fix my Split function in my array. Pretty ne at ASP
Thanks, Mike



Set conn = server.createobject("adodb.connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & server.mappath("../fpdb/PMData.mdb")
conn.Open DSNtemp
%>

<%

idarray=Split(Request(&quot;SurveyID&quot;),&quot;,&quot;)

Namearray=Split(Request(&quot;Name&quot;),&quot;, &quot;)
BParray=Split(Request(&quot;BP&quot;),&quot;,&quot;)
BPCommentsArray=Split(Request(&quot;BPComments&quot;),&quot;, &quot;)

BPReplyArray=Split(Request(&quot;BPReply&quot;),&quot;, &quot;)

for i=0 to UBound(idarray)



BPReplyarray(i) = Replace(BPReplyarray(i), &quot;'&quot;,&quot;''&quot;)

BPCommentsArray(i)= Replace(BPCommentsArray(i),&quot;'&quot;,&quot;''&quot;)




SQLStmt=&quot;UPDATE bsasurvey SET name = '&quot;&Namearray(i)&&quot;',BP = '&quot;&BParray(i)&&quot;', BPComments = '&quot;&BPCommentsArray(i)&&quot;', BPReply = '&quot;&BPReplyarray(i)&&quot;' WHERE SurveyID= &quot;&idarray(i)
Response.Write(SQLStmt)

Set rs = conn.Execute(SQLstmt)

Next

%>

 
You will need to do this client-side before you submit the form. When the browser submits a form with several values assigned to the same name it submits it as a comma delimited string, so by the time it actually gets to your server it is already a comma delimited string. You could write a small javascript function to replace commas with another character in your inputs, and just call it onBlur for those inputs. Once you split it on the server you could then replace whatever character you were using to hold the space for the comma back to a comma before inserting it inot the db.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
Tarwn, can you give me an example of this. I believe you are saying It needs to be in the page below and the commas must be strippd before it hits the process page , makes sense.. Again, any help on the script would be appreciated, the below script is about the far as I have gotten in Javascripting

<%response.buffer=true%>

<!-- METADATA TYPE=&quot;typelib&quot; FILE=&quot;C:\Program Files\Common Files\System\ado\msado15.dll&quot; -->

<% Response.ExpiresAbsolute = Now() - 1 %>
<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--

function UpdateReply()
{
document.forms[0].action = &quot;TC2ReplyProcess.asp&quot;;
document.forms[0].submit();
}
// -->
</SCRIPT>
<title></title>
</head>

<BODY background=&quot;bg.gif&quot; leftmargin=&quot;0&quot;>
<%
Dim Conn, dsntemp
Set conn = server.createobject(&quot;adodb.connection&quot;)
DSNtemp=&quot;DRIVER={Microsoft Access Driver (*.mdb)}; &quot;
DSNtemp=dsntemp & &quot;DBQ=&quot; & server.mappath(&quot;../fpdb/PMData.mdb&quot;)
conn.Open DSNtemp

%>


<table border=&quot;0&quot; width=&quot;654&quot;>
<tr>
<td width=&quot;239&quot;>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<td width=&quot;399&quot; align=&quot;LEFT&quot;>
<b><font color=&quot;#000000&quot; size=&quot;2&quot;>BankPro Helpdesk
(252-246-4949) -</font> </b>A<font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;>ssists
lenders with &quot;how to&quot; questions related to the use of the
BankPro Application.</font>
</td>
</tr>
</table>




<FORM METHOD=POST ACTION=&quot;TC2ReplyProcess.asp&quot;>
<TABLE BORDER=1 CELLSPACING=1 width=&quot;625&quot;>
<%
Dim SqlStmt
SQLstmt = &quot;SELECT * FROM bsasurvey order by SurveyID&quot;

Set rs = conn.Execute(SQLstmt)
%>


<%
Dim iCount
iCount = 0

%>







<table width=&quot;593&quot;>
<TR>
<td width=&quot;4&quot;>
<%Do While Not rs.EOF%>
<td width=&quot;492&quot;>
<p align=&quot;left&quot;><font color=&quot;#663300&quot; size=&quot;2&quot;><INPUT TYPE=&quot;text&quot; NAME=&quot;Name&quot; VALUE=&quot;<%=rs(&quot;Name&quot;)%>&quot; size=&quot;18&quot; style=&quot;text-align: Left&quot;></font></p>
</td>

<td width=&quot;388&quot;>
<p align=&quot;left&quot; align=&quot;CENTER&quot;><font color=&quot;#663300&quot; size=&quot;2&quot;><INPUT TYPE=&quot;text&quot; NAME=&quot;BP&quot; VALUE=&quot;<%=rs(&quot;BP&quot;)%>&quot; size=&quot;3&quot; style=&quot;text-align: Center&quot;></font></p>
</td>

<td width=&quot;432&quot;>
<p align=&quot;left&quot;><font color=&quot;#663300&quot; size=&quot;2&quot;><TextArea cols=39 NAME=&quot;BPReply&quot; rows=&quot;4&quot;><%=rs(&quot;BPReply&quot;)%></TextArea></font>

</td>
<td width=&quot;453&quot;>
<p align=&quot;left&quot;><font color=&quot;#663300&quot; size=&quot;2&quot;><TextArea cols=39 NAME=&quot;BPComments&quot; rows=&quot;4&quot;><%=rs(&quot;BPComments&quot;)%></TextArea></font>

</td>


</tr>

<td width=&quot;4&quot;><font color=&quot;#663300&quot;><INPUT TYPE=&quot;Hidden&quot; NAME=&quot;SurveyID&quot; VALUE=&quot;<%= RS(&quot;SurveyID&quot;)%>&quot;></font></td>

<%
iCount = iCount + 1

rs.MoveNext
lOOP
%>

<td width=&quot;492&quot;>

<P>
<INPUT TYPE=BUTTON VALUE=&quot;Update &quot; ONCLICK=&quot;UpdateReply();&quot;>


<INPUT TYPE=HIDDEN NAME=Count VALUE=&quot;<%=iCount - 1 %>&quot;
</FORM>
</table>
</table>
</BODY>
</XMP>




 
It is pretty easy. I am enclosing a sample page with two textboxes with the same name. The javascript function will replace all &quot;,&quot; with &quot;~&quot; before submitting the form. Then use split to get the entries and replace &quot;~&quot; with &quot;,&quot;.

Find the code below:

<%@ Language=VBScript %>
<%
If Request.QueryString(&quot;action&quot;)=&quot;submit&quot; Then
strTest=Split(Request.Form(&quot;txtName&quot;),&quot;,&quot;)
For i=0 to ubound(strTest)
Response.Write(Replace(strTest(i),&quot;~&quot;,&quot;,&quot;)&&quot;<br>&quot;)
Next
End if
%>
<HTML>
<script language=&quot;javascript&quot;>
function fnSubmit()
{
//no.of textboxes with the name txtName
var icount=document.frmTest.elements(&quot;txtName&quot;).length ;
var iindex;
//Loop thru all these textboxes
for(iindex=0;iindex<icount;iindex++)
{
stest=document.frmTest.txtName(iindex).value;
stest=stest.replace(/\,/g,&quot;~&quot;);
document.frmTest.txtName(iindex).value=stest;
}

document.frmTest.action=&quot;Test2.asp?action=submit&quot;;
document.frmTest.submit();
}
</script>
<HEAD>
</HEAD>
<BODY>
<form name=&quot;frmTest&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;txtName&quot;>
<input type=&quot;text&quot; name=&quot;txtName&quot;>
<input type=&quot;button&quot; value=&quot;Submit&quot; onclick=&quot;javascript:fnSubmit()&quot;>
</form>
</BODY>
</HTML>
 
Hi ecugrad,
Another alternative (to avoid using any client-side codes --which can be a support headache as there are many versions of browsers out there) is to make use of the request.form(var).count property which will tell you exactly how many variables were passed to you.

===========================
for i = 1 to Request.Form(&quot;SurveyID&quot;).count
SQLStmt=&quot;UPDATE bsasurvey SET name = '&quot; & Request.Form(&quot;Name&quot;)(i) & &quot;',BP = '&quot; & Request.Form(&quot;BP&quot;)(i) & &quot;', BPComments = '&quot; & Request.Form(&quot;BPComments&quot;)(i) & &quot;', BPReply = '&quot; & Request.Form(&quot;BPReply&quot;)(i) & &quot;' WHERE SurveyID= &quot; & Request.Form(&quot;SurveyID&quot;)(i)
Response.Write(SQLStmt)

Set rs = conn.Execute(SQLstmt)
Next
===========================

Hope this helps. cheers.

regards,
- Joseph ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Shopping --> , Soccer --> ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top