Re:How to select text for a user in textarea?
ignore what you don't need and just pick it out of the 'find/next'
button...
<html><head>
<title>myParHTA</title>
<STYLE>
BODY {BACKGROUND-COLOR: #cc66cc; margin:0px 0px 0px 0px}
#tx1 {width:100%; height:70%;font-family:tahoma; font-size:9pt}
#tx2,#tx3 {width:35% }
input {width:50% ;font-size:7pt}
button {width:58px; background-color:lime; font-family:ms sans serif
;font-size:7pt}
input {font-family:ms sans serif; font-size:9pt }
' #b1 {behavior:url(parse.htc)}
</STYLE>
<script language=VBScript defer>
dim sarray(),bdoc,gmatches,icount,bcount,r,a,w,marray()
dim fso
set fso=createobject("scripting.filesystemobject")
bcount=-1
icount=0
a=0
window.onerror=getref("doerror")
sub doerror(a,b,c)
msgbox a & b & c
end sub
sub window_onload()
f1.click
end sub
window.onunload=getref("doUnload")
sub doUnload()
set bdoc=nothing
set gmatches=nothing
set r=nothing
end sub
sub f2_onclick() 'in reverse
dim s,re
if window.event.altKey=True then
set gmatches=nothing
set r=nothing
bcount=-1
a=0
document.selection.empty
exit sub
end if
if bcount=-1 then
set re=new regexp
set r=tx1.createTextRange()
r.collapse
re.global=True
re.ignorecase=True
re.pattern=tx2.value
s=replace(tx1.value,vbnewline,chr(32))
set gmatches = re.execute(s)
if gmatches.count then
bcount=gmatches.count-1
end if
set re=nothing
end if
if gmatches.count then
if a=0 then
r.move "character",gmatches(bcount).firstindex
else
r.move "character",-(a - gmatches(bcount).firstindex)
end if
a=gmatches(bcount).firstindex
r.moveEnd "character",gmatches(bcount).length
r.select
bcount=bcount-1
if bcount < 0 then
set gmatches=nothing
set r=nothing
bcount=-1
a=0
window.settimeout "msgbox 'Finished Searching" & _
" The Document'",400,"VBScript"
end if
end if
end sub
sub f1_onclick() 'find
dim s,re
if window.event.altKey=True then
set gmatches=nothing
set r=nothing
icount=0
a=0
document.selection.empty
exit sub
end if
if icount=0 then
set re=new regexp
set r=tx1.createTextRange()
r.move "character",-1
re.global=True
re.ignorecase=True
re.pattern=tx2.value
s=replace(tx1.value,vbnewline," ")
set gmatches = re.execute(s)
set re=nothing
end if
if gmatches.count>0 then
r.moveStart "character",gmatches(icount).firstindex - a
a=gmatches(icount).firstindex
r.moveEnd "character",gmatches(icount).length
r.select
r.scrollIntoView
icount=icount+1
if icount>gmatches.count-1 then
set gmatches=nothing
set r=nothing
icount=0
a=0
window.settimeout "msgbox 'Finished Searching" & _
"The Document'",200,"VBScript"
end if
end if
end sub
sub repl1_onclick()
dim s
s=tx1.value
tx1.value=replace(s,tx2.value,tx3.value)
end sub
sub RER1_onclick()
set re=new regexp
re.global=true
re.ignorecase=true
re.pattern=tx2.value
tx1.value=re.replace(tx1.value,tx3.value)
set re=nothing
end sub
sub REIB1_onclick()
set re=new regexp
re.global=true
re.ignorecase=false
re.pattern=tx2.value
set matches = re.execute(tx1.value)
for i= (matches.count-1) to 0 step -1
xstr=tx1.value
tx1.value=left(xstr,matches.item(i).firstindex ) &
replace(xstr,matches.item(i),tx3.value &
matches.item(i),matches.item(i).firstindex+1,1,1)
next
set re=nothing
end sub
sub REIA1_onclick()
set re=new regexp
re.global=true
re.ignorecase=false
re.pattern=tx2.value
set matches = re.execute(tx1.value)
for i= (matches.count-1) to 0 step -1
xstr=tx1.value
tx1.value=left(xstr,matches.item(i).firstindex) & matches.item(i) &
replace(xstr,matches.item(i),tx3.value,matches.item(i).firstindex+1,1,1)
next
set re=nothing
end sub
sub doLoad()
dim s,i
for i=0 to bdoc.childNodes.length-2
s=s & bdoc.childNodes(i).text & vbnewline
next
s=s & bdoc.documentElement.outerHtml
tx1.value=s
end sub
sub doConnect()
dim sw,wi
set sw=createobject("shell.application")
for each wi in sw.windows
if wi.top < 50 then
if ucase(right(wi.fullname,12))="IEXPLORE.EXE" then
set w=wi
set bdoc=w.document
end if
end if
set sw=nothing
set wi=nothing
next
end sub
sub newWindow()
set
w=window.open("d:\web\ablank.htm","LW","toolbar=0,scrollbars=1,status=0,
menubar=0,width=500,height=400")
window.settimeout "set bdoc=w.document",2000
end sub
sub doFile()
set ts=fso.createtextfile("D:\myFile.htm",true,false)
ts.write tx1.value
ts.close
w.navigate "D:\myFile.htm"
end sub
</script>
</head>
<body style="margin:0px 0px 0px 0px">
<button onclick="vbs:doConnect">W</button>
<button onclick="vbs:doLoad">get</button>
<button id=b1>Pars</button>
<button onclick="vbs:w.navigate 'file://d:\web\ablank.htm'">nav</a>
<button onclick="vbs:w.navigate 'file://d:\VMLtem.htm'">vml</a>
<button onclick="vbs:doUnload">Unld</button>
<button onclick="vbs:doFile">ViaFile</button>
<button onclick="vbs:newWindow">New-W</button>
<br>
<textarea id=tx1 wrap=soft>Hello & Welcome, #custname#</textarea><br>
<textarea id=tx2>#custname#</textarea>
<textarea id=tx3></textarea><br>
<button id=repl1>Replace</button>
<button onclick="vbs:tx1.wrap='off'">WrapHard</button>
<button onclick="vbs:tx1.wrap='soft'">WrapSoft</button>
<button id=RER1>REReplace</button>
<button id=f1>find/next</button>
<button id=f2>inReverse</button>
<button id=REIB1>REInsertBefore</button>
<button id=REIA1>REInsertAfter</button>
</body>
</html>
-