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 in CInt()

Status
Not open for further replies.

SnaveBelac

Programmer
Oct 21, 2003
89
GB
I am doing domething very simple. Requestng a form variable and converting it to an integer. The form variable is set to 0 so I know that it is an intger but I keep getting a typemismatch error when the page is processed !! The code is below...

Code:
<%
curPage = "quote"
SectionArray = Trim(Request.Form("SectionArray"))
arrSection = Split(SectionArray, ",")
For i = 0 to UBound(arrSection)
  arrSection(i) = Trim(arrSection(i))
Next
arrayIndex = Trim(Request.Form("arrayIndex"))
if arrayIndex <> "" Then arrayIndex = CInt(arrayIndex)
If arrayIndex = "" Then
  section = "start"
elseif arrayIndex < UBound(arrSection) Then
  section = arrSection(arrayIndex)
else
  section = "final"
End If
%>

I think I must be missing something stupid but I just cant figure out what it is !

I hope someone can help...

-----------------------
SnaveBelac - Adventurer
-----------------------
 
more then likely the form value is passing characters that are not valid for numeric convertions.

have you tried testing the form values being sent
e.g.
arrayIndex = Trim(Request.Form("arrayIndex"))
Response.Write arrayIndex
Response.End

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
are you setting the form variable to 0 or "0"?? The latter may cause an error.

Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Thanks for the quick reply fellas.

I have output the value of arrayIndex and it is definitely 0 (zero) and not 0 (oh)

Any other thoughts?

----------------------------
SnaveBelac - Adventurer
----------------------------
 
I think I'm at a loss for ideas. just because when I do this
Code:
arrayIndex = Trim("0 ")
if arrayIndex <> "" Then arrayIndex = cInt(arrayIndex)
	If arrayIndex = "" Then
	  section = "start"
	elseif arrayIndex < UBound(arrSection) Then
	  section = arrSection(arrayIndex)
	else
	  section = "final"
	End If

it works fine..which leads me to the form collection

maybe someone else has hit this prior. sorry..

___________________________________________________________________

The answer to your ??'s may be closer then you think.
Check out Tek-Tips knowledge bank by clicking the FAQ link at the top of the page
 
mmmmm, in my view CInt(arrayIndex) handles that.
on which codeline is the error?


ttmug.gif
 
OK - I have it sorted now. I had a section of code further down the page that looped through the forms collection and output hidden input fields for each one. This was duplicating the field that stored the arrayIndex variable and causing the error (At least I assume it was that causing the error as now I have removed it the error has gone!)

However, if two hidden controls have the same name shouldn't the ouput be "value1, value2"? When I output the arrayIndex value it was just 0 (zero) !!

Anyway it is working now. Thanks to everyone for helping me to focus...

----------------------------
SnaveBelac - Adventurer
----------------------------
 
In amswer to your question the error was on the line with cInt on it. The error actually picked out cInt as the offending function.

I had already checked the the type of value being assigned using varType(), so I was pretty sure that cInt should work.

I would still like to know why the output value looked correct and yet did not work !!

----------------------------
SnaveBelac - Adventurer
----------------------------
 
Hello SnaveBelac,

Change the conditional to:
Code:
if arrayIndex <> "" and IsNumeric(arrayIndex) Then arrayIndex = CInt(arrayIndex)

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top