?
Solved

ASP VBScript IF Statement

Posted on 2011-03-08
12
Medium Priority
?
642 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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 look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 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