Monday, December 26, 2016

Micro Focus UFT VB Scripting Object Repository - HP_QTP-Descriptive Programming Object repository in VB Script

' VB Script Object repository for Micro Focus UFT
REM Vbs Object Repository For AUTIM
REM Version 14.0 Date:08/11/2014
REM Active - Pbwindow - SrchMainWin(Objclassname)

REM Array range Declaration
ArrayDec = 400 REM 400 is the Maximum array range.

Public Function AppMainFunc(ObjClass,ObjAliasName)

ObjName = Split(Trim(ObjAliasName),",") REM Splitting the ObjAliasName with "," Delimiter
ObjClassName = ObjName(0) REM ObjClassName - Contains the alias name

REM Splitting the Classname with "," Delimiter and assign it to AppObjType
AppObjType = Split("PbWindow,Window,PbObject,PbEdit,PbList,PbButton,PbLabel,10,winbutton,wincombobox,dialog,WinEdit,WinList,WinObject,VbWindow,ActiveX,WinRadioButton,PbEditor", ",")
REM Array Declaration for function - All the functions are stored in array
ObjFunc = Array("SrchMainWin(Objclassname)","SrchWdw(Objclassname)","SrchPbObj(Objclassname)","SrchPbEdit(Objclassname)","SrchPbList(Objclassname)","SrchPbBtn(Objclassname)","SrchPbLbl(Objclassname)","SrchWinBtn(Objclassname)","SrchWinCombx(Objclassname)","SrchWinDlg(Objclassname)","SrchWinedit(Objclassname)","SrchWinList(Objclassname)","SrchWinObject(Objclassname)","SrchVbWindow(Objclassname)","SrchActiveX(Objclassname)","SrchWinRdBtn(Objclassname)","SrchPbEditor(Objclassname)")

REM The below code will search for the "Class Name" and it will call the respective function
For i = 0 To UBound(AppObjType)
If LCase(AppObjType(i)) = LCase(Objclass) Then
Objppt = Eval(ObjFunc(i))
Exit For
End If
Next

REM Assign the Dynamic Properties
If LCase(Objppt) <> "fail" Then
For k = 1 To UBound(ObjName)
REM Splitting the ObjName with ":=" Delimiter
DyObjppt = Split(ObjName(k),":=")
REM Splitting the Objppt with "," Delimiter
PreDefObjppt = Split(Objppt,",")
Found = "false"

For i = 0 To UBound(PreDefObjppt)
REM Splitting the PreDefObjppt(i) with ":=" Delimiter
PreDefObjppt1 = Split(PreDefObjppt(i),":=")
If (LCase(Trim(PreDefObjppt1(0))) = LCase(Trim(DyObjppt(0)))) and (LCase(Trim(PreDefObjppt1(1))) <> LCase(Trim(DyObjppt(1)))) Then
PreDefObjppt1(1) = DyObjppt(1)
PreDefObjppt(i) = PreDefObjppt1(0)&":="&PreDefObjppt1(1)

Objppt = Join(PreDefObjppt,",")
Found = "true"
Exit For
End If
Next

If Found = "false" Then
Objppt = Objppt &","& ObjName(k)
End If
Next
End If

REM Creating the object
If LCase(Objppt) <> "fail" Then
Set AppObj = Description.Create
REM Splitting the Objppt with "," Delimiter
Objppt1 = Split(Objppt,",")
For i = 0 To UBound(Objppt1)
REM Splitting the Objppt1 with ":=" Delimiter
Objppt2 = Split(Objppt1(i),":=")
REM In some cases we need to add empty space in front of the value, when the property value is passed with "_" at the beginning it will be replaced with space
spaceadd = "false"
If Left(Objppt2(1),Len(Objppt2(1))-(Len(Objppt2(1))-1)) = "_" Then
Objppt2(1) = " "&Right(Objppt2(1),Len(Objppt2(1)) -1)
spaceadd = "true"
End If

REM In some cases we need to add empty space at the end of the value, when the property value is passed with "_" at the end it will be replaced with space
If Right(Objppt2(1),Len(Objppt2(1))-(Len(Objppt2(1))-1)) = "_" Then
Objppt2(1) = Left(Objppt2(1),Len(Objppt2(1)) -1)&" "
spaceadd = "true"
End If

REM In some cases we need to assign empty space to property value
pptName = Objppt2(0)
pptValue = Objppt2(1)
If Objppt2(1) = "" or Objppt2(1) = " " or spaceadd = "true" Then
pptValue = Objppt2(1)
Else
pptValue = Trim(Objppt2(1))
End If

REM In some cases we need to place ":" at the end of the property value
If UBound(Objppt2) > 1 Then
AppObj(Trim(pptName)).value = pptValue&":"
Else
AppObj(Trim(pptName)).value = pptValue
End IF
Next
Set AppMainFunc = AppObj
Else
REM Creating the object and setting it to the function AppMainFunc
Msgbox ObjClass&" - "&ObjClassName&" - NOT found in the Object Repository"
Set AppObj = Description.Create
Set AppMainFunc = AppObj
End If
End Function

REM This function (Array(1)) is to add all Pbwindow Poperties.
Public Function SrchMainWin(srchwinwdwtxt)
ReDim mwdw(ArrayDec,1)
mwdw(0,0)="MainAppWindow"
mwdw(0,1)="Class Name:=PbWindow,nativeclass:= FNWNS390,text:=Welcome.*,pbname:=w_login"

MainWindo = Checkppt(mwdw,srchwinwdwtxt)
Erase mwdw
SrchMainWin = MainWindo
End Function

REM This function (Array(2)) is to add all Window Poperties.
Public Function SrchWdw(srchwdwtxt)
ReDim swdw(ArrayDec,1)
swdw(0,0)="ACEReportDialog"
swdw(0,1)="Class Name:=Window,nativeclass:=WindowsForms10.Window.8.app.0.33c0d9d,regexpwndclass:=WindowsForms10.Window.8.app.0.33c0d9d"

Sfwdw = Checkppt(swdw,srchwdwtxt)
Erase swdw
SrchWdw= Sfwdw
End Function

REM This function (Array(3)) is to add all PbObject Poperties.
Public Function SrchPbObj(srchPbobjtxt)
ReDim sobj(ArrayDec,1)
sobj(0,0)="GroupsGroupBox"
sobj(0,1)="Class Name:=PbObject,nativeclass:=WindowsForms10.Window.8.app.0.33c0d9d,regexpwndclass:=WindowsForms10.Window.8.app.0.33c0d9d,Pbname:=GroupsGroupBox"

Sfobj = Checkppt(sobj,srchPbobjtxt)
Erase sobj
SrchPbObj = Sfobj
End Function

Public Function SrchPbEdit(srchPbedittxt)
ReDim sedit(ArrayDec,1)
sedit(0,0)="YearsToProject"
sedit(0,1)="Class Name:=PbEdit,nativeclass:=WindowsForms10.EDIT.app.0.33c0d9d,regexpwndclass:=WindowsForms10.EDIT.app.0.33c0d9d,Pbname:=YearsToProjectTextBox"

Sfedit = Checkppt(sedit,srchPbedittxt)
Erase sedit
SrchPbEdit = Sfedit
End Function


Public Function SrchPbList(srchPblsttxt)
ReDim slst(ArrayDec,1)
slst(0,0)="GroupListBox"
slst(0,1)="Class Name:=PbList,nativeclass:=WindowsForms10.LISTBOX.app.0.33c0d9d,regexpwndclass:=WindowsForms10.LISTBOX.app.0.33c0d9d,Pbname:=GroupListBox"

Sflst = Checkppt(slst,srchPblsttxt)
Erase slst
SrchPbList = Sflst
End Function

Public Function SrchPbBtn(srchtxtPbbtn)
ReDim sbtn(ArrayDec,1)
sbtn(0,0)="RunReportButton"
sbtn(0,1)="Class Name:=PbButton,nativeclass:=WindowsForms10.BUTTON.app.0.33c0d9d,regexpwndclass:=WindowsForms10.BUTTON.app.0.33c0d9d,Pbname:=btnOK,text:=&Run Report"

Sfbtn = Checkppt(sbtn,srchtxtPbbtn)
Erase sbtn
SrchPbBtn = Sfbtn
End Function

REM This function (Array(7)) is to add all PbLabel Poperties.
Public Function SrchPbLbl(srchPblbltxt)
ReDim slbl(ArrayDec,1)
slbl(0,0)="DepreciateLabel"
slbl(0,1)="Class Name:=PbLabel,Pbname:=DialogTitle,text:=Depreciate,nativeclass:=WindowsForms10.STATIC.app.0.33c0d9d"

Sflbl = Checkppt(slbl,srchPblbltxt)
Erase slbl
SrchPbLbl = Sflbl
End Function

Public Function SrchWinBtn(srchwinbtntxt)
ReDim wbtn(ArrayDec,1)
wbtn(0,0)="BCD1Next"
wbtn(0,1)="Class Name:WinButton,nativeclass:Button,regexpwndclass:Button,text:&Next >>"

Winbtn = Checkppt(wbtn,srchwinbtntxt)
Erase wbtn
SrchWinBtn = Winbtn
End Function

Public Function SrchWinCombx(srchwinCbxtxt)
ReDim wcombx(ArrayDec,1)
wcombx(0,0)="BCD1Database"
wcombx(0,1)="Class Name:WinComboBox,nativeclass:ComboBox,regexpwndclass:ComboBox,attached text:&Database:"

WinCombx = Checkppt(wcombx,srchwinCbxtxt)
Erase wcombx
SrchWinCombx = WinCombx
End Function

Public Function SrchWinDlg(dlgsrchtxt)
ReDim wdlg(ArrayDec,1)
wdlg(0,0)="BackupCompanyDialog1"
wdlg(0,1)="Class Name:Dialog,nativeclass:#32770,regexpwndclass:#32770,is owned window:True,is child window:False"

WinDlg = Checkppt(wdlg,dlgsrchtxt)
Erase wdlg
SrchWinDlg = WinDlg
End Function

Public Function SrchWinedit(wEdisrchtxt)
ReDim wEdi(ArrayDec,1)
wEdi(0,0)="BCD2FileName"
wEdi(0,1)="Class Name:WinEdit,nativeclass:Edit,regexpwndclass:Edit,attached text:File &name:"

wEdit= Checkppt(wEdi,wEdisrchtxt)
Erase wEdi
SrchWinEdit = wEdit
End Function

Public Function SrchWinList(WinLissrchtxt)
ReDim WinLis(ArrayDec,1)
WinLis(0,0)="BCD1Companies"
WinLis(0,1)="Class Name:WinList,nativeclass:ListBox,regexpwndclass:ListBox,attached text:C&ompanies:"

WList= Checkppt(WinLis,WinLissrchtxt)
Erase WinLis
SrchWinList = WList
End Function

Public Function SrchWinObject(WinObjsrchtxt)
ReDim wobj(ArrayDec,1)
wobj(0,0)="Shortcutbar"
wobj(0,1)="Class Name:WinObject,nativeclass:XTPShortcutBar,regexpwndclass:XTPShortcutBar,object class:XTPShortcutBar"

WinObj= Checkppt(wobj,WinObjsrchtxt)
Erase wobj
SrchWinObject = WinObj
End Function

Public Function SrchVbWindow(VbWindowsrchtxt)
ReDim vbWnd(ArrayDec,1)
vbWnd(0,0)="ReportVBWindow"
vbWnd(0,1)="Class Name:VbWindow,nativeclass:ThunderRT6FormDC"

VbWind= Checkppt(vbWnd,VbWindowsrchtxt)
Erase vbWnd
SrchVbWindow = VbWind
End Function

REM This function (Array(15)) is to add all ActiveX Poperties.
Public Function SrchActiveX(ActiveXsrchtxt)
ReDim ActvxObj(ArrayDec,1)
ActvxObj(0,0)="ActivexObj"
ActvxObj(0,1)="Class Name:ActiveX,nativeclass:ATL:3FED6850"

WinActive= Checkppt(ActvxObj,ActiveXsrchtxt)
Erase ActvxObj
SrchActiveX = WinActive
End Function

REM This function (Array(15)) is to add all WinRadioButton Poperties.
Public Function SrchWinRdBtn(WinRBtnsrchtxt)
ReDim WinRBtn(ArrayDec,1)
WinRBtn(0,0)="Smartpurge"
WinRBtn(0,1)="Class Name:WinRadioButton,nativeclass:Button,regexpwndclass:Button,text:&Smart purge"

WinRdBtn= Checkppt(WinRBtn,WinRBtnsrchtxt)
Erase WinRBtn
SrchWinRdBtn = WinRdBtn
End Function

REM This function (Array(17)) is to add all PbEditor Poperties.
Public Function SrchPbEditor(srchPwEdtrtxt)
ReDim sedtr(ArrayDec,1)
sedtr(0,0)= "NotesTab"
sedtr(0,1)= "Class Name:PbEditor,Pbname:NotesTextBoxAdd,regexpwndclass:WindowsForms10.EDIT.app.0.33c0d9d,nativeclass:WindowsForms10.EDIT.app.0.33c0d9d"

Sfedtr = Checkppt(sedtr,srchPbEdtrtxt)
Erase sedtr
SrchPbEditor = Sfedtr
End Function

REM Checkppt is the function to search for the Alias name in the array.
Public Function Checkppt(ValArray,srchtxt)
val =""
For i = 0 To UBound(ValArray)
If LCase(ValArray(i,0)) = LCase(srchtxt) Then
val = ValArray(i,1)
Exit For
End If
Next
REM When alias name is found it return the property for that object, else it returns fail.
If val <> "" Then
Checkppt = val
Else
Checkppt ="Fail"
End If
End Function

1 comment:

  1. Hi All, Feel free to ask Questions about the Global repository file ie., "Vbs Object Repository"-UFT_QTP-Descriptive Programming Object repository in VB Script.

    ReplyDelete