本文介绍了将两行文本传入 InputBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码中有以下一行要求用户输入.
strFind = InputBox("请输入要查找的文本.","替换文件中的文本")
我需要用户输入两行由 LF 或 CR 或 CRLF(换行符)分隔的文本
但是 InputBox 只排除一行文本.
有什么建议吗?
谢谢
解决方案
dim completedmsgbox inputboxml("输入文本:", "多行输入框通过 HTA", "默认" & vbcrlf & vbtab & "multiline" & vbcrlf & "text")函数 inputboxml(prompt, title, defval)昏暗的窗户设置窗口 = 创建窗口()完成 = 0defval = replace(replace(replace(replace(defval, "&", "&"), "<", "<"), ">", ">")带窗使用 .document.title = 标题.body.style.background = "按钮面".body.style.fontfamily = "consolas, courier new".body.style.fontsize = "8pt".body.innerhtml = ""&提示&"</nobr><br><br></center><textarea id='hta_textarea' style='font-family: consolas, courier new; width: 100%; height: 580px;'>;"&defval &"</textarea><br><button id='hta_cancel' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>Cancel<;/button><button id='hta_ok' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>OK</button></div>"以.resizeto 700, 700.moveto 100, 100以window.hta_textarea.focus设置 window.hta_cancel.onclick = getref("hta_cancel")设置 window.hta_ok.onclick = getref("hta_ok")设置 window.document.body.onunload = getref("hta_onunload")做直到完成 >0wscript.sleep 10环形选择案例完成情况1inputboxml = ""案例2inputboxml = ""window.close案例3inputboxml = window.hta_textarea.valuewindow.close结束选择结束函数函数创建窗口()rem 源 http://forum.script-coding.com/viewtopic.php?pid=75356#p75356昏暗的签名,shellwnd,proc下一个错误恢复签名 = left(createobject("Scriptlet.TypeLib").guid, 38)做set proc = createobject("WScript.Shell").exec("mshta""about:<head><script>moveTo(-32000,-32000);</script><hta:application id=app边框=对话框最小化按钮=无最大化按钮=无滚动=无显示任务栏=是上下文菜单=无选择=是内边框=无图标=""%windir%\system32\notepad.exe"""/><object id='shellwindow'classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'>shellwindow.putproperty('" & signature & "'document.parentWindow);</script></head>""")做如果 proc.status >0 然后退出做对于 createobject("Shell.Application").windows 中的每个 shellwndset createwindow = shellwnd.getproperty(signature)如果 err.number = 0 则退出函数错误. 清除下一个环形环形结束函数sub hta_onunload完成 = 1结束子sub hta_cancel完成 = 2结束子子 hta_ok完成 = 3结束子I have the following line in my code asking for user input.
strFind = InputBox("Please enter the text to look for.","Replace Text in Files")
I need the user to input two lines of text separated by LF or CR or CRLF (line-breaks)
However the InputBox only excepts one line of text.
Any suggestion?
Thanks
解决方案 dim completed
msgbox inputboxml("Enter text:", "Multiline inputbox via HTA", "default" & vbcrlf & vbtab & "multiline" & vbcrlf & "text")
function inputboxml(prompt, title, defval)
dim window
set window = createwindow()
completed = 0
defval = replace(replace(replace(defval, "&", "&"), "<", "<"), ">", ">")
with window
with .document
.title = title
.body.style.background = "buttonface"
.body.style.fontfamily = "consolas, courier new"
.body.style.fontsize = "8pt"
.body.innerhtml = "<div><center><nobr>" & prompt & "</nobr><br><br></center><textarea id='hta_textarea' style='font-family: consolas, courier new; width: 100%; height: 580px;'>" & defval & "</textarea><br><button id='hta_cancel' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>Cancel</button><button id='hta_ok' style='font-family: consolas, courier new; width: 85px; margin: 10px; padding: 3px; float: right;'>OK</button></div>"
end with
.resizeto 700, 700
.moveto 100, 100
end with
window.hta_textarea.focus
set window.hta_cancel.onclick = getref("hta_cancel")
set window.hta_ok.onclick = getref("hta_ok")
set window.document.body.onunload = getref("hta_onunload")
do until completed > 0
wscript.sleep 10
loop
select case completed
case 1
inputboxml = ""
case 2
inputboxml = ""
window.close
case 3
inputboxml = window.hta_textarea.value
window.close
end select
end function
function createwindow()
rem source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
dim signature, shellwnd, proc
on error resume next
signature = left(createobject("Scriptlet.TypeLib").guid, 38)
do
set proc = createobject("WScript.Shell").exec("mshta ""about:<head><script>moveTo(-32000,-32000);</script><hta:application id=app border=dialog minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=yes innerborder=no icon=""%windir%\system32\notepad.exe""/><object id='shellwindow' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shellwindow.putproperty('" & signature & "',document.parentWindow);</script></head>""")
do
if proc.status > 0 then exit do
for each shellwnd in createobject("Shell.Application").windows
set createwindow = shellwnd.getproperty(signature)
if err.number = 0 then exit function
err.clear
next
loop
loop
end function
sub hta_onunload
completed = 1
end sub
sub hta_cancel
completed = 2
end sub
sub hta_ok
completed = 3
end sub
这篇关于将两行文本传入 InputBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-14 04:45