Solved

ASP VBScript IF Statement

Posted on 2011-03-08
12
624 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:garethtnash
  • 5
  • 4
  • 3
12 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 35072991
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 35073005
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
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35073050
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
 

Author Comment

by:garethtnash
ID: 35086937
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
 
LVL 32

Expert Comment

by:Big Monty
ID: 35087290
the stored procedure you have here looks good, is it not working?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35087348
Please post the code around line 26 on vacancyview.asp.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:garethtnash
ID: 35087463
<%

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
 

Author Comment

by:garethtnash
ID: 35098590
any suggestions guys?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35098978
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
 

Author Comment

by:garethtnash
ID: 35111910
Is there a way then within the SP, to only execute the SP, if @AdvertID is an int?

Thanks
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35112556
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
 

Author Closing Comment

by:garethtnash
ID: 35116836
perfect thank you
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now