ASP VBScript IF Statement

Hello Experts,

I need to put together an If statement that only operates the next function / code IF -

IF HTTP_USER_AGENT NOT LIKE '%Google%'
AND HTTP_USER_AGENT NOT LIKE '%google%'
AND HTTP_USER_AGENT NOT LIKE '%slurp%'
AND HTTP_USER_AGENT NOT LIKE '%twiceler%'
AND HTTP_USER_AGENT NOT LIKE '%msnbot%'
AND HTTP_USER_AGENT NOT LIKE '%inspyder%'
AND HTTP_USER_AGENT NOT LIKE '%baidu%'
AND HTTP_USER_AGENT NOT LIKE '%BDFetch%'
AND HTTP_USER_AGENT NOT LIKE '%bdbrandprotect%'
AND HTTP_USER_AGENT NOT LIKE '%Feed%'
AND HTTP_USER_AGENT NOT LIKE '%jobcrawler%'
AND HTTP_USER_AGENT NOT LIKE '%wise-guys%'
AND HTTP_USER_AGENT NOT LIKE '%tesco%'
AND HTTP_USER_AGENT NOT LIKE '%Wanadoo%'
AND HTTP_USER_AGENT NOT LIKE '%eSobiSubscriber%'
AND HTTP_USER_AGENT NOT LIKE '%Jeeves%'
AND HTTP_USER_AGENT NOT LIKE '%Jobrapido%'
AND HTTP_USER_AGENT NOT LIKE '%spbot%'
AND HTTP_USER_AGENT NOT LIKE '%trovitBot%'
AND HTTP_USER_AGENT NOT LIKE '%twiceler%'
AND HTTP_USER_AGENT NOT LIKE '%oodlebot%'
AND HTTP_USER_AGENT NOT LIKE '%Pingdom%'
AND HTTP_USER_AGENT NOT LIKE '%PostRank%'
AND HTTP_USER_AGENT NOT LIKE '%R6_FeedFetcher%'
AND HTTP_USER_AGENT NOT LIKE '%TwitterFeed%'
AND HTTP_USER_AGENT NOT LIKE '%Wget%'
AND HTTP_USER_AGENT NOT LIKE '%Yandex%'
AND HTTP_USER_AGENT NOT LIKE '%SimpleFeed%'  
AND HTTP_USER_AGENT IS NOT NULL)

Please advise best way of doing this

Thank you
garethtnashAsked:
Who is Participating?
 
wdosanjosCommented:
I think the check should be on the ASP.NET code as follows:

<%

Dim CMDVacancyView__AdvertID
CMDVacancyView__AdvertID = "0"
if(Request("i") <> "") then CMDVacancyView__AdvertID = Request("i")
if(Request("ID") <> "") then CMDVacancyView__AdvertID = Request("ID")

Dim CMDVacancyView__SiteID
CMDVacancyView__SiteID = "0"
if(Session("SITEID") <> "") then CMDVacancyView__SiteID = Session("SITEID")

Dim CMDVacancyView__agent
CMDVacancyView__agent = "0"
if(Request.ServerVariables("HTTP_USER_AGENT") <> "") then CMDVacancyView__agent = Request.ServerVariables("HTTP_USER_AGENT")

%>
<%
If IsNumeric(CMDVacancyView__AdvertID) And IsNumeric(CMDVacancyView__SiteID) Then
    set CMDVacancyView = Server.CreateObject("ADODB.Command")
    CMDVacancyView.ActiveConnection = MM_recruta2_STRING
    CMDVacancyView.CommandText = "dbo.usp_AdvertViews"
    CMDVacancyView.CommandType = 4
    CMDVacancyView.CommandTimeout = 0
    CMDVacancyView.Prepared = true
    CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@RETURN_VALUE", 3, 4)
    CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@AdvertID", 3, 1,4,CMDVacancyView__AdvertID)
    CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@SiteID", 3, 1,4,CMDVacancyView__SiteID)
    CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@agent", 200, 1,1000,CMDVacancyView__agent)
    CMDVacancyView.Execute()
End If
%>

Open in new window

0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
might be better to put this into a stored procedure and then return 1 if all of the conditions are met and 0 if they aren't. if you still want to go with the IF statement, here it is:

IF InStr( UCase( HTTP_USER_AGENT ) , "GOOGLE" ) > 0
AND InStr( UCase( HTTP_USER_AGENT ) "SLURP" ) > 0  
AND InStr( UCase( HTTP_USER_AGENT ) "TWICELER" ) > 0  
....rest of if conditions

the above code assumes the variable HTTP_USER_AGENT has been populated correctly
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
forgot the last condition:

IF InStr( UCase( HTTP_USER_AGENT ) , "GOOGLE" ) > 0
AND InStr( UCase( HTTP_USER_AGENT ) "SLURP" ) > 0  
AND InStr( UCase( HTTP_USER_AGENT ) "TWICELER" ) > 0  
....rest of if conditions
AND not isNull( HTTP_USER_AGENT )
AND HTTP_USER_AGENT <> "" then
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wdosanjosCommented:
You can try this: (uses a regular expression)

Set regEx = New RegExp
regEx.Pattern = "(google)|(slurp)|(twiceler)|(msnbot)|(inspyder)|(baidu)|(bdfetch)|(bdbrandprotect)|(feed)|(jobcrawler)|(wise-guys)|(tesco)|(wanadoo)|(esobisubscriber)|(jeeves)|(jobrapido)|(spbot)|(trovitbot)|(twiceler)|(oodlebot)|(pingdom)|(postrank)|(r6_feedfetcher)|(twitterfeed)|(wget)|(yandex)|(simplefeed)"
regEx.IgnoreCase = True

' Do the search test.
If Not IsNull(HTTP_USER_AGENT) And Not regEx.Test(HTTP_USER_AGENT) Then
    MsgBox(HTTP_USER_AGENT & " is valid")
End If

Open in new window

0
 
garethtnashAuthor Commented:
Hello Both,

thanks for your replies, as it stands currently I have a page that processes the stored procedure highlighted in the code view area....

However my reason for wanting to build a VBScript IF statement, is because currently I get lots of errors that read

"File Name: /scripts/vacancyview.asp
Line Number: 26
Description: Application uses a value of the wrong type for the current operation."

These errors appear to happen when the HTTP User Agent contains one of the User Agents on the NOT list like "HTTP User Agent: Mozilla/4.0 (compatible;  Vagabondo/4.0; webcrawler at wise-guys dot nl; " (wise-guys)

So the only solution that I can see to get around this, is to write an IF statement that only processes the code that call the stored procedure (code on /scripts/vacancyview.asp) if the HTTP User Agent Not like those on the list...

Would the solutions above be the best route? please can you advise how to call these?

Thank you
USE [xxxxxxx]
GO
/****** Object:  StoredProcedure [dbo].[usp_AdvertViews]    Script Date: 03/09/2011 19:46:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[usp_AdvertViews] 
@AdvertID int,
@SiteID int,
@agent nvarchar(1000)
 AS
DECLARE @views int;
 
IF (
@agent NOT LIKE '%Google%' 
AND @agent NOT LIKE '%google%' 
AND @agent NOT LIKE '%slurp%' 
AND @agent NOT LIKE '%twiceler%' 
AND @agent NOT LIKE '%msnbot%' 
AND @agent NOT LIKE '%inspyder%' 
AND @agent NOT LIKE '%baidu%' 
AND @agent NOT LIKE '%BDFetch%' 
AND @agent NOT LIKE '%bdbrandprotect%' 
AND @agent NOT LIKE '%Feed%' 
AND @agent NOT LIKE '%jobcrawler%' 
AND @agent NOT LIKE '%wise-guys%' 
AND @agent NOT LIKE '%tesco%' 
AND @agent NOT LIKE '%Wanadoo%' 
AND @agent NOT LIKE '%eSobiSubscriber%' 
AND @agent NOT LIKE '%Jeeves%' 
AND @agent NOT LIKE '%Jobrapido%' 
AND @agent NOT LIKE '%spbot%' 
AND @agent NOT LIKE '%trovitBot%' 
AND @agent NOT LIKE '%twiceler%' 
AND @agent NOT LIKE '%oodlebot%' 
AND @agent NOT LIKE '%Pingdom%' 
AND @agent NOT LIKE '%PostRank%' 
AND @agent NOT LIKE '%R6_FeedFetcher%'
AND @agent NOT LIKE '%TwitterFeed%'
AND @agent NOT LIKE '%Wget%'
AND @agent NOT LIKE '%Yandex%'
AND @agent NOT LIKE '%SimpleFeed%'   
AND @agent IS NOT NULL) 
BEGIN
SELECT @views=SUM(AdViews) +1
            FROM dbo.JBADView
            WHERE AdvertID = @AdvertID;
 
IF (@views IS NOT NULL)
    UPDATE dbo.JBADView
    SET AdViews = @views
    Where AdvertID = @AdvertID
ELSE 
   INSERT INTO dbo.JBADView(AdvertID, SiteID, AdViews)
       VALUES(@AdvertID, @SiteID, 1)
END
GO

Open in new window

0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
the stored procedure you have here looks good, is it not working?
0
 
wdosanjosCommented:
Please post the code around line 26 on vacancyview.asp.
0
 
garethtnashAuthor Commented:
<%

Dim CMDVacancyView__AdvertID
CMDVacancyView__AdvertID = "0"
if(Request("i") <> "") then CMDVacancyView__AdvertID = Request("i")
if(Request("ID") <> "") then CMDVacancyView__AdvertID = Request("ID")

Dim CMDVacancyView__SiteID
CMDVacancyView__SiteID = "0"
if(Session("SITEID") <> "") then CMDVacancyView__SiteID = Session("SITEID")

Dim CMDVacancyView__agent
CMDVacancyView__agent = "0"
if(Request.ServerVariables("HTTP_USER_AGENT") <> "") then CMDVacancyView__agent = Request.ServerVariables("HTTP_USER_AGENT")

%>
<%

set CMDVacancyView = Server.CreateObject("ADODB.Command")
CMDVacancyView.ActiveConnection = MM_recruta2_STRING
CMDVacancyView.CommandText = "dbo.usp_AdvertViews"
CMDVacancyView.CommandType = 4
CMDVacancyView.CommandTimeout = 0
CMDVacancyView.Prepared = true
CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@RETURN_VALUE", 3, 4)
CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@AdvertID", 3, 1,4,CMDVacancyView__AdvertID)
CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@SiteID", 3, 1,4,CMDVacancyView__SiteID)
CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@agent", 200, 1,1000,CMDVacancyView__agent)
CMDVacancyView.Execute()

%>


Line 26 being --

CMDVacancyView.Parameters.Append CMDVacancyView.CreateParameter("@AdvertID", 3, 1,4,CMDVacancyView__AdvertID)


Thanks
0
 
garethtnashAuthor Commented:
any suggestions guys?
0
 
wdosanjosCommented:
The problem is with CMDVacancyView__AdvertID (@AdvertID) not CMDVacancyView__agent (@agent).  Since @AdvertID is an int, most likely there are cases when Request("ID") or Request("i") is not numeric. Thus causing the error you reported.

Please check what values are coming in for Request("ID") and Request("i") when the error occurs.  Maybe trimming spaces is all that's needed.
0
 
garethtnashAuthor Commented:
Is there a way then within the SP, to only execute the SP, if @AdvertID is an int?

Thanks
0
 
garethtnashAuthor Commented:
perfect thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.