Linker IT Software
Google
Web www.oraxcel.com
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
VB6: This array is fixed or temporarily locked (Read 6798 times)
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
VB6: This array is fixed or temporarily locked
09.03.09 at 10:50:44
 
VB6: This array is fixed or temporarily locked
 
In VB, error 10 is received with the description "This array is fixed or temporarily locked". Is this a bug in VB6? I am using VB6 SP2.
 
The statement on which the error seems to occur is this:
MsgBox strMsg, vbOKOnly, cAppTitle
 
The error only occurs with compiled code and not when run in VB6. The strange thing is that the message box is actually shown as normal and the error comes aftwerwards. The error line reported is the line on which the msgbox statement is coded. The next line with a different line number is an End If statement. Perhaps another piece of code is raising the error but which.
Back to top
 
« Last Edit: 09.03.09 at 11:15:06 by Gerrit-Jan Linker »  

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Re: VB6: This array is fixed or temporarily locked
Reply #1 - 09.03.09 at 14:04:36
 
Commenting the message box statement out made the code fail on an earlier statement with the same error message. It was a call to the Excel Range object to do a sort. Commenting that out made it fail yet somewhere else. Interesting. Bug in VB or Excel?
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Gerrit-Jan Linker
YaBB Administrator
*****




Posts: 75
Re: VB6: This array is fixed or temporarily locked
Reply #2 - 12.03.09 at 12:39:11
 
Problem solved!
 
After reading this article at MSDN I started wondering whether I had locked a variant. I actually didn't know you could lock a variant but there you go!
http://msdn.microsoft.com/en-us/library/aa231012(VS.60).aspx
 
Code that failed:

j=0
For each Cell in Row.Cells
  With vntFields(j)
    .Value = Cell.Value
    If .Error <> 0 then
     lFieldInError = j
     Exit For
    end if
  end with
  j=j+1
Next Cell

 
The problem occurs when .Error <> 0 and when it hits the exit for. I believe it leaves the variant array vntFields(j) locked.
 
After modifying the code to remove the with statement the problem is resolved:
 

j=0
For each Cell in Row.Cells
  vntFields(j).Value = Cell.Value
  If vntFields(j).Error <> 0 then
    lFieldInError = j
    Exit For
  end if
  j=j+1
Next Cell
Back to top
 
 

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1