Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does it mean when an error occurs stating? 1

Status
Not open for further replies.

zishan619

Programmer
May 28, 2003
284
0
0
MX
Hi I am using an array. I dim the array at the beginning and then redim the array again.
I get this error
This array is fixed or temporarily locked
....
Part of my code goes something like this:
Dim Code(1)
strZ="Select 8 from tblOrders"
set rs = server.CreateObject ("ADODB.recordset")
rs.Open strZ, ADOConn,1,3

rs.moveLast
rs.movefirst
x=0
ReDIM Code(rs.RecordCount)
do until rs.EOF
Response.Write &quot;<TH bgcolor=#cccccc nowrap>&quot; & vbcrlf
Response.Write rs(&quot;TPCode&quot;) & rs(&quot;TPCodeID&quot;) & vbcrlf
set Code(x)=rs(&quot;TPCodeID&quot;)
Response.Write &quot;</TH>&quot; & vbcrlf
x = x+1
rs.MoveNext
Loop
Thanks for the help
Z
 
when you originally dim you array do it with empty ()
i.e

Dim Code()
 
Hey Thanks. But now I get an error when I go down further in my code using the array:
I get an error on the following code:(Exception occurred. )
if rst(&quot;CodeID&quot;) = Code(x) then

below is the rest of my code.
I am using two recordsets.
rs and rst. Two sql statements.
Both are open.

do until rst.EOF
Response.Write &quot;<TR>&quot; & vbcrlf
Response.Write &quot;<TD nowrap>&quot; & rst(&quot;Manager&quot;) & &quot;</TD>&quot; & vbcrlf
Response.Write &quot;<TD nowrap>&quot; & rst(&quot;Analyst&quot;) & &quot;</TD>&quot; & vbcrlf
strAnalyst=rst(&quot;Analyst&quot;)
Response.Write &quot;<TD nowrap>&quot; & rst(&quot;dtsDate&quot;) & &quot;</TD>&quot; & vbcrlf
For x=0 to Ubound(Code)
if rst.EOF then
exit for
else

if strAnalyst <> rst(&quot;Analyst&quot;) then
if rst(&quot;CodeID&quot;) = Code(x) then
Response.Write &quot;<TD>&quot; & rst(&quot;Total_Hours&quot;) & rst(&quot;CodeID&quot;) & &quot;</TD>&quot; & vbcrlf
rst.MoveNext
else
Response.Write &quot;<TD> &nbsp;</TD>&quot; & vbcrlf
end if
Else
if rst(&quot;CodeID&quot;) = Code(x) then
Response.Write &quot;<TD>&quot; & rst(&quot;Total_Hours&quot;) & rst(&quot;CodeID&quot;) & &quot;</TD>&quot; & vbcrlf
rst.MoveNext
else
Response.Write &quot;<TD> &nbsp;</TD>&quot; & vbcrlf
end if
End if
End if
Next

loop
rs.Close
Set rs=Nothing

rst.Close
set rst=nothing
 
is rst(&quot;CodeID&quot;) = null or is it empty or it is a string or an array or what???

my guess is the comparison you are asking it to do isnt fair.

can you try and pipe the rst(&quot;CodeID&quot;) to the screen first and tell us what you see, i.e. use a msgbox
 
No it is a number from the second rst. it is 26. That is why I do not understand why it doesn't work. I did response.write rs.RecordCount and gave me the correct number which is 15.
I am so confused.
 
whats in your Code() array???

convert them both to Int or Str with CInt() or CStr()
then try and compare them
 
How do I do that.
Do I
Dim Code(CInt())
is that correct?
Thanks
 
I converted them and now my code reads:
if strAnalyst <> rst(&quot;Analyst&quot;) then
if CInt(rst(&quot;CodeID&quot;)) = CInt(Code(x)) then
Response.Write &quot;<TD>&quot; & rst(&quot;Total_Hours&quot;) & &quot;</TD>&quot; & vbcrlf
rst.MoveNext
else
Response.Write &quot;<TD> &nbsp;</TD>&quot; & vbcrlf
end if
Else
if CInt(rst(&quot;CodeID&quot;))= CInt(Code(x)) then
Response.Write &quot;<TD>&quot; & rst(&quot;Total_Hours&quot;) & &quot;</TD>&quot; & vbcrlf
rst.MoveNext
else
Response.Write &quot;<TD> &nbsp;</TD>&quot; & vbcrlf
end if
End if
End if
Next

loop
But I get the same error message.
Exception Occurred.
 
whne you grab something from a recordset sometimes you dont know what it is youve got, it might be NUll or an array etc

So, before doing the comparison try

If Not IsNull(rst(&quot;CodeID&quot;) Then
If Not IsArray(rst(&quot;CodeID&quot;) Then
'no compare, you should have something reasonable
 
I did what you have told me and I still get that error. I do not know what else to try or do.
Hey I wanted to say Thank you for helping me out.
 
no problem but i wont sleep tonight if we dont find the problem!!! ;-)
 
ok, at the line where it fails what is the value of:

x
CInt(Code(x))
CInt(rst(&quot;CodeID&quot;))

i.e. do a
response.write &quot;here we go just before&quot;
response.write x
response.write CInt(Code(x))
response.write CInt(rst(&quot;CodeID&quot;))

 
Well I place that in and this is the results of what I got when I response.write it out:
here we go just before
x=15
Code=0
CodeID=30
Let me explain what I am trying to do:
first I need to create a recordset which creates a row of TimeCodes.
Second I create another recordset which creates the analyst, manager, date and placing the correct hours into each of the appropiate timecodes.
I do not know if I am doing this correctly. It is like doing a crosstab query but yet as we all now crosstab can not be done in T-sql to use on an asp page. So this is the only way I can think of.
Now the tricky thing is that for each CCNum (site) there are different Timecodes associated with them. So that is why I am using an array.
Thanks
 
im lost, if you can pipe the results the screen then you should be able to compare them. strictly speaking you are implicitly converting them to a string when you put them to the screen....not that it should make the slightest difference.
how about trying a string comparison instead CStr()
whats more i think for safety sake you should do the IsNull stuff

sorry i not offering more help

mrmovie
 
Thank you mrmovie. But its all good. I thank you very much for even trying to help me out.
 
Dim code(1) ' static array, you cannot use ReDim later
Dim code() ' dynamic array, you can use ReDim later

Also, remember that numbers in VBScript may display identically, but actually be different data types. You cannot compare different numeric types without converting one or both to a common type as suggested above. Some conversion functions are:
Code:
cBool() 'vbBoolean  vartype()=11
cByte() 'vbByte     vartype()=17
cCur()  'vbCurrency vartype()=6
cDbl()  'vbDouble   vartype()=5
cInt()  'vbInteger  vartype()=2
cLng()  'vbLong     vartype()=3
cSng()  'vbSingle   vartype()=4
cStr()  'vbString   vartype()=8
Note that the vartype() function returns an integer type.
 
>set Code(x)=rs(&quot;TPCodeID&quot;)
Try to replace the above code with this:
Code(x)=rs(&quot;TPCodeID&quot;)

Hope This Help
PH.
 
Thank You PHV it worked. I forgot you can set an array. I was thinking yesterday. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top