Pages

Thursday, January 9

How to download a file from a url using vbscript/QTP

Hello Friends!!

In this post, we will see how to download a file from url/internet to your local drive.

' Path of the file you want to download

strFileUrl = "http://abc.com/results/myfile01.zip"

'Local drive's path where you want to save the file
strSaveFileTo = "C:\xxxxxxx\yyyyyyyyy\\xyz.zip"


' create a XMLHTTP object

Set oHTTP = CreateObject("MSXML2.XMLHTTP")

oHTTP.open "GET", strFileUrl, False
oHTTP.send

'create FSO object
Set oFSO = CreateObject("Scripting.FileSystemObject")

'If  strSaveFileTo file already exist, delete it
If oFSO.FileExists(strSaveFileTo) Then
  oFSO.DeleteFile(strSaveFileTo)
End If

If oHTTP.Status = 200 Then
  Dim oADOStream
  Set oADOStream = CreateObject("ADODB.Stream")
  With oADOStream
    .Type = 1
    .Open
    .Write oHTTP.ResponseBody
    .SaveToFile strSaveFileTo
    .Close
  End With
  set oADOStream = Nothing
End If

If oFSO.FileExists(strSaveFileTo) Then
  Print "File has been downloaded successfully and save to  " & strSaveFileTo
End If


Above code will save any file to your loacal drive at the given path. Now if the file is a ZIP file, you will need to extract it.


Below code will help you to pick any file from local and extract it's content to given folder



'Local drive's path where you want to Extract the file (in case file is a ZIP file)

strExtractFileTo="C:\MyFilePath\"


'If tstrExtractFileTo path does not exist on local drive, create it
Set oFSO = CreateObject("Scripting.FileSystemObject")

If NOT oFSO.FolderExists(strExtractFileTo) Then
   oFSO.CreateFolder(strExtractFileTo)
End If

'Extract the contants of the zip file.

Set oShell = CreateObject("Shell.Application")
Set strZIPFiles=oShell.NameSpace(strSaveFileTo).items
oShell.NameSpace(strExtractFileTo).CopyHere(strZIPFiles)

'release objects
Set oFSO = Nothing
Set oShell = Nothing


Monday, November 11

How to prepare for PMP exam based on PMBOK 5! - Part-2

Hello Friends,

This post is Part-2 of the series of posts - How to prepare for PMP exam based on PMBOK 5!

Click here for Part-1.

In Part-1, we looked into following points-

1. Pre-requisites - Things you must be prepared for before you head towards PMP direction
2. Study Resources - Books and other resources I found most useful
3. Study Plan - Strategic steps, resources and tips for preparation and clear the exam!!

In this part (Part-2) of this post we will discuss more about the content, topics and areas that are most important and preparation strategy for the exam!!

Alright! I'll start with a very important point I've observed and might be quite helpful for you as well.







Look at the above table. Have you noticed that-

23 processes (in green) have 76% weightage in the exam and
24 processes (in orange) have only 24% weightage.

So, by preparing 23 processes, you can cover 76% of the exam!! :)


Needless to say that mastering 23 processes with all ITTOs is much easier then mastering all 47 :)


How about that?


to be continued....


Wednesday, November 6

Send Outlook Email (with text formatting) using QTP

Hello Friends!!

In this post we will quickly see how to send an outlook email.
I know, most of you all know how to send email using QTP, then why this post??

Well, here we will see how to use HTML code to format your email's body i.e. text style, font color, formatting etc. Here we go!!

Dim oOutlook, oEmail, vEmailTo, vEmailCC, vEmailBCC

vEmailTo = "catchall1@email.com"    'replace  this with your email id
vEmailCC = "catchall2@email.com"
vEmailBCC = "catchall3@email.com"
vEmailSubject = "Test Email from QTPschool.com"

Set oOutlook = CreateObject("Outlook.Application")
Set oEmail = oOutlook.CreateItem(0)

oEmail.To = vEmailTo
oEmail.CC = vEmailCC
oEmail.BCC = vEmailBCC
oEmail.Subject = vEmailSubject

oEmail.HTMLBody = "<HTML>"&_
"<Body>"&_
"<p Style=""background-color:red""><b>This text is bold and red background</b></p>"&_
"<p><strong>This text is strong</strong></p>"&_
"<p><em>This text is emphasized</em></p>"&_
"<p><Font color=""green""<i>This text is green and italic</Font></i></p>"&_
"<p><Font color=""red"" size = 16><small>This text is red and big!</small></Font></p>"&_
"<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>"&_
"</Body>"&_
"</HTML>"

wait 2
oEmail.Send
wait 2

Set oEmail = Nothing
Set oOutlook = Nothing


'For more details on HTML code, please visit http://www.w3schools.com/html/html_formatting.asp

In case of any queries, please post your comments. Happy QTPing!!