0

I need a way to find the difference between two strings in a Windows application using VBScript. One of the strings is known but the second one is completely unknown during coding. I know there are functions like StrCompare, InStr etc. but these require you to know the second string also during coding.

Explanation:

There is a text box in the screen and there are several buttons in the same screen. As and when the buttons are clicked, the text in the text box changes depending on the button clicked. Is there a way to find the changes made to the text after the button is clicked ? Basically I need to get the text entered due to the button click. Is there a simple way to do this or it requires complex coding ?

Thanks in Advance.

4

2 回答 2

1

这取决于您的应用程序和新字符串的格式。


如果您需要查找附加到原始字符串的文本,您可以获取新文本并将原始字符串的第一次出现替换为空字符串:

Dim strOld, strNew, strDiff

strOld = "Apple"
strNew = "Apple, Orange"

strDiff = Replace(strNew, strOld, "", 1, 1)
WScript.Echo strDiff

样本输出:

, 橙子


或者,如果您需要获取不带逗号的附加文本,您可以使用以下内容:

strDiff = Replace(strNew, strOld + ", ", "", 1, 1)
于 2013-05-21T11:29:24.207 回答
0

要访问(读/写)HTML 文本输入的内容,您需要获取 HTML 元素(document.all.<Name/Id> or document.getElementById(<Name/Id>)及其 .value;就像在这个演示中:

<html>
 <head>
  <Title>readtext</Title>
  <hta:application id="readtext" scroll = "no">
  <script type="text/vbscript">
   Function Change()
     document.all.txtDemo.value = "Changed Value"
   End Function

   Function Check()
     Dim txtDemo : Set txtDemo = document.getElementById("txtDemo")
     Dim sDemo   : sDemo       = txtDemo.value
     Select Case LCase(Trim(sDemo))
       Case "initial value"
         MsgBox "still: " & sDemo
       Case "changed value"
         MsgBox "now: " & sDemo
       Case Else
         MsgBox "surpise: " & sDemo
     End Select
   End Function
  </script>
 </head>
 <body>
  <input type="text" id="txtDemo" value="Initial Value" />
  <hr />
  <input type="button" value="Change" onclick="Change" />
  <input type="button" value="Check"  onclick="Check"  />
 </body>
</html>
于 2013-05-21T10:57:08.260 回答