所以我對編碼非常陌生,特別是在Vbscript中,所以我一直在搞亂,試圖通過做。所以我一直在研究一個小程序,它將採用用戶名(比如計算機用戶名),將字母加起來,並根據總和來侮辱用戶,因爲爲什麼不呢。雖然我在line 10上遇到了一個錯誤,但由於我的代碼設置的方式,我很肯定我會在後面的每一行中都遇到它。你能幫我麼?我不斷收到錯誤代碼800A01B6「對象不支持此屬性或方法。」 (我刪除,因爲所使用的語言的侮辱,不用擔心......)vbscripting對象不支持屬性或方法如果elseif其他
Dim networkInfo
Dim nameVal
Dim infoStr
Dim insult
Set networkInfo = CreateObject("WScript.NetWork")
nameVal=1
infoStr = networkInfo.UserName & vbCr & vbLf
if InStr(1, networkInfo, "a") > 0 Then
nameVal = nameVal + 1
Elseif InStr(1, networkInfo, "b") > 0 Then
nameVal = nameVal + 2
Elseif InStr(1, networkInfo, "c") > 0 Then
nameVal = nameVal + 3
Elseif InStr(1, networkInfo, "d") > 0 Then
nameVal = nameVal + 4
Elseif InStr(1, networkInfo, "e") > 0 Then
nameVal = nameVal + 5
Elseif InStr(1, networkInfo, "f") > 0 Then
nameVal = nameVal + 6
Elseif InStr(1, networkInfo, "g") > 0 Then
nameVal = nameVal + 7
Elseif InStr(1, networkInfo, "h") > 0 Then
nameVal = nameVal + 8
Elseif InStr(1, networkInfo, "i") > 0 Then
nameVal = nameVal + 9
Elseif InStr(1, networkInfo, "j") > 0 Then
nameVal = nameVal + 10
Elseif InStr(1, networkInfo, "k") > 0 Then
nameVal = nameVal + 11
Elseif InStr(1, networkInfo, "l") > 0 Then
nameVal = nameVal + 12
Elseif InStr(1, networkInfo, "m") > 0 Then
nameVal = nameVal + 13
Elseif InStr(1, networkInfo, "n") > 0 Then
nameVal = nameVal + 14
Elseif InStr(1, networkInfo, "o") > 0 Then
nameVal = nameVal + 15
Elseif InStr(1, networkInfo, "p") > 0 Then
nameVal = nameVal + 16
Elseif InStr(1, networkInfo, "q") > 0 Then
nameVal = nameVal + 17
Elseif InStr(1, networkInfo, "r") > 0 Then
nameVal = nameVal + 18
Elseif InStr(1, networkInfo, "s") > 0 Then
nameVal = nameVal + 19
Elseif InStr(1, networkInfo, "t") > 0 Then
nameVal = nameVal + 20
Elseif InStr(1, networkInfo, "u") > 0 Then
nameVal = nameVal + 21
Elseif InStr(1, networkInfo, "v") > 0 Then
nameVal = nameVal + 22
Elseif InStr(1, networkInfo, "w") > 0 Then
nameVal = nameVal + 23
Elseif InStr(1, networkInfo, "x") > 0 Then
nameVal = nameVal + 24
Elseif InStr(1, networkInfo, "y") > 0 Then
nameVal = nameVal + 25
Elseif InStr(1, networkInfo, "z") > 0 Then
nameVal = nameVal + 26
Else MsgBox ("")
End If
If nameVal < 5 Then
insult = ("")
Elseif nameVal > 5 Then
insult = ("")
Elseif nameVal > 10 Then
insult = ("")
Elseif nameVal > 20 Then
insult = ("")
Elseif nameVal > 30 Then
insult = ("")
Elseif nameVal > 40 Then
insult = ("")
Elseif nameVal > 50 Then
insult = ("")
Elseif nameVal > 60 Then
insult = ("")
Elseif nameVal > 70 Then
insult = ("")
Elseif nameVal > 80 Then
insult = ("")
Elseif nameVal > 90 Then
insult = ("")
Elseif nameVal > 100 Then
insult = ("")
Elseif nameVal > 110 Then
insult = ("")
Elseif nameVal > 120 Then
insult = ("")
Elseif nameVal > 130 Then
insult = (".")
Elseif nameVal > 140 Then
insult = ("")
Elseif nameVal > 150 Then
insult = ("")
Elseif nameVal > 160 Then
insult = ("")
Elseif nameVal > 170 Then
insult = ("")
Elseif nameVal > 180 Then
insult = ("")
Elseif nameVal > 190 Then
insult = ("")
Elseif nameVal > 200 Then
insult = ("")
Elseif nameVal > 210 Then
insult = ("")
Elseif nameVal > 220 Then
insult = ("")
Elseif nameVal > 230 Then
insult = ("")
Elseif nameVal > 240 Then
insult = ("")
Elseif nameVal > 250 Then
insult = ("")
Elseif nameVal > 260 Then
insult = ("")
Elseif nameVal > 270 Then
insult = ("")
Elseif nameVal > 280 Then
insult = ("")
Elseif nameVal > 290 Then
insult = ("")
Elseif nameVal > 300 Then
insult = ("")
Elseif nameVal > 310 Then
insult = ("")
Elseif nameVal > 320 Then
insult = ("")
Elseif nameVal > 330 Then
insult = ("")
Elseif nameVal > 340 Then
insult = ("")
Elseif nameVal > 350 Then
insult = (".")
Elseif nameVal > 360 Then
insult = ("")
Elseif nameVal > 370 Then
insult = ("")
Elseif nameVal > 380 Then
insult = ("")
Elseif nameVal > 390 Then
insult = ("")
Elseif nameVal > 400 Then
insult = ("")
Elseif nameVal > 410 Then
insult = ("")
Elseif nameVal > 420 Then
insult = ("")
Elseif nameVal = 420 Then
insult = ("")
Elseif nameVal > 430 Then
insult = ("")
Elseif nameVal > 440 Then
insult = ("")
Elseif nameVal > 450 Then
insult = ("")
Elseif nameVal > 460 Then
insult = ("")
Elseif nameVal > 470 Then
insult = ("")
Elseif nameVal > 480 Then
insult = ("")
Elseif nameVal > 490 Then
insult = ("")
Elseif nameVal > 500 Then
insult = ("")
Elseif nameVal > 510 Then
insult = ("")
Elseif nameVal > 520 Then
insult = ("")
Elseif nameVal > 530 Then
insult = ("")
End If
MsgBox infoStr & insult
如果你也可以給我如何使代碼更有效或更好的結構化的提示,我也會很感激!感謝您花時間閱讀本文以及您可能給我的任何幫助。
這是打破節目的首要原則的經典案例 - [DRY(https://en.wikipedia.org/wiki/Don't_repeat_yourself)。你在做什麼?您可以爲每個值使用一個'Array',並使用一個循環來遍歷它們,並且執行檢查時不會出現所有這些重複的行,難以閱讀,效率低下並且難以管理。 – Lankymart
我不認爲你的腳本目前是如何工作的。它看起來像你想檢查用戶名中的所有字母變體,並從中產生一個數字值,但是,現在它只會檢查第一個匹配,因此你下次檢查例如'Elseif nameVal = 420 Then'將永遠不會碰到最大數量的第一個檢查將產生的是'26'。 – Lankymart