Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Type mismatch - using arrays and functions

Reply
Thread Tools

Type mismatch - using arrays and functions

 
 
Laura
Guest
Posts: n/a
 
      07-23-2003
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!

 
Reply With Quote
 
 
 
 
AspDotNetDeveloper
Guest
Posts: n/a
 
      07-23-2003
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.

"Laura" <> wrote in message
news:851001c3515b$f25f9510$...
> 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!
>



 
Reply With Quote
 
 
 
 
Laura
Guest
Posts: n/a
 
      07-23-2003
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?
>-----Original Message-----
>Checked - it is an array, but still no go with the
>function. Other ideas?
>>-----Original Message-----
>>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.
>>
>>"Laura" <> wrote in message
>>news:851001c3515b$f25f9510$...
>>> 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!
>>>

>>
>>
>>.
>>

>.
>

 
Reply With Quote
 
Mark Schupp
Guest
Posts: n/a
 
      07-23-2003
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

http://www.ielearning.com
714.637.9480 x17


"Laura" <> wrote in message
news:067c01c35163$60b2f960$...
> 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?
> >-----Original Message-----
> >Checked - it is an array, but still no go with the
> >function. Other ideas?
> >>-----Original Message-----
> >>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.
> >>
> >>"Laura" <> wrote in message
> >>news:851001c3515b$f25f9510$...
> >>> 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!
> >>>
> >>
> >>
> >>.
> >>

> >.
> >



 
Reply With Quote
 
Joe Iano
Guest
Posts: n/a
 
      07-24-2003
Have you tried forcing the type?
like: cint(var1) = cint(var1)

"Laura" <> wrote in message
news:851001c3515b$f25f9510$...
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!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL Type Mismatch error indexed name returns a value whose type does not match programmingzeal VHDL 0 05-06-2012 06:38 AM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
type mismatch when using FindControl("...") daniel.hedz@gmail.com ASP .Net 5 01-17-2007 09:14 PM
Functions = Type mismatch James ASP General 1 03-31-2005 10:20 PM
Type mismatch using Mozilla ActiveX in place of Microsoft WebBrowser? Noozer Firefox 0 05-19-2004 08:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57