Forum Moderators: open

Message Too Old, No Replies

Matching a text string in ASP

God knows why it isn't working!

         

bateman_ap

4:51 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, working on some geo targetting, have done the hard work converting the ip to a number, looking it up against the database I created from a free csv file and returning the country the user is in as a 3 letter code (ie GBR). So I thought the trouble was over! However having a hell of a time getting the IF statement to work in my asp. Currently I have something below as a start to test, obviopusly when it is working can set it to do all sorts but it just won't recognise the GBR.

The Response.Write for check_country correctly returns GBR but the Response.Write for clickhere is returning the Test Bust value. Not what I want!

It is obviously something simple but I have been kicking myself!

<%
check_country = (RsLoc.Fields("COUNTRY_CODE3").value)

IF check_country = "GBR" THEN
clickhere = "Test"
ELSE
clickhere = "Test Bust!"
END IF

Response.Write (check_country)
Response.Write (clickhere)
%>

txbakers

6:04 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it's a stupid thing, but I run into it all the time. In java (not script) you can't use the "==" comparison for string variables, you need to use the ".equals" instead.

In ASP I've found the same holds true sometimes. What we think are strings aren't brought in as strings.

So......try this:

check_country = cstr((RsLoc.Fields("COUNTRY_CODE3").value) )

It just might work.

bateman_ap

6:12 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Afraid not. It is madness, it displays it as GBR in the code, it jsut won't match it!

bateman_ap

6:16 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Grrrr, solved it, I first put it through
check_country = Trim((RsLoc.Fields("COUNTRY_CODE3").value))

The database must have introduced some spaces in it.

Thanks!

txbakers

7:51 pm on Sep 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the TRIM function is my favorite vb function.

I use AS/400 a lot and if the field says 15 characters, you get 15 characters - even though 12 might be blank, so I use trim everywhere.