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

Comparing an array value to a recordset value

Status
Not open for further replies.

transparent

Programmer
Sep 15, 2001
333
GB
if arr_department_id(i) = obj_RSet("department_id") then ....

however it doesn't seem to detect when the values do match.

I thought this might be due to the fact that the value in the array may be considered a string but

cint(arr_department_id(i)) doesn't seem to work (i get an error)

I've also tried trimming both values - this didn't help either.

Does naybody have a solution to this problem??
 
The first thing I would do is check exactly what is contained in each variable to see if they are compatible to be compared. The second thing I would say is to put the error you get in this thread to give us a chance of helping you :p. -GTM Consult, Home of USITE-
-=
 
The array was created using the split command upon a string ie 2,4,5,6,7

The data in obj_RSet("department_id") is of type int.

The error was:

Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'cint'

corresponding to:

if cint(arr_department_id(i)) = obj_RSet("department_id") then.....


Cheers
 
Hmm. Whats the error generated when you use just:

if cint(arr_department_id(i)) = obj_RSet("department_id") then..... ?

Can you post the full code here?

-GTM Consult, Home of USITE-
-=
 
Have you tried forcing both values to Int??
Code:
If CInt(arr_department_id(i)) = CInt(obj_RSet("department_id")) Then.....
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
I have included the code apart from the database connectivity stuff which is tried and tested.

The error corresponds to ' cint(arr_department_members(i)) '

<%

str_department_members = request.form(&quot;str_department_members&quot;)
arr_department_members = split(str_department_members,&quot;,&quot;)

...data base connectivity.....

if isarray(arr_department_members) then

for i=0 to ubound(arr_department_members)

if cint(arr_department_members(i)) = obj_RSet(&quot;department_id&quot;) then response.write &quot;match!&quot;

next
end if

%>

cheers
 
the problem stems from not being able to force arr_department_members(i) to a int using cint. Any ideas?
 
The solution I have used...

if arr_department_members(i) = cstr(obj_RSet(&quot;department_id&quot;))

cheers for the help.

 
Ok I ran some test code on my server...

===========
<?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;<html xmlns=&quot;<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; />
</head>

<%

str_department_members = &quot;1,2,3,4,5,6,7,8,9&quot;
arr_department_members = split(str_department_members,&quot;,&quot;)

test_string = 6

if isarray(arr_department_members) then

for i=0 to ubound(arr_department_members)

if cint(arr_department_members(i)) = test_string then response.write &quot;match! &quot; & arr_department_members(i)

next
end if

%>

<body>
</body>
</html>
============

and the results can be seen at
This leads me to believe that there is a problem with either what is getting passed from your form, or what is coming from the database.

Any help?
-GTM Consult, Home of USITE-
-=
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top