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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type mismatch 1

Status
Not open for further replies.

coachdan

MIS
Mar 1, 2002
269
US
I am getting a type mismatch (800a000d) on the following segment of code. The error is thrown on the line starting "For i = 1..." Could this be caused by using the Dim statement with ASP? Or can anyone see another reason?

Code:
KCO = Request.Form("KCOCodes").Count



Dim KCOCodes()
Dim C

For C = 1 to KCO
	CurRecs = Request.Form("KCOCodes").Count
	REDIM PRESERVE KCOCodes(CurRecs)
Next



For i = 1 to Request.Form("KCOCodes").Count
	KCO(i) = Request.Form("KCOCodes")(i)
Next

coachdan32

 
should this
KCO(i) = Request.Form("KCOCodes")(i)

be this

KCOCodes(i) = Request.Form("KCOCodes")(i)
 
<%
KCO = int(Request(&quot;KCOCodes&quot;).Count)

ReDim KCOCodes(KCO)

For i = 0 to KCO-1
KCOCodes(i) = Request(&quot;KCOCodes&quot;)(i+1)
Next

%>

Remember arrays in ASP start at 0

 
<%
KCO = int(Request(&quot;KCOCodes&quot;).Count)

ReDim KCOCodes(KCO)

For i = 0 to KCO-1

KCOCodes(i) = Request(&quot;KCOCodes&quot;)(i+1)
Next

%>

Remember arrays in ASP start at 0

 
GaryC,

Tried your suggestion and I am now getting the following error:

Microsoft VBScript runtime error '800a01a8'

Object required: 'KCO'

/Training_Dept/KCOCP.asp, line 73


Replaced:

Code:
KCO = Request.Form(&quot;KCOCodes&quot;).Count



Dim KCOCodes()
Dim C

For C = 1 to KCO
    CurRecs = Request.Form(&quot;KCOCodes&quot;).Count
    REDIM PRESERVE KCOCodes(CurRecs)
Next



For i = 1 to Request.Form(&quot;KCOCodes&quot;).Count
    KCO(i) = Request.Form(&quot;KCOCodes&quot;)(i)
Next


With:

Code:
KCO = int(Request(&quot;KCOCodes&quot;).Count)

ReDim KCOCodes(KCO)

For i = 0 to KCO-1

    KCOCodes(i) = Request(&quot;KCOCodes&quot;)(i+1)
Next

coachdan32

 
do you have a option explicit in the page and are not definnig this var

_____________________________________________________________________
onpnt2.gif

Hakuna matata!!
 
The error actually comes in the next section of code where the values are being validated. I didn't post the code in the last post because I was still trying to track down where it was occurring.

Code:
For i = 1 to KCO.Count
	If (KCO(i) = &quot; &quot;) Then
		KCO(i) = Null
	Else
		KCO(i) = CSng(KCO(i))
	End If
Next

Should the KCO throughout this segment maybe be KCOCodes instead of KCO? I am a bit lost on which variable holds what value. It is confusing to me because it seems that KCO, CurRecs, and KCOCodes all are being assigned the same value (KCOCodes.Count). I'm new, but usually able to follow what is going on and the reason, but I am lost on this one.

coachdan32

 
Yep well spotted, I changed it kcocodes since you were using kco as a counter variable which would give an error since you were using it as an array as well. So just change kco to kcocodes in the rest of your code

 
Now instead of getting the &quot;Object required: 'KCO'&quot; error, it says &quot;Object required: 'KCOCodes'&quot;. The error is thrown on the same line as before. It seems like it doesn't matter which object is used, it doesn't recognize either of them.

coachdan32

 
GaryC,

This will probably sound stupid, but I can not be 100% sure because this is inherited code. I do have the db and the ability to view the page, so I will try to interpret a hopefully somewhat acurate guess.

There are an assortment of fields in the db named KCO1, KCO2, KCO3 (up to KCO35)...that the users have to input a value of 0, 0.5 or 1.0 into. These are fixed values entered via a dropdown box for each. The KCO fields represent days within a period, which can vary between 28 days and 35 days (based on a 7 day week and the 4-4-5 scheme that most companies use for a corporate year). I believe the section of code we are working on is trying to get a count of whether the number entered is 28 or 35 and then using that number to roll through the array for values. I'm sorry if that is not helpful enough, I am new to programming and all the code I am dealing with is inherited. I will gladly post all the code if you have the time to muddle through it. I appreciate the fact you have taken time to help me, especially since I am the only programmer on my site and have no one else to ask. I have been able to figure a lot of my inherited problems out on my own, but this one has me lost.

coachdan32

 
Maybe best to see the whole code, for example this

KCO(i) = CSng(KCO(i))

is basically just setting the array element to itself! So I don't see the point of this code section, apart from whatever KCO.Count is supposed to be - I assume the field count from the previous page, but the syntax is wrong.

For i = 1 to KCO.Count
If (KCO(i) = &quot; &quot;) Then
KCO(i) = Null
Else
KCO(i) = CSng(KCO(i))
End If
Next


 
Here is the full code for the page throwing the error:

Code:
<%@language=&quot;vbscript&quot;%>
<%
varBusName = Session(&quot;varRedirectBus&quot;)
%>
<!--#include file=&quot;global.asa&quot;-->
<!--#include file=&quot;include/Connect.asp&quot;-->
<html>

<head>
<title>Classroom Occupancy Confirmation Page</title>
</head>

<body background=&quot;WB00760_.gif&quot;>

<hr>

<hr>

<p><font size=&quot;6&quot;>Classroom Occupancy Confirmation Page</font></p>

<hr>

<hr>
<!--#include file=&quot;include/menu.asp&quot;-->
<%


varLocCity = Request.Form(&quot;LocCity&quot;)
varVBU = Request.Form(&quot;VBU&quot;)
varTrnRm = Request.Form(&quot;TrnRm&quot;)


If (varLocCity=&quot; &quot;) Then
	Response.Write &quot;<H2>ERRORS PLEASE CORRECT</H2>&quot;
  	Response.Write &quot;Please Enter: <H2>'LOCATION CITY'</H2> <BR><BR>&quot;
	Response.Write &quot;Use your Back Button to correct field - Use reset to clear all fields.&quot;
	Response.End
End If
If (varTrnRm=&quot; &quot;) Then
	Response.Write &quot;<H2>ERRORS PLEASE CORRECT</H2>&quot;
  	Response.Write &quot;Please Enter: <H2>'CLASS ROOM'</H2> <BR><BR>&quot;
	Response.Write &quot;Use your Back Button to correct field - Use reset to clear all fields.&quot;
	Response.End
End If


varMonth = Request.Form(&quot;MonMonth&quot;)
varYear = Request.Form(&quot;YrYear&quot;)


KCO = int(Request(&quot;KCOCodes&quot;).Count)

ReDim KCOCodes(KCO)

For i = 0 to KCO-1

KCOCodes(i) = Request(&quot;KCOCodes&quot;)(i+1)
Next

'Validate Array Numbers
'

For i = 1 to KCO.Count
	If (KCO(i) = &quot; &quot;) Then
		KCO(i) = Null
	Else
		KCO(i) = CSng(KCO(i))
	End If
Next

'*************************** LOAD TABLE ********************
'

lsYear = Right(varYrA, 2)

If varBusName = &quot;Citi&quot; Then
varDB = &quot;Training_Delivery_Data&quot; & lsYear & &quot;.mdb&quot;
Else
varDB = &quot;Training_Delivery_Data&quot; & lsYear & &quot;Sears.mdb&quot;
End If

Connect = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.Mappath(varDB) & &quot;;&quot;

   	SQLAdd = &quot; SELECT * FROM KCO &quot;

   	Set uCN = Server.CreateObject(&quot;ADODB.Connection&quot;)
	Set uRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)
	
On Error Resume Next
uCN.Open Connect
if ERR.Number <> 0 then
Response.Write(&quot;Error Number -> &quot; & Err.Number)
Response.Write(&quot;<BR>Error Source -> &quot; & Err.Source)
Response.Write(&quot;<BR>Error Desc -> &quot; & Err.Description)
Response.Write(&quot;<BR>Connect -> &quot; & Connect)
Err.Clear
end if
uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic


uRS.AddNew

uRS.Fields(&quot;LocCity&quot;) = varLocCity
uRS.Fields(&quot;Month&quot;) = varMonth
uRS.Fields(&quot;Year&quot;) = varYear
uRS.Fields(&quot;TrnRm&quot;) = varTrnRm

For i = 1 to 35
uRS.Fields(&quot;KCO&quot; & i) = KCOCodes(i)
Next
uRS.Update
uRS.Close
Set uRS=nothing

' Headers & Data
'
%>

<h2>KCO Confirm Page</h2>
<%
Response.Write &quot;Here are the Records that have been entered&quot;

Response.Write (&quot;<table border=1>&quot;)

Response.Write (&quot;<tr><th>Location City</th><th>Month</th><th>Year</th><th>Training Room</th></tr>&quot;)
Response.Write (&quot;<tr><td>&quot; & varLocCity & &quot;</td><td>&quot; & varMonth & &quot;</td><td>&quot; & varYear & &quot;</td><td>&quot; & varTrnRm & &quot;</td></tr>&quot;)


Response.Write (&quot;<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>&quot;)
Response.Write (&quot;<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>&quot;)


Response.Write (&quot;</table>&quot;)
%>

<p><br>
<br>
<a HREF=&quot;KCORD.asp?Yr=<%=varYrA%>&quot;>Click Here to Enter Additional 'KeyMetrics CO' Data</a><br>
<br>
<a HREF=&quot;/../Default.asp&quot;>Click Here for Main Menu</a> </p>
</body>
<%

Conn.Close
Set Conn=Nothing

%>
</html>

It is a confirmation page for the database form where they input the values. If you need to see the code for the input page as well, I will gladly post it as well. I don't want to overwhelm you with code when I know you have a job of your own to do as well.

coachdan32

 
I've amended the middle section of code.

<%
' Get the number of fields on the previous page
KCO = int(Request(&quot;KCOCodes&quot;).Count)

ReDim KCOCodes(KCO)

' Assign them to the array
For i = 0 to KCO-1
KCOCodes(i) = Request(&quot;KCOCodes&quot;)(i+1)
Next

'*************************** LOAD TABLE ********************

lsYear = Right(varYrA, 2)

If varBusName = &quot;Citi&quot; Then
varDB = &quot;Training_Delivery_Data&quot; & lsYear & &quot;.mdb&quot;
Else
varDB = &quot;Training_Delivery_Data&quot; & lsYear & &quot;Sears.mdb&quot;
End If

Connect = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & Server.Mappath(varDB) & &quot;;&quot;

SQLAdd = &quot; SELECT * FROM KCO &quot;

Set uCN = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set uRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

On Error Resume Next
uCN.Open Connect
if ERR.Number <> 0 then
Response.Write(&quot;Error Number -> &quot; & Err.Number)
Response.Write(&quot;<BR>Error Source -> &quot; & Err.Source)
Response.Write(&quot;<BR>Error Desc -> &quot; & Err.Description)
Response.Write(&quot;<BR>Connect -> &quot; & Connect)
Err.Clear
end if
uRS.Open SQLAdd, Connect, adOpenKeyset,adLockOptimistic


uRS.AddNew

uRS.Fields(&quot;LocCity&quot;) = varLocCity
uRS.Fields(&quot;Month&quot;) = varMonth
uRS.Fields(&quot;Year&quot;) = varYear
uRS.Fields(&quot;TrnRm&quot;) = varTrnRm

' Loop thru the array and update the database
For i = 1 to (ubound(KCOCodes)+1)
uRS.Fields(&quot;KCO&quot; & i) = KCOCodes(i-1)
Next
uRS.Update
uRS.Close
Set uRS=nothing

%>

 
GaryC,

You are wonderful! That got rid of the error messages. The only problem I have now is the date and year is not being posted to the db. I had this problem on another page that was similar to this one and got it resolved. I am going to have a go at these myself. I thank you for the effort and you will definately get a star for your time. Thanks!!

coachdan32

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top