Loading
Showing posts with label ASP VB Script. Show all posts
Showing posts with label ASP VB Script. Show all posts

Wednesday, April 7, 2010

ASP VB Script - Determine Morning or Afternoon

' ASP Determine Morning or Afternoon
<%

dim intHourOfDay
intHourOfDay = hour(now())
if intHourOfDay < 12 then
    Response.Write("Good Morning World!<br><br>The hour of the day is ") & intHourOfDay
else
    Response.Write("Good Afternoon World!<br><br>The hour of the day is ") & intHourOfDay
end if
%>

ASP VB Script - Get Server System Directory

sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")

ASP VB Script - Function to Check Valid Email Address

<% 
' Function IsEmailValid(strEmail) 
' Action: checks if an email is correct. 
' Parameter: strEmail - the Email address 
' Returned value: on success it returns True, else False. 
Function IsEmailValid(strEmail) 
  
    Dim strArray 
    Dim strItem 
    Dim i 
    Dim c 
    Dim blnIsItValid 
  
    ' assume the email address is correct  
    blnIsItValid = True 
    
    ' split the email address in two parts: name@domain.ext 
    strArray = Split(strEmail, "@") 
  
    ' if there are more or less than two parts  
    If UBound(strArray) <> 1 Then 
        blnIsItValid = False 
        IsEmailValid = blnIsItValid 
        Exit Function 
    End If 
  
    ' check each part 
    For Each strItem In strArray 
        ' no part can be void 
        If Len(strItem) <= 0 Then 
            blnIsItValid = False 
            IsEmailValid = blnIsItValid 
            Exit Function 
        End If 
        
        ' check each character of the part 
        ' only following "abcdefghijklmnopqrstuvwxyz_-." 
        ' characters and the ten digits are allowed 
        For i = 1 To Len(strItem) 
               c = LCase(Mid(strItem, i, 1)) 
               ' if there is an illegal character in the part 
               If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then 
                   blnIsItValid = False 
                   IsEmailValid = blnIsItValid 
                   Exit Function 
               End If 
        Next 
   
      ' the first and the last character in the part cannot be . (dot) 
        If Left(strItem, 1) = "." Or Right(strItem, 1) = "." Then 
           blnIsItValid = False 
           IsEmailValid = blnIsItValid 
           Exit Function 
        End If 
    Next 
  
    ' the second part (domain.ext) must contain a . (dot) 
    If InStr(strArray(1), ".") <= 0 Then 
        blnIsItValid = False 
        IsEmailValid = blnIsItValid 
        Exit Function 
    End If 
  
    ' check the length oh the extension  
    i = Len(strArray(1)) - InStrRev(strArray(1), ".") 
    ' the length of the extension can be only 2, 3, or 4 
    ' to cover the new "info" extension 
    If i <> 2 And i <> 3 And i <> 4 Then 
        blnIsItValid = False 
        IsEmailValid = blnIsItValid 
        Exit Function 
    End If

    ' after . (dot) cannot follow a . (dot) 
    If InStr(strEmail, "..") > 0 Then 
        blnIsItValid = False 
        IsEmailValid = blnIsItValid 
        Exit Function 
    End If 
  
    ' finally it's OK  
    IsEmailValid = blnIsItValid 
    
 End Function 
%>

ASP VB Script - Auto Refresh Page

Refresh every 10 seconds within a page
<% 

    Response.AddHeader "Refresh", "10" 'Seconds
%>
     

Refresh every 5 seconds and redirect to a given link.

<% 
    Response.AddHeader "Refresh", "5;URL=www.google.com"  '5 Seconds    
%>