how can i detect multiplt VBNewLine's in a row

S

SLH

if i have a text area on a page that i want to validate, and i dont want
there to ever be 2 "enter"s in a row, how can i check for this?
ive been playing with something like:

If InStr(string, "vbnewline&vbnewline") <> 0

but i cant get that to work no matter what i do with the quotes etc. but
thats the general idea of what i want to do.
any ideas?
 
B

Bob Barrows [MVP]

SLH said:
if i have a text area on a page that i want to validate, and i dont
want there to ever be 2 "enter"s in a row, how can i check for this?
ive been playing with something like:

If InStr(string, "vbnewline&vbnewline") <> 0

but i cant get that to work no matter what i do with the quotes etc.
but thats the general idea of what i want to do.
any ideas?

vbCrLf & vbCrLf
 
S

SLH

thank you ill try that now. question, what is the actual difference between
vbNewLine and vbCrLf?
i ask because i do some other things on various pages using vbNewLine and im
wondering if there is good reason to change it to vbCrLf

thanks
 
B

Bob Barrows [MVP]

They are platform/situation-dependent:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp

I posted that suggestion without testing, assuming it would be the
answer. It turns out I was wrong. According to this test:
<%
dim s, i, ar
ar=array(vbNewLine, vbCrLf)
for each s in ar
Response.Write "Next constant:<BR>"
for i = 1 to len(s)
Response.Write Asc(mid(s,i,1)) & "<BR>"
next
next
%>

The two constants would seem to be equivalent in this situation. So, I
would suggest looping through your string (similar to the above) and
discover what actually is being passed in the form submission for line
break characters.

In fact, based on this test:
<%
if Request.Form.Count>0 then
dim s, i
s=Request.Form("txt")
for i = 1 to len(s)
Response.Write Asc(mid(s,i,1)) & "<BR>"
next
Response.Write "Instr(s,vbCrLf & vbCrLf): " & Instr(s,vbCrLf & vbCrLf)
& "<BR>"
Response.Write "Instr(s,vbNewLine & vbNewLine): " & Instr(s,vbNewLine &
vbNewLine) & "<BR>"
end if
%>
<HTML>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<textarea name=txt></textarea>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
</BODY>
</HTML>

Both constants seem to work when I enter a<enter><enter>a in the text
area and submit it.
 
B

Bob Barrows [MVP]

SLH said:
if i have a text area on a page that i want to validate, and i dont
want there to ever be 2 "enter"s in a row, how can i check for this?
ive been playing with something like:

If InStr(string, "vbnewline&vbnewline") <> 0
Oh jeez, I just noticed. it should be:

If InStr(string, vbnewline & vbnewline) > 0 then
 
S

SLH

Bob Barrows said:
They are platform/situation-dependent:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp

I posted that suggestion without testing, assuming it would be the
answer. It turns out I was wrong. According to this test:
<%
dim s, i, ar
ar=array(vbNewLine, vbCrLf)
for each s in ar
Response.Write "Next constant:<BR>"
for i = 1 to len(s)
Response.Write Asc(mid(s,i,1)) & "<BR>"
next
next
%>

The two constants would seem to be equivalent in this situation. So, I
would suggest looping through your string (similar to the above) and
discover what actually is being passed in the form submission for line
break characters.

In fact, based on this test:
<%
if Request.Form.Count>0 then
dim s, i
s=Request.Form("txt")
for i = 1 to len(s)
Response.Write Asc(mid(s,i,1)) & "<BR>"
next
Response.Write "Instr(s,vbCrLf & vbCrLf): " & Instr(s,vbCrLf & vbCrLf)
& "<BR>"
Response.Write "Instr(s,vbNewLine & vbNewLine): " & Instr(s,vbNewLine &
vbNewLine) & "<BR>"
end if
%>
<HTML>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<textarea name=txt></textarea>
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
</BODY>
</HTML>

Both constants seem to work when I enter a<enter><enter>a in the text
area and submit it.




--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



right now im looking for vbCrLf & vbCrLf (2 or more in a row) and replacing
with a single vbCrLf.
i keep looping until theyve all been replaced. this seems to work....
 
B

Bob Barrows [MVP]

SLH said:
right now im looking for vbCrLf & vbCrLf (2 or more in a row) and
replacing with a single vbCrLf.
i keep looping until theyve all been replaced. this seems to work....

Something like this?

Do Until Instr(string, vbCrLf & vbCrLf)=0
string = Replace(string,vbCrLf & vbCrLf,vbCrLf)
Loop

(yeah, I know there's a great regex solution for this, but I'm leaving
that as an exercise ... )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top