2014-12-04 115 views
1

我寫了一個非常簡單的VBS程序,以便不同的程序可以調用它,以便使用SendKeys方法。當我只寫出一個簡單的字符串來測試它是這樣的:SendKeys不能使用變量

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.SendKeys "testing" 

它工作得很好。但是,當我在地方的字符串使用等效變量,像這樣:

Set WshShell = WScript.CreateObject("WScript.Shell") 
Set thingy = "testing" 

WshShell.SendKeys thingy 

它提供了以下錯誤調用時:

Error in line 2: Object required: '[string: "testing"]'

回答

1

問題是與set thingy = "testing",不與SendKeysSet statements用於將對象分配給變量。它們不能用於分配原始數據類型。

改爲使用thingy = "testing"

+0

我不明白。因爲我沒有使用'Set' – user206168 2018-03-02 16:40:29