1

次のエラーが発生する理由を教えてください。

VBScript ランタイム エラー: この配列は固定されているか、一時的にロックされています: 'temp'

これは、エラーを生成しているコードです。私はそれを解決する方法がわかりません。

DRY フォルダーにあるファイルを解凍して ACS フォルダーに移動しようとしています。どうもありがとうございました

Set FSO = CreateObject("Scripting.FileSystemObject")
Set fldr = FSO.GetFolder("C:\Ebooks\DRY\")
For Each fil In fldr.Files
    If LCase( Right( fil.Name, 4 ) ) = ".zip" Then
        zipFilePath = fil.Path
        temp = file.Name
        temp = Left( temp, LEN(temp) - 4 ) ' remove the .zip
        temp = Split( temp, "_" ) ' split base name away from month-day-year
        temp = temp( UBOUND(temp) ) ' get just month-day-year
        temp = Split( temp, "-" ) ' get month day and year separately
        mn = CINT(temp(0)) ' get the month number
        dirName = MonthName(mn,True) & temp(2) ' True means get 3 letter abbrev for month
        Response.Write "Unpacking " & fil.Name & " to directory " & dirName & "<br/>" & vbNewLine
        objZip.UnPack zipFilePath, "D:\ACS\" & dirName & "\"
    End If
Next
4

2 に答える 2

2

これは次の原因で発生します:

temp = temp(ubound(temp))

次の方法で修正できます。

temp = (temp(ubound(temp)))
于 2012-05-17T13:13:33.957 に答える
1

配列変数に任意の値を代入/上書きできますが、次のようにします。

>> a = Array(1)
>> b = Array(2)
>> a = b
>> b = 4711
>> WScript.Echo Join(a), b
>>
2 4711

配列自体を保持する変数に配列要素を割り当てることはできません。

>> a = a(0)
>>
Error Number:       10
Error Description:  This array is fixed or temporarily locked
>> a = Array(Array(1), Array(2))
>> a = a(1)
>>
Error Number:       10
Error Description:  This array is fixed or temporarily locked

そのため、一時変数の再利用/誤用が問題の原因の 1 つです。次に、「fil」と「file」の違いに悩まされます。

Alex Kの回答を読んだ後、そのエラー10を回避できることがわかりました。外側()は「値ごとに渡す」括弧であり、無害な割り当ての前に元の配列のコピーを作成すると思います。しかし、適切な変数名を使用し、変数を再利用しない方が良い方法だと今でも信じています。

于 2012-05-17T13:28:23.470 に答える