Custom Search

Thursday, December 6, 2018

How to find repeated character from given dynamic string

str="i am busy at work in my company"
str=Replace(str," ","")
For i=1 To Len(str)-1
 If Len(str)=0 Then
  Exit for
 End If
 k=Mid(str,1,1)
 If InStr(Right(str,Len(str)-1),k)>0 Then
  str2=str2&k
  str=Replace(str,k,"")
  Else
  str=Replace(str,k,"")
 End If
Next


MsgBox str2

Friday, December 19, 2014

solution for "the requested operation requires elevation" error while opening QTP through AOM

Open Regedit and go to below path

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]

change the "EnableLUA"value to 0

save and restart the system.

Thursday, May 29, 2014

Getting running applications names from task manager

Set Word = CreateObject("Word.Application")
Set Tasks = Word.Tasks
For Each Task in Tasks
   If Task.Visible Then msgbox Task.Name
Next
Word.Quit

Thursday, January 24, 2013

how to concatenate string with double quotes without using “&” or “+” and double quotes in vbscripting

Dim str(2)
str(1)="Vbscripting"

 str(0)=Chr(34)
  str(2)=Chr(34)

msgbox join(str,"")

How to split the string without using split function

str="i am busy with work"
dim strarray()
Redim preserve strarray(0)

for i = 1 to len(str)

    strchar=mid(str,i,1)
    if strchar<>" " then
        strRes=strRes & strchar
    End if
       
        If strchar=" " Then
                  strsize=ubound(strarray)
                  Redim preserve strarray(strsize+1)
                 strarray(strsize+1)=strRes
                 strRes=""
        End If

        If len(str)=i Then
                strsize=ubound(strarray)
                  Redim preserve strarray(strsize+1)
                 strarray(strsize+1)=strRes
        End If
 
Next

for i=1 to ubound(strarray)
print strarray(i)
next

Wednesday, January 16, 2013

How to swap the numbers in array like even numbers are onside and odd numbers are other side withourt using temp array


strnum=Array(7,2,5,4,9,8,10,23,12,21)

for i=0 to UBound(strnum) -1

            intre= strnum(i) mod 2
            If  intre <> 0 Then
           
                        intre1=strnum(i+1) mod 2           
                        If intre1 = 0 Then
           
                                intnumber=strnum(i)
                                strnum(i)=strnum(i+1)
                                strnum(i+1)=intnumber
                                else
                                For j=i+2 to Ubound(strnum)
                               
                                            If  strnum(j) mod 2 =0 Then
                                                        intnumber=strnum(i)
                                                        strnum(i)=strnum(j)
                                                        strnum(j)=intnumber
                                                        Exit for
                                            End If           
                                Next       
                        End if           
            End if

Next

For i=0 to Ubound(strnum)
print  strnum(i)

Next

Thursday, January 10, 2013

How to check whether any Polidrome words are there in given string without using strReverse function

msgbox CheckPalindromeString("Hi madam how is you son oho")


Function CheckPalindromeString(Str)
Dim strPlidrome ,strPlidrome_Name
strPlidrome=0
strwords=split(Str," ")
for j=0 to Ubound(strwords)

For i = Len(strwords(j)) To 1 Step -1
Str2 = Str2 + Mid(strwords(j), i, 1)
Next
If strcomp(strwords(j),Str2)=0 Then
strPlidrome=strPlidrome+1
If strPlidrome<>1Then
strPlidrome_Name=strPlidrome_Name & " , "& strwords(j)
Else
strPlidrome_Name= strwords(j)
End If
End If
Str2=""

Next
CheckPalindromeString= "Polidrome words : " & strPlidrome & " ; " & strPlidrome_Name

End Function

Wednesday, January 9, 2013

Write VbScript code to convert given numbers in to words

Print CurrencyToWord(623.32)


Function CurrencyToWord(MyNumber)
Dim Temp
Dim Rupees, Paisa
Dim DecimalPlace, iCount
Dim Hundreds, Words
ReDim Place(9)
Place(0) = " Thousand "
Place(2) = " Lakh "
Place(4) = " Crore "
Place(6) = " Arab "
Place(8) = " Kharab "
On Error Resume Next

' Convert MyNumber to a string, trimming extra spaces.
MyNumber = Trim(Str(MyNumber))
' Find decimal place.
DecimalPlace = InStr(MyNumber, ".")
' If we find decimal place...
If DecimalPlace > 0 Then
' Convert Paisa
Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
Paisa = " and " & ConvertTens(Temp) & " Paisa"
' Strip off paisa from remainder to convert.
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If

' Convert last 3 digits of MyNumber to ruppees in word.
Hundreds = ConvertHundreds(Right(MyNumber, 3))
' Strip off last three digits
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
iCount = 0
Do While MyNumber <> ""
'Strip last two digits
Temp = Right(MyNumber, 2)
If Len(MyNumber) = 1 Then
Words = ConvertDigit(Temp) & Place(iCount) & Words
MyNumber = Left(MyNumber, Len(MyNumber) - 1)
Else
Words = ConvertTens(Temp) & Place(iCount) & Words
MyNumber = Left(MyNumber, Len(MyNumber) - 2)
End If
iCount = iCount + 2
Loop
CurrencyToWord = "Ruppees " & Words & Hundreds & Paisa & " Only."
End Function


' Conversion for hundreds

'*************************************…
Private Function ConvertHundreds(MyNumber)
Dim Result
' Exit if there is nothing to convert.
If MyNumber = 0 Then Exit Function
' Append leading zeros to number.
MyNumber = Right("000" & MyNumber, 3)
' Do we have a hundreds place digit to convert?
If Left(MyNumber, 1) <> "0" Then
Result = ConvertDigit(Left(MyNumber, 1)) & " Hundreds "
End If

' Do we have a tens place digit to convert?
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & ConvertTens(Mid(MyNumber, 2))
Else
' If not, then convert the ones place digit.
Result = Result & ConvertDigit(Mid(MyNumber, 3))
End If
ConvertHundreds = Trim(Result)
End Function

' Conversion for tens
'*************************************…
Private Function ConvertTens(MyTens)
Dim Result
' Is value between 10 and 19?
If (Left(MyTens, 1)) = 1 Then
Select Case (MyTens)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else

' .. otherwise it's between 20 and 99.
Select Case (Left(MyTens, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
' Convert ones place digit.
Result = Result & ConvertDigit(Right(MyTens, 1))
End If

ConvertTens = Result
End Function

Private Function ConvertDigit( MyDigit)
Select Case (MyDigit)
Case 1: ConvertDigit = "One"
Case 2: ConvertDigit = "Two"
Case 3: ConvertDigit = "Three"
Case 4: ConvertDigit = "Four"
Case 5: ConvertDigit = "Five"
Case 6: ConvertDigit = "Six"
Case 7: ConvertDigit = "Seven"
Case 8: ConvertDigit = "Eight"
Case 9: ConvertDigit = "Nine"
Case Else: ConvertDigit = ""
End Select
End Function

Wednesday, November 21, 2012

User Defined Environment Variables vs Public Variables at Test Level

When a variable isn't declared within a function library, you may notice different things: An Environment variable declared within an action can be used by another action, but this statement does not hold true for normal variables (declared via Public, Private, Dim). Any other variable declared in one action cannot be seen in another. Private variables when declared in a function library cannot ...

Difference between Mercury DeviceReplay and Sendkeys

The Device Replay feature is used to perform mouse and keyboard actions against screen coordinates that are provided. The Device Replay functions are not automatically recorded, but must be programmed manually in the Expert View.
1. Create the Device Replay Object.
Example:
Set DeviceReplay = CreateObject(“Mercury.DeviceReplay”)

2. Call the desired Device Replay function.
Example:
DeviceReplay.SendString(“Hello, World”)

3. When done with the Device Replay object, release it.
Example:
Set DeviceReplay = Nothing

The functions that can be used with the Device Replay object are (all coodinates are relative to the top left corner of the screen):

Mercury DeviceReplay is a powerful utility to simulate keyboard input and also for simulating mouse clicks and movements. Under Java Add-in, you can find the DeviceReplay property.

We use SendKeys method to send keyboard input/keystrokes to applications that dont have automation interface. We can also send more than one keystroke at a time using Sendkeys method. To send keystrokes x,y and z, you would send the string argument "xyz".


So, the difference between Mercury DeviceReplay and Sendkeys is

SendKeys -> Support only Keyboard Operations
DeviceReplay-> Support Keyboard + Mouse Operations like Drag Drop too.


In addition to that DeviceReplay supports sending multilingual characters and symbols, while sendkeys support limited keyboard operations.


The other operational difference is dependency on QTP software.

Mercury.DeviceReplay :- It comes with QTP as a module, so you need QTP on the system and only from QTP action you can use it.
SendKeys :- It could be used in VBS script to simulate keyboard inputs with native windows shell commands. It has no dependency on QTP as such.

work with the DLL's in QTP

'Declare FindWindow method

Extern.Declare micHwnd, "FindWindow", "user32.dll", "FindWindowA", micString, micString

'Declare SetWindowText method

Extern.Declare micLong, "SetWindowText", "user32.dll", "SetWindowTextA", micHwnd, micString

'Get HWND of the Notepad window

hwnd = Extern.FindWindow("MicrosoftExcel", vbNullString)

if hwnd = 0 then

MsgBox "Notepad window not found"
else
msgbox hwnd

end if

'Change the title of the notepad window

res = Extern.SetWindowText(hwnd, "kuku")

set Off for Image capture while execution from QTP options

Rem  Using below option to uncheck ImageCapture Option
Set qtpobj=Createobject("Quicktest.application")
qtpobj.Options.Run.ImageCaptureForTestResults= "Never"
Set qtpobj=Nothing

To set automatically detect settings On/Off in IE

'Example use of IEautomaticallydetect
 IEautomaticallydetect  "off"
 IEautomaticallydetect  "show"
 IEautomaticallydetect  "on"
 IEautomaticallydetect  "show"
 
 SUB IEautomaticallydetect (status)  

 DIM sKey,sValue,binaryVal
 Dim oReg
 Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")     
 Const HKCU=&H80000001
 
 sKey = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
 sValue = "DefaultConnectionSettings"  
 oReg.GetBinaryValue HKCU, sKey, sValue, binaryVal
 
 select case lcase(status)
   case "on"    binaryVal(8) = binaryVal(8) OR 8      'Force Autodetect on
   case "off"    binaryVal(8) = binaryVal(8) XOR 8    'Force Autodetect off
   case "show" print  "Automatically detect is set to " & ((binaryVal(8) and 8) = 8)
   case else    print  "Invalid parameter - IEautomaticallydetect  on, off or show"
 end select
 
 if lcase(status)="on" or lcase(status)="off" then oReg.SetBinaryValue HKCU, sKey, sValue, binaryVal
 
 end sub

Wednesday, October 31, 2012

How to return "working" from "I am working in on office" string

str= "I am working in on office"
strsearch="working"
msgbox mid(str,instr(1,str,strsearch),Len(strsearch))

Thursday, October 25, 2012

How to get Subject and body from the Outlook mail


set olApp=createObject("Outlook.Application")
set olns=olApp.GetNameSpace("MAPI")
set objFolder=olns.GetDefaultFolder(6)
for each item1 in objFolder.items
if item1.unread then
msgbox item1.subject
msgbox item1.body
end if
next

Monday, October 22, 2012

How to Restart computer through VBScript\QTP

strComputer = "ComputerName"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
        strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    objOperatingSystem.Reboot()
Next

How to Import\Download attachment files from QC Test Plan to local Drive


LocalFilePath = "C:\Updated_Files_Form_QC_TillDate"
Set QCConnection = QCUtil.QCConnection
Set treeManager = QCConnection.TreeManager
'Specify the Quality Center path to the desired folder
QC_Path ="Subject\Automation\Regression\Library"
Set node = treeManager.nodebypath(QC_Path)
set stratt = node.attachments
For Each obj_QCAttachment In stratt.NewList("")
      Set obj_QCAttachmentStorage = obj_QCAttachment.AttachmentStorage
      obj_QCAttachmentStorage.ClientPath = LocalFilePath 'give the directory where u want to save the file
      obj_QCAttachmentStorage.Load obj_QCAttachment.Name,True
Next

Wednesday, October 3, 2012

How to find length of the string without using Len function

str="FindLength"
'Here you need to add one single character which is not existed in your string
str=FindLengthr"
'here i had added one character "r" in the last of the string
msgbox instr(1,str,"r",1)-1

OtherWay:
str="VBSCRIPTING"
i=1
do
str1=mid(str,i,1)
if str1<>"" then
i=i+1
else
exit do
end if
loop until str1=""
msgbox i-1

How to verify some text in Excel which is having large number of data

Set xl=CreateObject("Excel.Application")
xl.Workbooks.Open "C:\Test.xlsx"
Set r = xl.Range("A1:N20").Find("kamesh")
If r Is Nothing Then
xl.Cells(1,1).Value= "not found"
Else
xl.Cells(1,1).Value= "found"
End If
xl.quit
set xl=nothing