VB scripting

How to check the given string is a Palindrome using VB script

MyString = Ucase (Inputbox(“Enter a String:”))

RevString =strreverse(MyString)

if strcomp (MyString, RevString)= 0 then

msgbox “Given string is a  Palindrome”

else

msgbox “Given string is not a Palindrome”

end if

How to find the alpha characters in a string.

Dim objStr

Dim objLength

Dim objChar

objStr=”1q2w3etest”

objLength=len(objStr)

alphacount=0

For i=1 to objLength

If not isnumeric (mid(objStr,i,1)) then

alphacount =alphacount+1

alphacharacter  = alphacharacter & mid(objStr,i,1)

End if

 

Next

msgbox “alpha chara count is  ” & alphacount

msgbox “alpha charaters are :   ” & alphacharacter

How to create a word document using VBscript in QTP?

Dim oWordDocument

‘ To initaiate a Word Document object

Set oWordDocument = CreateObject(“Word.Application”)

oWordDocument.Documents.Add

‘ type words on documents

oWordDocument.Selection.TypeText “This is 1st line text on word file ” & vbnewline & “This is 2nd line text on word file”

oWordDocument.ActiveDocument.SaveAs “C:\SampleWordDoc.doc”

oWordDocument.Quit

Set oWordDocument=Nothing

Leave a Reply

Your email address will not be published. Required fields are marked *