Ricky11
asked on
UNABLE TO COMAPRE STRING VALUE , PLEASE HELP! 500PTS. URGENT
Okay I am using the following code to compare a value, I have checked both values contains the same text but it does not execute the if then else code.. something must be still wrong..
' get the querystring in the url and save in 'a' in this case firstofsize = '72X90"OB'
<%a = Request.QueryString("first ofsize")%>
' Just to make sure that it is there
<%=A%> ' this outputs 72X90"OB
' i need to run a loop to check each record and comapre the record to check if it matches with a, if so then execute the statement
<% t = 1 %>
<% do while t <> 7 %>
<%IF a = (FP_FieldVal(fp_rs,"size" & t )) then%>
<%response.write FOUND%>
<% else %>
<% response.write "NOTFOUND" %>
<% end if%>
<%t = t + 1%>
<% loop %>
The output that I get is all NOTFOUND, even though I know that when i output the value of
(FP_FieldVal(fp_rs,"size" & t )) i do see the same value of 'a' so i don't see why it is unble to compare it..
i dont think it has anything to do with the type of variable, both should be strings
note that (FP_FieldVal(fp_rs,"size" & t )) refers to field from size1 to size7, for example the code cycles through size1 through size7 and comapres each of them to the value of a, so for example.
VALUE OF A = 72X90"OB
SIZE1 = 72X72"RD
SIZE2 = 45X45"SQ
SIZE3 = 72X90"OB -- here it should find that the value of (FP_FieldVal(fp_rs,"size" & t )) = to 'a'
SIZE4= 60X60"RD
Hope his is understandable.
Thanks.
' get the querystring in the url and save in 'a' in this case firstofsize = '72X90"OB'
<%a = Request.QueryString("first
' Just to make sure that it is there
<%=A%> ' this outputs 72X90"OB
' i need to run a loop to check each record and comapre the record to check if it matches with a, if so then execute the statement
<% t = 1 %>
<% do while t <> 7 %>
<%IF a = (FP_FieldVal(fp_rs,"size" & t )) then%>
<%response.write FOUND%>
<% else %>
<% response.write "NOTFOUND" %>
<% end if%>
<%t = t + 1%>
<% loop %>
The output that I get is all NOTFOUND, even though I know that when i output the value of
(FP_FieldVal(fp_rs,"size" & t )) i do see the same value of 'a' so i don't see why it is unble to compare it..
i dont think it has anything to do with the type of variable, both should be strings
note that (FP_FieldVal(fp_rs,"size" & t )) refers to field from size1 to size7, for example the code cycles through size1 through size7 and comapres each of them to the value of a, so for example.
VALUE OF A = 72X90"OB
SIZE1 = 72X72"RD
SIZE2 = 45X45"SQ
SIZE3 = 72X90"OB -- here it should find that the value of (FP_FieldVal(fp_rs,"size" & t )) = to 'a'
SIZE4= 60X60"RD
Hope his is understandable.
Thanks.
so:
why dont you use a for loop:
For t = 1 to 6
If a = (FP_fieldval(fp_rs,"size" & t )) Then
Response.write "FOUND"
Else
response.write "NOT FOUND"
End If
Next
why dont you use a for loop:
For t = 1 to 6
If a = (FP_fieldval(fp_rs,"size" & t )) Then
Response.write "FOUND"
Else
response.write "NOT FOUND"
End If
Next
i take it by having the Do While t <> 7 it will onmly go up to 6, hence the
For t = 1 to 6 bit of the above code
For t = 1 to 6 bit of the above code
If not it looks to me like this bit must be coded wrongly if you know for sure the value is in A, what you should do is response,write all of the values of (FP_FieldVal(fp_rs,"size" & t )) and see what it gives you just to make sure that it actually is the write string and it holds the values.
Again you can do this with a for loop:
for t = 1 to 6
response.write (FP_FieldVal(fp_rs,"size" & t )) & "<BR>"
next
Again you can do this with a for loop:
for t = 1 to 6
response.write (FP_FieldVal(fp_rs,"size" & t )) & "<BR>"
next
as an addon to apresto's code, try explicitly converting them to strings to be sure you're comparing the same types, and trim them as well:
For t = 1 to 6
If cstr(trim(a)) = cstr(trim(FP_fieldval(fp_r s,"size" & t ))) Then
Response.write "FOUND"
Else
response.write "NOT FOUND"
End If
Next
peh803
For t = 1 to 6
If cstr(trim(a)) = cstr(trim(FP_fieldval(fp_r
Response.write "FOUND"
Else
response.write "NOT FOUND"
End If
Next
peh803
ASKER
I have change the code to For t = 1 as below, which still gives the same result as my if and while loop.
Although this is better than using 2 loops the result it still the same..
Both values are the same, but still it is not able to display the FOUND, thanks.
<%t = 1 %>
<%a = Request.QueryString("first ofsize")%>
<br>
A IS, <%=A%>
<BR><br>
<%For t = 1 to 6 %>
<br> <%
If a = (FP_fieldval(fp_rs,"size" & t )) Then
Response.write "*FOUND*"
Else
response.write " NOT FOUND "
End If
Next%>
Although this is better than using 2 loops the result it still the same..
Both values are the same, but still it is not able to display the FOUND, thanks.
<%t = 1 %>
<%a = Request.QueryString("first
<br>
A IS, <%=A%>
<BR><br>
<%For t = 1 to 6 %>
<br> <%
If a = (FP_fieldval(fp_rs,"size" & t )) Then
Response.write "*FOUND*"
Else
response.write " NOT FOUND "
End If
Next%>
did you try trimming and explicitly converting them to strings? (see my previous post)
peh803
peh803
>>did you try trimming and explicitly converting them to strings?
the above may be the same as this suggestion i just dont know what it means :)! Have you tried printing the values of what you are checking to the screen just to make sure that the values are in there??
Just blank everything and print them to the screen, it wont take long but could solve the problem
the above may be the same as this suggestion i just dont know what it means :)! Have you tried printing the values of what you are checking to the screen just to make sure that the values are in there??
Just blank everything and print them to the screen, it wont take long but could solve the problem
@apresto:
>>"the above may be the same as this suggestion..."
No, not the same, but thanks for the thought! Your comment / suggestion is helpful in its own right.
Regards,
peh803
>>"the above may be the same as this suggestion..."
No, not the same, but thanks for the thought! Your comment / suggestion is helpful in its own right.
Regards,
peh803
ASKER
Okay Guys.
1 I have tried the trimmings, result is the same, STILL NOT FOUND
2. I have tried printing the values, infact i had done that before just to make sure i wasn't asking a question for nothing.
The result that I got if I print the values of (FP_fieldval(fp_rs,"size" & t ) is as follows
36X36"RD
NOT FOUND
54X54"SQ
NOT FOUND
54X72"OB
NOT FOUND
72X90"OB -- it should show FOUND since this is the current value of "A"
NOT FOUND
72X108"OB
NOT FOUND
72X126"OB
NOT FOUND
1 I have tried the trimmings, result is the same, STILL NOT FOUND
2. I have tried printing the values, infact i had done that before just to make sure i wasn't asking a question for nothing.
The result that I got if I print the values of (FP_fieldval(fp_rs,"size" & t ) is as follows
36X36"RD
NOT FOUND
54X54"SQ
NOT FOUND
54X72"OB
NOT FOUND
72X90"OB -- it should show FOUND since this is the current value of "A"
NOT FOUND
72X108"OB
NOT FOUND
72X126"OB
NOT FOUND
It just occurred to me:
FP_fieldval = frontpage recordset manipulation function...?
Are you using frontpage?
FP_fieldval = frontpage recordset manipulation function...?
Are you using frontpage?
good good, just out of curiosity what does it mean if you "explicitely trim", i ask as it may come in handy when debugging
ignore that last comment, ill open a thread myself
ASKER
This was my code..
<%t = 1 %>
<%a = Request.QueryString("first ofsize")%>
<br>
A IS, <%=A%> ' just so i know what is a - it returns 72X90"OB
<BR><br>
<%For t = 1 to 6 %>
<br> <%
response.write (FP_FieldVal(fp_rs,"size" & t )) & "<BR>" - this also returns 72X90"OB after step 4
If cstr(trim(a)) = cstr(trim(FP_fieldval(fp_r s,"size" & t ))) Then
Response.write "*FOUND*"
Else
response.write " NOT FOUND "
End If
Next%>
<%t = 1 %>
<%a = Request.QueryString("first
<br>
A IS, <%=A%> ' just so i know what is a - it returns 72X90"OB
<BR><br>
<%For t = 1 to 6 %>
<br> <%
response.write (FP_FieldVal(fp_rs,"size" & t )) & "<BR>" - this also returns 72X90"OB after step 4
If cstr(trim(a)) = cstr(trim(FP_fieldval(fp_r
Response.write "*FOUND*"
Else
response.write " NOT FOUND "
End If
Next%>
try and declare a = [whatever your using now] under the foor loop but above the IF statement, i have no scientific explanation for this it may be that the scope of your A variable isnt seeing it through properly
so then, are you using frontpage?
peh803
peh803
ASKER
yes this is within a frontpage database region wizard.
@apresto:
When I was asking about explicit conversion (cstr()) and trimming the value (trim()), basically all I meant was that ricky should make sure the values the he is comparing are both of the same type as strings (for example, 1 <> "1"), and he should make sure he trims all leading or trailing spaces off his values.
peh803
When I was asking about explicit conversion (cstr()) and trimming the value (trim()), basically all I meant was that ricky should make sure the values the he is comparing are both of the same type as strings (for example, 1 <> "1"), and he should make sure he trims all leading or trailing spaces off his values.
peh803
Aah, i see to make sure that they are literally identical basically then? Right, thanks for that.
oh geez, frontpage. that's a bummer.
I hate frontpage. I'm sure you wouldn't be having this problem if this was your own ASP.
For example:
<%
Dim rs, SQL
set rs = server.createobject("ADODB .Recordset ")
SQL= "SELECT * FROM myTable"
rs.open SQL, oActiveConnection, 1, 3, 1
do while not rs.eof
response.write ("A: " & a & "<BR>")
response.write ("recordset value : " & (rs.fields("myField"))&"<B R>")
response.write ("A = recordset value? : " & (a=rs.fields("myField"))&" <BR>")
rs.movenext
loop
rs.close
set rs = nothing
%>
The only thing I haven't done here is use appropriate table / field names and I haven't created / opened the oActiveConnection.
But when you let frontpage get its ugly claws into the mix, you never know what you're gonna get...
peh803
I hate frontpage. I'm sure you wouldn't be having this problem if this was your own ASP.
For example:
<%
Dim rs, SQL
set rs = server.createobject("ADODB
SQL= "SELECT * FROM myTable"
rs.open SQL, oActiveConnection, 1, 3, 1
do while not rs.eof
response.write ("A: " & a & "<BR>")
response.write ("recordset value : " & (rs.fields("myField"))&"<B
response.write ("A = recordset value? : " & (a=rs.fields("myField"))&"
rs.movenext
loop
rs.close
set rs = nothing
%>
The only thing I haven't done here is use appropriate table / field names and I haven't created / opened the oActiveConnection.
But when you let frontpage get its ugly claws into the mix, you never know what you're gonna get...
peh803
Agreed!
@apresto:
>>i see to make sure that they are literally identical basically then
You got it!
And of course, you're welcome!
peh803
>>i see to make sure that they are literally identical basically then
You got it!
And of course, you're welcome!
peh803
ASKER
Thanks Guys.. just wondering if we could solve my issue ? Would really appreciate it..! Sorry to be bother, would just like to get to the bottom of this.. It is strange I have comapred values before but this is strange.
ASKER
Well I can't do anything about that unfortunatley, fronpage is pulling the data from the access table, and that is the way it has been set up, i wouldn't want to go in and recode it all. I am sure there must be a way since both fields are actually the same value, it just doesn't seem the compare then.. i did notice something though. when i do <%=a%> it shows 72X90"OB i notice there is a space after it when i highlight it.. don't know if that makes a difference.
Here is the actuall output page if you want to see it.
http://www.homenlinens.com/asp/tablecloth2.asp?firstofsize=72X90"OB
Here is the actuall output page if you want to see it.
http://www.homenlinens.com/asp/tablecloth2.asp?firstofsize=72X90"OB
Whats is the name of your database and table you are accessing, also if you list the fields in the table it would help. Do you know how to create a database connection using ASP(hardcoding it, not front page generated)?
Do you need the " in between 72X90 and OB, can you not replace it with another character? that may be a cause
ASKER
the name of the datbase is invoice.mdb the fields name are product id and size1, size2, size3 up to size6.
I can create a database connection without frontpage, just requires some learning i guess. But i feel the result may be the same, when i output both fields, a , and the size&t they appear to be the same. so god knows why it doesnt execute the code.
I can create a database connection without frontpage, just requires some learning i guess. But i feel the result may be the same, when i output both fields, a , and the size&t they appear to be the same. so god knows why it doesnt execute the code.
ASKER
i have tried setting a = 72X90"OB the results are also the same.
ASKER
i need the " chr since it represent inches.
ASKER
well i will look int to again.. will check back here tomm for any furthur comments. hope it helps me..
will be in touch.
tks
will be in touch.
tks
I can't think of anything else to suggest.
The fact that you're working with frontpage means that there are moving parts that we're not familiar with.
Please do let us know if you figure out what the problem was.
peh803
The fact that you're working with frontpage means that there are moving parts that we're not familiar with.
Please do let us know if you figure out what the problem was.
peh803
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tried your new code as below. but it displayed the following message
"
ADODB.Recordset error '800a0e7d'
The connection cannot be used to perform this operation. It is either closed or invalid in this context"
Dim conn
Dim srtdb
Dim strCon
Dim a
Dim Sql
Dim rs
a = request.querystring("first ofsize")
'Your database path
strdb = "/FPdb/invoice.mdb"
'Declare your database conenction variable
set conn = server.createobject("ADODB .recordset ")
'Database connection info and driver
strcon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.mappath (strdb)
'Set an active connection to the connection object
conn.open strcon
'****
set rs = server.createobject("ADODB .recordset ")
rs.open "SELECT * FROM tblProducts", conn 'change table for the name of your table in the database
For t = 1 to 6
If (rs("size" & t)) = a Then
Response.write "FOUND"
Else
Response.write "NOT FOUND"
End If
Next
Rs.close
Set rs = nothing
'****
%>
"
ADODB.Recordset error '800a0e7d'
The connection cannot be used to perform this operation. It is either closed or invalid in this context"
Dim conn
Dim srtdb
Dim strCon
Dim a
Dim Sql
Dim rs
a = request.querystring("first
'Your database path
strdb = "/FPdb/invoice.mdb"
'Declare your database conenction variable
set conn = server.createobject("ADODB
'Database connection info and driver
strcon = "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=; DBQ=" & Server.mappath (strdb)
'Set an active connection to the connection object
conn.open strcon
'****
set rs = server.createobject("ADODB
rs.open "SELECT * FROM tblProducts", conn 'change table for the name of your table in the database
For t = 1 to 6
If (rs("size" & t)) = a Then
Response.write "FOUND"
Else
Response.write "NOT FOUND"
End If
Next
Rs.close
Set rs = nothing
'****
%>
ASKER
I THINK I found the problem.
it sems that a = "72X90"OB " -- note the space after OB
AND SIZE & T = "72X90"OB" - no space after the OB
however i am using the trim function as you can see above and also i am have tried using unescape function, still the result is the same, i just have to figure out howot remove the extra space. i have even tried.
<%a = Replace(a," ","") %>
still the a still has the space afterwards... when i check the url there is no space there.
strange.
it sems that a = "72X90"OB " -- note the space after OB
AND SIZE & T = "72X90"OB" - no space after the OB
however i am using the trim function as you can see above and also i am have tried using unescape function, still the result is the same, i just have to figure out howot remove the extra space. i have even tried.
<%a = Replace(a," ","") %>
still the a still has the space afterwards... when i check the url there is no space there.
strange.
ASKER
i think this may be related problem with the' " ' i think.
https://www.experts-exchange.com/questions/21157828/How-to-compare-two-string-with-in-the-string.html
https://www.experts-exchange.com/questions/21157828/How-to-compare-two-string-with-in-the-string.html
Well you do have a couple of more avenues to explore.
my first is the try setting both values to trim and ucase ie: ucase(trim(a)) = ucase(trim(rs("size" & t))
and you can convert to string if you need to.
and the other is to go a bit further, But you'll have to go to the ascii values to truely check whys it's incorrect [Because there is more than one character reference in the ascii tables to signfy the quot.]
anyway here's some code.
Function ShowAscii( v )
dim lL: For lL = 1 to len(s)
'show the ascii value and the char representation
Response.Write asc(mid(v,lL,1)) & ":" & mid(v,lL,1) & ", "
Next
response.write "<br>"
End Function
'Show your passed value
ShowAscii a
'then in your loop
For t = 1 to 6
'Show the ascii of the recordset values
ShowAscii rs("size" & t))
If (rs("size" & t)) = a Then
Response.write "FOUND"
Else
Response.write "NOT FOUND"
End If
Next
--Try that if the one your testing, if the numbers dont equal each other you may have to do a replace on something to correct
Good Luck
CooPzZ
my first is the try setting both values to trim and ucase ie: ucase(trim(a)) = ucase(trim(rs("size" & t))
and you can convert to string if you need to.
and the other is to go a bit further, But you'll have to go to the ascii values to truely check whys it's incorrect [Because there is more than one character reference in the ascii tables to signfy the quot.]
anyway here's some code.
Function ShowAscii( v )
dim lL: For lL = 1 to len(s)
'show the ascii value and the char representation
Response.Write asc(mid(v,lL,1)) & ":" & mid(v,lL,1) & ", "
Next
response.write "<br>"
End Function
'Show your passed value
ShowAscii a
'then in your loop
For t = 1 to 6
'Show the ascii of the recordset values
ShowAscii rs("size" & t))
If (rs("size" & t)) = a Then
Response.write "FOUND"
Else
Response.write "NOT FOUND"
End If
Next
--Try that if the one your testing, if the numbers dont equal each other you may have to do a replace on something to correct
Good Luck
CooPzZ
t = 1
If a = (FP_fieldval(fp_rs,"size" & t )) Then
Do while t <> 7
have u tried it that way around, the If above the While, looking at it it makes sense but dont be surprised if i post again apologising!