QTP Scripts to make life easy..

Normalizing Strings

The NormalizeString function receives a string and returns the equivalent string in a regular expression.

Function NormalizeString(OrgStr)

Dim TempStr

TempStr = Replace(OrgStr, "\", "\\")

TempStr = Replace(TempStr, "*", "\*")

TempStr = Replace(TempStr, "+", "\+")

TempStr = Replace(TempStr, ".", "\.")

NormalizeString = Replace(TempStr, "?", "\?")

End function

msgbox NormalizeString ("a+b*c.d?e")

Using Message Boxes That Close Automatically

The function below shows a message box that disappears after the specified timeout (in seconds). The script execution then continues.

Public Sub MsgBoxTimeout (Text, Title, TimeOut)

Set WshShell = CreateObject("WScript.Shell")

WshShell.Popup Text, TimeOut, Title

End Sub

If TimeOut is 0, it behaves just like a normal message box. If TimeOut is greater than 0, the dialog box disappears after the specified number of seconds.


Using Microsoft Outlook to Send Email

The code below illustrates two methods for sending email using the VBScript code in QuickTest Professional, and two different COM objects. The following examples can be found in SendingEmail.vbs file located in the \CodeSamplesPlus folder.

' Example 1

Function SendMail(SendTo, Subject, Body, Attachment)

Set ol=CreateObject("Outlook.Application")

Set Mail=ol.CreateItem(0)

Mail.to=SendTo

Mail.Subject=Subject

Mail.Body=Body

If (Attachment <> "") Then

Mail.Attachments.Add(Attachment)

End If

Mail.Send

ol.Quit

Set Mail = Nothing

Set ol = Nothing

End Function

' Example 2

Function SendMail(SendFrom, SendTo, Subject, Body)

Set objMail=CreateObject("CDONTS.Newmail")

ObjMail.From = SendFrom

ObjMail.To = SendTo

ObjMail.Subject = Subject

ObjMail.Body = Body

ObjMail.Send

Set objMail = Nothing

End Function



Comments

Popular posts from this blog

Overall QuickTest Workflow