Type mismatch - using arrays and functions

L

Laura

Help. Below is my code. Getting Type mismatch error on
the noted line. I'm trying to send an array (aryNewD)
with 4 columns and x rows to a function to save all the
array info into a SQL Server table via a stored
procedure. Keep getting this error. Any suggestions?

Code:
'ASP:

if blnNewD then
dim blnWrite
if fDisasterDescription_Write2(aryNewD) = 1
then 'ERROR MESSAGE POINTS TO THIS LINE
blnWrite = True
else
blnWrite = False
end if
if not blnWrite then blnValid = False
if blnValid = False then
response.write "An error has occured."
response.end
end if
end if

'---------------------------------------------------------
-----------------------------
'Function:

function fDisasterDescription_Write2(aryNewD)


dim conDisasterWaste, cmdDisasterWaste,
blnCriticalError
dim param1, param2, param3, param4, param5
dim my_adCmdStoredProc, my_adChar, my_adInteger,
my_adParamInput
dim my_adSmallInt, my_adVarChar, my_adDate
dim strTypeID, strDescription, strDate, intDisasterID

my_adCmdStoredProc = &H0004
my_adChar = 129
my_adInteger = 3
my_adParamInput = &H0001
my_adSmallInt = 2
my_advarchar = 200
my_adDate = 7

'Set the Connection Object

set conDisasterWaste = server.createobject
("ADODB.Connection")

conDisasterWaste.Open "database", "username", "password"

'Run stored procedure

set cmdDisasterWaste = server.CreateObject
("ADODB.Command")

set cmdDisasterWaste.ActiveConnection =
conDisasterWaste
cmdDisasterWaste.CommandType = my_adCmdStoredProc
cmdDisasterWaste.CommandText
= "tf_insert_DisasterDescription"

set param1 = cmdDisasterWaste.CreateParameter
("@idLandfill", my_adChar, my_adParamInput, 12)
set param2 = cmdDisasterWaste.CreateParameter
("@typeID", my_adSmallint, my_adParamInput)
set param3 = cmdDisasterWaste.CreateParameter
("@description", my_advarchar, my_adParamInput, 1000)
set param4 = cmdDisasterWaste.CreateParameter("@date",
my_adDate, my_adParamInput)
set param5 = cmdDisasterWaste.CreateParameter
("@disasterid", my_adinteger, my_adParamInput)

cmdDisasterWaste.Parameters.Append(param1)
cmdDisasterWaste.Parameters.Append(param2)
cmdDisasterWaste.Parameters.Append(param3)
cmdDisasterWaste.Parameters.Append(param4)
cmdDisasterWaste.Parameters.Append(param5)

cmdDisasterWaste.Parameters("@idlandfill") = Session
("idlandfill")

For i = 0 to ubound(aryNewD, 2)
strTypeID = aryNewD(1, i)
strDescription = aryNewD(3, i)
strDate = aryNewD(2, i)
intDisasterID = aryNewD(0, i)

cmdDisasterWaste.Parameters("@typeID") = strTypeID
cmdDisasterWaste.Parameters("@description") =
strDescription
cmdDisasterWaste.Parameters("@date") = strDate
cmdDisasterWaste.Parameters("@disasterid") =
intDisasterID

cmdDisasterWaste.execute
Next

If Err.number = 0 then
fDisasterDescription_Write2 = 1
Else
fDisasterDescription_Write2 = 2
Response.Write(err.description & "<br>")
end if

set cmdDisasterWaste.ActiveConnection = Nothing
set cmdDisasterWaste = Nothing

conDisasterWaste.Close
set conDisasterWaste = Nothing


end function

THANK YOU!
 
A

AspDotNetDeveloper

You should use the IsArray function to test that it is actually an array,
before calling the function, or in the first part of the function.
 
L

Laura

Even if I change the function to get rid of the database
crap and simply be the following:

function fDisasterDescription_write3(aryNewD)

dim strTypeID, strDescription, strDate, intDisasterID

fDisasterDescription_write3 = 2

For i = 0 to ubound(aryNewD, 2)
strTypeID = aryNewD(1, i)
strDescription = aryNewD(3, i)
strDate = aryNewD(2, i)
intDisasterID = aryNewD(0, i)

response.write strTypeID & ", " & strDescription
& ", " & strDate & ", " & intDisasterID & "<br>"
Next

if err.number > 0 then
fDisasterDescription_Write3 = 2
else
fDisasterDescription_Write3 = 1
end if

end function


I still have the same type mismatch error. Help?
 
M

Mark Schupp

What happens if you set the function result to a variable

dim code

code = fDisasterDescription_Write2(aryNewD)
Response.Write code

--
Mark Schupp
--
Head of Development
Integrity eLearning
Online Learning Solutions Provider
(e-mail address removed)
http://www.ielearning.com
714.637.9480 x17
 
J

Joe Iano

Have you tried forcing the type?
like: cint(var1) = cint(var1)

Help. Below is my code. Getting Type mismatch error on
the noted line. I'm trying to send an array (aryNewD)
with 4 columns and x rows to a function to save all the
array info into a SQL Server table via a stored
procedure. Keep getting this error. Any suggestions?

Code:
'ASP:

if blnNewD then
dim blnWrite
if fDisasterDescription_Write2(aryNewD) = 1
then 'ERROR MESSAGE POINTS TO THIS LINE
blnWrite = True
else
blnWrite = False
end if
if not blnWrite then blnValid = False
if blnValid = False then
response.write "An error has occured."
response.end
end if
end if

'---------------------------------------------------------
-----------------------------
'Function:

function fDisasterDescription_Write2(aryNewD)


dim conDisasterWaste, cmdDisasterWaste,
blnCriticalError
dim param1, param2, param3, param4, param5
dim my_adCmdStoredProc, my_adChar, my_adInteger,
my_adParamInput
dim my_adSmallInt, my_adVarChar, my_adDate
dim strTypeID, strDescription, strDate, intDisasterID

my_adCmdStoredProc = &H0004
my_adChar = 129
my_adInteger = 3
my_adParamInput = &H0001
my_adSmallInt = 2
my_advarchar = 200
my_adDate = 7

'Set the Connection Object

set conDisasterWaste = server.createobject
("ADODB.Connection")

conDisasterWaste.Open "database", "username", "password"

'Run stored procedure

set cmdDisasterWaste = server.CreateObject
("ADODB.Command")

set cmdDisasterWaste.ActiveConnection =
conDisasterWaste
cmdDisasterWaste.CommandType = my_adCmdStoredProc
cmdDisasterWaste.CommandText
= "tf_insert_DisasterDescription"

set param1 = cmdDisasterWaste.CreateParameter
("@idLandfill", my_adChar, my_adParamInput, 12)
set param2 = cmdDisasterWaste.CreateParameter
("@typeID", my_adSmallint, my_adParamInput)
set param3 = cmdDisasterWaste.CreateParameter
("@description", my_advarchar, my_adParamInput, 1000)
set param4 = cmdDisasterWaste.CreateParameter("@date",
my_adDate, my_adParamInput)
set param5 = cmdDisasterWaste.CreateParameter
("@disasterid", my_adinteger, my_adParamInput)

cmdDisasterWaste.Parameters.Append(param1)
cmdDisasterWaste.Parameters.Append(param2)
cmdDisasterWaste.Parameters.Append(param3)
cmdDisasterWaste.Parameters.Append(param4)
cmdDisasterWaste.Parameters.Append(param5)

cmdDisasterWaste.Parameters("@idlandfill") = Session
("idlandfill")

For i = 0 to ubound(aryNewD, 2)
strTypeID = aryNewD(1, i)
strDescription = aryNewD(3, i)
strDate = aryNewD(2, i)
intDisasterID = aryNewD(0, i)

cmdDisasterWaste.Parameters("@typeID") = strTypeID
cmdDisasterWaste.Parameters("@description") =
strDescription
cmdDisasterWaste.Parameters("@date") = strDate
cmdDisasterWaste.Parameters("@disasterid") =
intDisasterID

cmdDisasterWaste.execute
Next

If Err.number = 0 then
fDisasterDescription_Write2 = 1
Else
fDisasterDescription_Write2 = 2
Response.Write(err.description & "<br>")
end if

set cmdDisasterWaste.ActiveConnection = Nothing
set cmdDisasterWaste = Nothing

conDisasterWaste.Close
set conDisasterWaste = Nothing


end function

THANK YOU!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top