Reputation: 1557
Can you please tell me why I am getting the following error?
VBScript runtime error: This array is fixed or temporarily locked: 'temp'
This is the code that is generating the error. I am unsure of how to resolve it.
I am just trying to unpack a file that is in DRY folder and move it to ACS folder. Thank you very much
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
Upvotes: 1
Views: 2592
Reputation: 38775
While you can assign to/overwrite an array variable with arbitrary values:
>> a = Array(1)
>> b = Array(2)
>> a = b
>> b = 4711
>> WScript.Echo Join(a), b
>>
2 4711
you can't assign an array element to the variable holding the array itself:
>> 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
So re/mis-using the temp variable is one cause of your problem. The difference between "fil" and "file" will bite you next.
After reading Alex K's answer, I realise that you can avoid that error 10. I think that the outer () are 'pass me per value' parentheses, that create a copy ov the original array before the then harmless assignment. But I still believe that using proper variable names and not re-using variables is a better way.
Upvotes: 1
Reputation: 175936
This is caused by:
temp = temp(ubound(temp))
and can be fixed by:
temp = (temp(ubound(temp)))
Upvotes: 2