...

View Full Version : Type Mismatch error....



jaywhy13
08-22-2005, 02:27 PM
I get this error:
Response object error 'ASP 0106 : 80020005'

Type Mismatch

/cvibe/c-link.asp, line 0

An unhandled data type was encountered.

C-Link file contents....

<html>
<head>
<title>Whats New - www.c-vibe.com</title>
<!-- #INCLUDE file="includes\header.asp" -->
<!-- #INCLUDE file="functions\folderFunctions.asp" -->
</head>

<body bgcolor="<%=bgColor2%>" topmargin="5px" background="<%=bg%>">
<script language="JavaScript1.2">mmLoadMenus();</script>
<table width="<%=tblWidth%>" align="center" border="1" cellpadding="0" cellspacing="0" id="mainTbl" bgcolor="black" bordercolor="<%=lightBlue%>">
<tr>
<td>
<!--#INCLUDE file="bannerNmenu.asp"-->
</td>
<%response.flush%>
</tr>

<tr>
<td>
<!--Container for the main part for the wattsnew page... -->
<table width="900px" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="80%" valign="top">
<%
Dim fId
fId = CLINK
folderDisplay(fId) %>

</td>

<td valign="top">
Random Images...
<!--#INCLUDE file="randomPics.asp"-->
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

I think the problem is at that line really (in red)...
here is also that function....


'Display functions..............................................................
function folderDisplay(fId)
'A valid folderId must be dimmed before this inclusion and initialised to some value
Dim folderId
folderId = CInt(fId)
grabFolder folderId,"full"
response.write folderId


end function

Once I try to write out the folder id.... I get that error... the one at the top of my post.... plz help

ghell
08-22-2005, 02:39 PM
what is CLINK.. if its not an earlier global variable that would just be trying to use Empty but i duno if thats the problem

however thats not line 0 anyway.. have you tried commenting out that response.flush as nowhere on that page (althoguh possibly on an earlier include) does it use response.buffer = true

also even earlier than this you have

<body bgcolor="<%=bgColor2%>" topmargin="5px" background="<%=bg%>">
so that might come up as line 0 and be a problem with those values.. or does it just say line 0 if it cant find which line its on or its a syntax not runtime error or something maby..

jaywhy13
08-22-2005, 03:04 PM
what is CLINK.. if its not an earlier global variable that would just be trying to use Empty but i duno if thats the problem

however thats not line 0 anyway.. have you tried commenting out that response.flush as nowhere on that page (althoguh possibly on an earlier include) does it use response.buffer = true

also even earlier than this you have

<body bgcolor="<%=bgColor2%>" topmargin="5px" background="<%=bg%>">
so that might come up as line 0 and be a problem with those values.. or does it just say line 0 if it cant find which line its on or its a syntax not runtime error or something maby..

CLINK is a global constant that I use... it is defined in the folderFunctions.asp file. It is not empty, I have written it out to the browser to test.

bgColor and bg are all define in my header file...

I tried both putting the lines:
<%@ Language=VBScript %>
<%option explicit
Response.Buffer=true%>
at the top and I also tried commenting out the flush... none worked

jaywhy13
08-22-2005, 03:10 PM
This is very frustrating...
this works...

function folderDisplay(fId)
'A valid folderId must be dimmed before this inclusion and initialised to some value
fId = CInt(fId)
response.write fId
grabFolder fId,"full"
end function
with the response before i call grabFolder.. but this arrangement gives me the error.


function folderDisplay(fId)
'A valid folderId must be dimmed before this inclusion and initialised to some value
fId = CInt(fId)
grabFolder fId,"full"
response.write fId

end function

It gives me an error if I attempt to write out fId after I am finished calling the grabFolder...
The grabFolder takes in two parameters... an int and a string. It makes NO reference to "fid".

jaywhy13
08-22-2005, 03:12 PM
To make it even more confusing... here's what I found.
This doesn't work...


function folderDisplay(fId)
'A valid folderId must be dimmed before this inclusion and initialised to some value
fId = CInt(fId)
grabFolder fId,"full"
response.write fId

end function
But this works...


function folderDisplay(fId)
'A valid folderId must be dimmed before this inclusion and initialised to some value
fId = CInt(fId)
grabFolder (fId),"full"
response.write fId

end function
...if i bracket the fid..
can anyone help explainin what could be going on here?

ghell
08-22-2005, 03:20 PM
when calling the sub try

Call grabFolder(fId, "full")


this probably wont fix it but might releave some of that confusing parenthasis stuff

also do u have on error resume next on or on error goto 0 because on error resume next can do things like exit the function on an error which might be why in one order it works and in one it doesnt..

jaywhy13
08-22-2005, 03:24 PM
when calling the sub try

Call grabFolder(fId, "full")


this probably wont fix it but might releave some of that confusing parenthasis stuff

also do u have on error resume next on or on error goto 0 because on error resume next can do things like exit the function on an error which might be why in one order it works and in one it doesnt..

Where exactly should I try putting that? Oh and using the call syntax gives the same error when its not bracketed.

But I really am trying to understand what is happening. What is causing the error so that I can be very sure of it and I can know what to do to correct it.

ghell
08-22-2005, 03:40 PM
*shrugs* when calling subs use

Call subname(arg1, arg2, etc)
or
subname arg1, ag2, etc

i was thinking it might be a problem if you used the () as it would kinda read it as

subname(arg1), arg2

which should throw an error if you have on error goto 0 on or just do nothing if you have on error resume next on.. this might not be the error at all however

jaywhy13
08-22-2005, 03:43 PM
I inserted the on error thing at the top... now its stop giving me the error
But I still cannot use the variable fid anywhere...
If I try to print it out... it doesn't print anything.. If I add extra text to the write string like...
response.write "the fid is: " & (fId)
It still doesn't print out a thing!
And I need to use the fid during the rest of the course of the function

ghell
08-22-2005, 04:07 PM
well you should use
On Error Goto 0
for developing (this is usually what it is by default) and then
On Error Resume Next
once its finished (you can switch between them at any time)


goto 0 throws an error, resume next allows you to handle it in its own way (it just continues to the next line but functions the next line is the next line outside the function), i would make sure it was on goto 0 at the moment
when using resume next you can use this sort of thing to make the final product a bit neater:
If Err.Number <> 0 Then
Response.Write Err.Description
Response.End
End Iflook at the Err object in "vbscript reference" or [d] in my signature for further help

really folder display should be a sub not a function anyway as it does not return anything.

try using this page:
on error goto 0

'it is a good idea to give arguments unique names, it does not need to be fId here
Sub folderDisplay(folderId)
'write the number to make sure its ok at this point
Response.Write "|" & folderId & "|"

Call grabFolder(folderId, "full")

'write the number to make sure it hasnt disapeared by here
Response.Write "!" & folderId & "!"
End Sub

Sub grabFolder(grabFolderId, strFullVar)
...
End Sub

'sample data
Dim CLINK
CLINK = 4

Dim fId
fId = CInt(CLINK)
Call folderDisplay(fId)i have a feeling the problem will be in grabFolder() if it is anywhere

jaywhy13
08-22-2005, 04:17 PM
Alright... have a look at the first few rows of my grabFolder function

function grabFolder(folderArray,mode)
'Takes as input... list of folder indices
Dim req 'Requested number of folders for grabbbing...
if not isArray(folderArray) AND isNumeric(folderArray) then
folderArray = Array(folderArray)
end if
req = ubound(folderArray)

Dim sqlWhere
if req = 0 then
sqlWhere = " folderId=" & folderArray(0)
else if req > 0 then
sqlWhere = " folderId IN (" & join(folderArray,",") & ")"
else
if blnDebug then response.write "No folders specified for grab!"
Exit Function
end if
end if
.
.
.
.
.
end function


It is supposed to taken in an array and a string... An array of ints... But I attempted to make it flexible. so it checks to see if I only supplied an int and a string and then converts the single int to an array... then runs the functions again.

See anything there that would cause a problem?

ghell
08-22-2005, 04:20 PM
change it to a sub (and dont forget Exit Fucntion --> Exit Sub)

neocool00
08-22-2005, 05:11 PM
@jaywhy13,
I think the problem here is fId = CInt(fId) in your folderDisplay function. My advice would be to change the fId inside of your function to some other variable. It's not good to use the same variable names unless you are passing them in by reference. Also, if your function does not return anything, I would make it a Sub instead.

ghell
08-22-2005, 05:16 PM
um.. i just said all of that :rolleyes:


Sub grabFolder
should fix i think..

jaywhy13
08-23-2005, 03:47 PM
@jaywhy13,
I think the problem here is fId = CInt(fId) in your folderDisplay function. My advice would be to change the fId inside of your function to some other variable. It's not good to use the same variable names unless you are passing them in by reference. Also, if your function does not return anything, I would make it a Sub instead.

@neocool00,
thanks for ur suggestions... u 2 ghell.. however none of those worked. The CInt function was not the problem... i tried using CInt after I was getting the error. Tried changing it to a sub.. that didn't solve the problem. The objective of the grab functions are not to return a value, they just grab some data and store them in some global arrays. I pick up that you're saying that by principle that should be a Sub... thanks for pointin that out.

For the most part I only use the variable names for reference because they are all just functions.

I've got 1000 lines of functions, some of them don't return a value.. is that reason to be concerned?

neocool00
08-23-2005, 05:33 PM
@jaywhy,
You can have a function that doesn't return anything, it's just kind of a best practice to have functions return things and subs to not. I don't know why, it's just the what I was told by some asp guru when I first started out.

jaywhy13
08-23-2005, 06:18 PM
Just another coding convention I guess... subs for no returns and functions for returning :p

ghell
08-23-2005, 07:48 PM
subs are subroutines and functions are functions..um.. its kinda just how it is.. the problem was more of how u were calling it confused subs and functions which might be why it came up on line 0

functions always should return data.. if they dont you are pretty much wasting stuff .. it would be kinda like just putting 1 on its own in a line.. there are probably other hidden performance benefits too but a big diff is how they are called.

for ages i had openConn and closeConn as functions even though they returned nothing.. it doesnt break it its just bad practice and prob a bit of a bugger for the interpreter or something..

i cant think what else would be the problem though.. try and isolate the code as i said earlier and put it all in one file.. making this a lot simpler should make it easier to find the bug.. if you still cant find it you can just post that isolated file here and we can take a look for you :)

jaywhy13
08-23-2005, 10:08 PM
I'm starting to think that the arguments might be a real part of the problem...
the GrabFunctions take in arguments as follows:
Sub grabFolder(folderArray,mode)
its expecting an array first... and a string second.
I added some code as I am lazy that will accept a single int and convert it into an int array... I was just thinkin that that could cause a problem.

And I was reading somewhere how they do the optional arguments in vb scripts.. one of the methods is an array method... where they use varying number of indices as optional arguemtns to the function. And since the argument types are different.. one being an int and the other being a string.. mayb it confuses things a little.

Consider again...

Dim req 'Requested number of folders for grabbbing...
if not isArray(folderArray) AND isNumeric(folderArray) then
folderArray = Array(folderArray)
end if
req = ubound(folderArray)

Dim sqlWhere
if req = 0 then
sqlWhere = " folderId=" & folderArray(0)
else if req > 0 then
sqlWhere = " folderId IN (" & join(folderArray,",") & ")"
else
if blnDebug then response.write "No folders specified for grab!"
Exit Sub
end if
end if

neocool00
08-24-2005, 02:49 PM
Not sure about this, but I think you will get a type mismatch on this line of code: "if not isArray(folderArray) AND isNumeric(folderArray) then". Mainly, because if folderArray is an array, it can't be numeric. I would check to see if it is an array first then check to see if it is numeric (if not an array). Doing both on one line is gonna throw an error.

jaywhy13
08-24-2005, 07:33 PM
Not sure about this, but I think you will get a type mismatch on this line of code: "if not isArray(folderArray) AND isNumeric(folderArray) then". Mainly, because if folderArray is an array, it can't be numeric. I would check to see if it is an array first then check to see if it is numeric (if not an array). Doing both on one line is gonna throw an error.
I see what you mean. Important point. But I would think that these functions in vb are properly equipped to deal with those kind of blunders from amateurs like myself...
I'll change it and get back to you as soon as I do

neocool00
08-24-2005, 09:04 PM
I see what you mean. Important point. But I would think that these functions in vb are properly equipped to deal with those kind of blunders from amateurs like myself...
I'll change it and get back to you as soon as I do
Nope, it's not and if it was then I wouldn't have to worry about mispelling variables all the time ;) "Know what I mean, Vern?"

jaywhy13
08-26-2005, 03:57 PM
Nope, it's not and if it was then I wouldn't have to worry about mispelling variables all the time ;) "Know what I mean, Vern?"
:D Know eXactly wot you mean...
However that seemed to solve only part of the problem. I still get the error. Does IIS just like go goof headed sometimes? COz I wonder about that alot? Does IIS go coo coo in tha head sometimes or is it ALWAYS an error in ur code?

ghell
08-26-2005, 04:22 PM
Not sure about this, but I think you will get a type mismatch on this line of code: "if not isArray(folderArray) AND isNumeric(folderArray) then". Mainly, because if folderArray is an array, it can't be numeric. I would check to see if it is an array first then check to see if it is numeric (if not an array). Doing both on one line is gonna throw an error.actually this would not throw the error, if you deduce it logically:

if it was an array then:
( (IsArray() --> True) AND (IsNumeric() --> False) ) --> False

every if statement you can convert into a series of true and falses and basically in the end it is If True Then ..in this case it goes like this:
If IsArray(arr) AND IsNumeric(arr) Then
If IsArray(arr) = True AND IsNumeric(arr) = True Then
If True = True AND False = True Then
If False = True Then

however if it was a number then:
( (IsArray() --> False) AND (IsNumeric() --> True) ) --> False

it would always return false as it cant be both...but its not the source of the error.

"if not isArray(folderArray) AND isNumeric(folderArray) then"
that actually says if it isnt an array and it is a number but it cant be both so it woulud work the same if it was just "if isNumeric(folderArray) then".. the not also confuses it if you dont use parenthasis to select which part you want NOT on etc.. if i had an if statement with more than one argument i would use "= False" not "NOT" as it makes it clearer.

also you can use that logic conversion i mentioned earlier in some useful places eg you can do this
blnIsATallGuy = (intHeight > 6 AND strGender = "Male")rather than this:
If intHeight > 6 AND strGender = "Male" Then
blnIsATallGuy = True
End Ifif you need to store a boolean for use in several if statements this can be very useful :)

its very unlikely its just iis messing you about, if you send me the whole code i will gladly debug it for you, just pm me here if you want my email addres to send the code :thumbsup:

neocool00
08-26-2005, 06:24 PM
@ghell,
Your right. I did a couple of test to confirm and could not throw an error (which is unusal b/c normaly I have no problems throwing one ;)). IsNumeric and IsArray is not going to throw a type mismatch error b/c it's checking the type, not the value of what the variable is.

@jay,
Going back to your original problem. I found this article, which pretty much states that there is a type mismatch problem. I thought the issue might be where I saw in your code that you had this:

Dim folderId
folderId = CInt(fId)
grabFolder folderId,"full"
I was thinking that because you specifically set the variable you are passing in as an Integer that that was causing the problem. But I did a test where I dimed a variable and assigned CInt(1) to it and then did a IsArray test and it did not error out. Only thing I can suggest at this point is to post the full source code for c-link.asp, since that is the page that is throwing an error. Somewhere on this page, you are setting a value to a variable and then using it in the wrong context, thus Type Mismatch error.

jaywhy13
08-26-2005, 10:01 PM
The watts-new.asp file includes a folderFunction.asp file which is 790 lines, which includes a displayFunction.asp file which is 200 lines.

Don't konw how you're gonna do it coz the wattsnew file includes alot of different files...
http://rapidshare.de/files/4403306/functions.zip.html (http://rapidshare.de/files/4403306/functions.zip.html )
Those are the main files...

jaywhy13
08-27-2005, 12:16 AM
Here is the contents of the watts new file:


<%@ Language=VBScript %>
<%option explicit
Response.Buffer=true%>
<%
on error goto 0
%>
<html>
<head>
<title>Whats New - www.c-vibe.com</title>
<!-- #INCLUDE file="includes\header.asp" -->
<!-- #INCLUDE file="functions\folderFunctions.asp" -->
</head>

<body bgcolor="<%=bgColor2%>" topmargin="5px" background="<%=bg%>">
<script language="JavaScript1.2">mmLoadMenus();</script>
<table width="<%=tblWidth%>" align="center" border="1" cellpadding="0" cellspacing="0" id="mainTbl" bgcolor="black" bordercolor="<%=lightBlue%>">
<tr>
<td>
<!--#INCLUDE file="bannerNmenu.asp"-->
</td>
<%response.flush%>
</tr>

<tr>
<td>
<!--Container for the main part for the page... -->
<table width="900px" cellpadding="5" cellspacing="0" border="0">
<tr>
<td width="80%" valign="top">
<%
Dim fId, tId
fId = CLINK
tId = WATTSNEW
typeDisplay (fId),(tId), 5
%>

</td>

<td valign="top">
<%
recentArticles (fId),(tId)
%>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

ghell
08-27-2005, 01:34 PM
"Your IP-address 62.252.0.8 is already downloading a file. You have to wait until it is finished.".. damn i hate rapidshare... thats not even my sodding ip its my isp grr :mad:

glenngv
08-29-2005, 12:48 PM
In VBScript, parameters are passed by parameter (ByRef) by default, the other type is by value (ByVal). Meaning if a Function or Sub modifies the parameter, the new value is carried over to the passed variable. See this (http://www.asp101.com/tips/index.asp?id=68) for more info on the difference of ByRef and ByVal.

So, to fix your problem, you have to pass the folderArray parameter by value because you don't want the change which might occur in the grabFolder function to reflect on the calling function or statements.


function grabFolder(ByVal folderArray, ByVal mode)

The best practice is to always specify the type and most often than not, you want it to be ByVal. There may be few instances that you need it to be ByRef. You have to know when to use each of them.

jaywhy13
08-29-2005, 04:46 PM
hmm... thanks for pointin that out. And I'm definitely gonna read the link that you posted. I don't want folderArray to be changed, neither do I want mode to be changed. I want them to be independent variables that are local to the function/sub once they are passed in.

Secondly... the grab sub's all make reference to a global array function... the "folders" array.

Would that cause a problem?

jaywhy13
08-30-2005, 02:43 PM
THAT SOLVED THE PROBLEM!!!!! :thumbsup: Thanks guys!!!!

jaywhy13
08-30-2005, 02:49 PM
That worked!!!!! :thumbsup: And now I know why...
Silly error too....
Look back at the first few lines of the function..

function grabFolder(folderArray,mode)
'Takes as input... list of folder indices
Dim req 'Requested number of folders for grabbbing...
if not isArray(folderArray) AND isNumeric(folderArray) then
folderArray = Array(folderArray)
end if
req = ubound(folderArray)

Dim sqlWhere
if req = 0 then
sqlWhere = " folderId=" & folderArray(0)
else if req > 0 then
sqlWhere = " folderId IN (" & join(folderArray,",") & ")"
else
if blnDebug then response.write "No folders specified for grab!"
Exit Function
end if
end if
.
.
.
.
.
end function

If an INT is passed in, it is converted to an array.... if an array is passed in, its stays as an array...
The type mismatch came from me passing the array to a write method. Because often times I would simply pass an int into the array but I would want to print back out the int.. but it was converted to an array by that time...

However, now that I used "byVal" and a copy of the variable was made... no change occurs to the variable which is what I have now come to notice is really what I wanted to happen...
:p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum