Solved

ASP VBScript IF Statement

Posted on 2011-03-08
12
630 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 33

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 33

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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 33

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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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