Saturday 8 June 2013

Validating an IP address using vb script

The following VB Script shows how can you validate an IP address by using vb scripting. Just copy and paste in a notepad and save it as .vbs file and then run this.

This script may be used in automation scripts where you want the user to enter an IP address to proceed with the test case.



' ------------------------ Functions/Subroutines --------------------
function is_ip(ip_adress)
  is_ip = True
  ' split string into list
  ip_adress_lst = split(ip_adress,".")
  ' if number of IP adress parts is 4
  if uBound(ip_adress_lst) = 3 then
    ' validate if every IP part is numeric
    for each ip_part in ip_adress_lst
      if not isNumeric(ip_part) then
        is_ip = False
        exit for
      end if
    next
  else
    ' if number of IP adress parts is not 4
    is_ip = False
  end if
end function

sub EnterIP
  'textbox for entering value
  UserIP = inputbox( "Please Enter the IP Address you wish to" )
  'if cancel is pressed
  if UserIP = "" then
MsgBox("No Input, Closing the Tool")
    wscript.quit
  end if

  if not is_ip (UserIP) then
    wscript.echo "This needs to be an IP address like 1.1.1.1"
    call EnterIP
  else
    wscript.echo "This is the IP-address submitted by you - '" & UserIP & "'"
  end if
end sub
Do
' now calling the subroutine
call EnterIP

Thursday 6 June 2013

VB Script to open a webpage


Dim objIE

objIE = CreateObject("Internetexplorer.Application")
objIE.Visible = 1 
objIE.Navigate ("www.google.com")


Defect Life Cycle in Agile World

Oliver Lloyd

Using VB Scripting to send a mail from your outlook



This is one of the easiest way to automate email sending through outlook using VB Script.

Pre-Requsite:
1. Keep your outlook open.
2. Provide the file location in the script

Here goes the VB Script

Dim outobj,mailobj
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
With mailobj
.To = ToEmailID
.Subject = "Any Subject you like"
.Body = ""
.Attachments.Add " C:\testfile.txt"
  .Send
End With