如何解决VB 脚本 - 帮助使用 HTA 表单将变量设置为用户输入的值
示例脚本最初由 OMEGASTRIPES 发布在这里:https://pastebin.com/wZYTtT8V
并在此处进一步讨论,在 Stack Overflow 上,在以下链接下:Pass two lines of text into InputBox
脚本基本上完全符合我的需要(或至少是它的第一部分),即捕获一长串文本(包括换行符),然后我需要对其进行按摩,以便重新-使用字符串的一部分。该脚本现在正在做我需要的一切,只有一个例外。示例脚本最后在一个窗口中显示用户的输入。我不想显示窗口,而只想将用户输入的值分配给一个变量。不是开发人员(只是在必要时偶尔试一试)我已经努力了几个小时试图实现这一目标,包括尝试使用 GetElementbyName 的失败尝试。 有人可以让我摆脱痛苦吗,因为我确信这会变得非常简单,但我只是不知道如何并且我的研究是空白。示例脚本中的违规行位于 case 语句的第三个区域:
inputBoxml = window.hta_textarea.value
window.close
以下只是我尝试(但失败)将输入值分配给变量的许多不同方法的一个示例:
inputBoxml = document.getElementsByName("hta_textarea")
任何人都可以提供给我的任何帮助将不胜感激。下面是整个示例脚本。
谢谢,史蒂夫
'Example Script
dim completed
msgBox inputBoxml("Enter text:","Multiline inputBox via HTA","default" & vbcrlf & vbtab & "multiline" & vbcrlf & "text")
function inputBoxml(prompt,title,defval)
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
解决方法
我认为您可以为 inputboxml 函数的输出设置一个变量,而不是将该输出直接发送到 msgbox。
' instead of this
'msgbox inputboxml("Enter text:","Multiline inputbox via HTA","default" & vbcrlf & vbtab & "multiline" & vbcrlf & "text")
' use this
dVal = inputboxml("Enter text:","default" & vbcrlf & vbtab & "multiline" & vbcrlf & "text")
msgbox dVal
我添加了一个 msgbox 来检查结果是否相同。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。