how to verify sapguitree("").activeitem is available in sapguitree using uft - hp-uft

I would like to know if i can able to identify activeitem(below code) is available in SapGuiTree in SAP.
code:
SAPGuiSession("guicomponenttype:=12").SAPGuiWindow("guicomponenttype:=21").SAPGuiTree("treetype:=SapColumnTree").ActivateItem "Inbound Monitor;11.05.2016;1111;Sales Movement","Sales Movement"
i tried below method but not worked
if isNull 'code' then
else
statement
end if
Can anyone suggest any method to identy this issue
Thanks in advance.

You can achieve this by checking all the node values under a SAPGuiTree object.
'Set Object
Set TreeObj = SAPGuiSession("a").SAPGuiWindow("b").SAPGuiTree("c").Object
'First you need to get all values under this tree
Set AllValues = TreeObj.GetAllNodeKeys
'Get count
Count = AllValues.Count
'Begin search the value you want
Found = 0
For i = 0 to Count-1
NodeText = TreeObj.GetNodeTextByKey(AllValues(i))
If NodeText = "SearchValue" Then
Found = 1
Exit For
End if
Next
If Found = 1 Then
'Do something
End if
Update1:
You can also use Regular Expression to do a pattern match when searching your desired value under a tree object.

Related

VBA - SAP GUI Scripting - Active Row number

I am struggling with the code to read out the active row-number. I searched this forum (and others) and tried several things but I am not getting it running... I am doing a kind of find in my code, but then I will need the row number (actually the value of the 1st column) of the reference number I searched for.
test1 = session.FindById("wnd[0]/usr/tblSAPLV60PTCTRL_KOPIEREN").RowCount
' this returns the total number of records which is perfectly fine
test1 = session.FindById("wnd[0]/usr/tblSAPLV60PTCTRL_KOPIEREN").SetFocus
test1 = session.FindById("wnd[0]/usr/tblSAPLV60PTCTRL_KOPIEREN").CurrentRow
test1 = session.FindById("wnd[0]/usr/tblSAPLV60PTCTRL_KOPIEREN").VerticalScrollbar.Position
test1 = session.FindById("wnd[0]/usr/tblSAPLV60PTCTRL_KOPIEREN").getAbsoluteRow
test1 = session.FindById("wnd[0]/usr/tblSAPLV60PTCTRL_KOPIEREN").CurrentCellRow
getting this error message:
run-time error 438 - Reference SAP GUI scripting is enabled
Please let me know what I am missing or doing wrong.
Thanks in advance for your guidance
Flooo
As far as I am aware you cannot directly get the row number of the selected row(s).
The basic approach I use is to loop all the rows and then check if they have been selected or not, then action from there, something like:
Dim objTable as Object
Dim objRow As Object
Dim numbRows As Long
Set objTable = session.findById("wnd[0]/usr/tblSAPLCMDITCTRL_3500")
With objTable
numbRows = objTable.RowCount
For r = 0 To (numbRows - 1)
Set objRow = .GetAbsoluteRow(r)
If objRow.Selected Then
' your action here ....
End If
Next r
End With
Remember; you need to be able to handle scrolling additional pages otherwise you will get an error

Parse word document in VBScript

I got a weird mission from a friend, to parse through a bunch of Word files and write certain parts of them to a text file for further processing.
VBscript is not my cup of tea so I'm not sure how to fit the pieces together.
The documents look like this:
Header
A lot of not interesting text
Table
Header
More boring text
Table
I want to parse the documents and get all the headers and table of contents out of it. I'm stepping step through the document with
For Each wPara In wd.ActiveDocument.Paragraphs
And I think I know how to get the headers
If Left(wPara.Range.Style, Len("Heading")) = "Heading" Then
But I'm unsure of how to do the
Else if .. this paragraph belongs to a table..
So, any hint on how I could determine if a paragraph is part of a table or not would be nice.
Untested, because I have no access to MS Word right now.
Option Explicit
Dim FSO, Word, textfile, doc, para
' start Word instance, open doc ...
' start FileSystemObject instance, open textfile for output...
For Each para In doc.Paragraphs
If IsHeading(para) Or IsInTable(para) Then
SaveToFile(textfile, para)
End If
Next
Function IsHeading(para)
IsHeading = para.OutlineLevel < 10
End Function
Function IsInTable(para)
Dim p, dummy
IsInTable = False
Set p = para.Parent
' at some point p and p.Parent will both be the Word Application object
Do While p Is Not p.Parent
' dirty check: if p is a table, calling a table object method will work
On Error Resume Next
Set dummy = obj.Cell(1, 1)
If Err.Number = 0 Then
IsInTable = True
Exit Do
Else
Err.Clear
End If
On Error GoTo 0
Set p = p.Parent
Loop
End Function
Obviously SaveToFile is something you'd implement yourself.
Since "is in table" is naturally defined as "the object's parent is a table", this is a perfect situation to use recursion (deconstructed a little further):
Function IsInTable(para)
IsInTable = IsTable(para.Parent)
If Not (IsInTable Or para Is para.Parent) Then
IsInTable = IsInTable(para.Parent)
End If
End Function
Function IsTable(obj)
Dim dummy
On Error Resume Next
Set dummy = obj.Cell(1, 1)
IsTable = (Err.Number = 0)
Err.Clear
On Error GoTo 0
End Function

Ruby Search Array And Replace String

My question is, how can I search through an array and replace the string at the current index of the search without knowing what the indexed array string contains?
The code below will search through an ajax file hosted on the internet, it will find the inventory, go through each weapon in my inventory, adding the ID to a string (so I can check if that weapon has been checked before). Then it will add another value after that of the amount of times it occurs in the inventory, then after I have check all weapon in the inventory, it will go through the all of the IDs added to the string and display them along with the number (amount of occurrences). This is so I know how many of each weapon I have.
This is an example of what I have:
strList = ""
inventory.each do |inv|
amount = 1
exists = false
ids = strList.split(',')
ids.each do |ind|
if (inv['id'] == ind.split('/').first) then
exists = true
amount = ind.split('/').first.to_i
amount += 1
ind = "#{inv['id']}/#{amount.to_s}" # This doesn't seem work as expected.
end
end
if (exists == true) then
ids.push("#{inv['id']}/#{amount.to_s}")
strList = ids.join(",")
end
end
strList.split(",").each do |item|
puts "#{item.split('/').first} (#{item.split('/').last})"
end
Here is an idea of what code I expected (pseudo-code):
inventory = get_inventory()
drawn_inv = ""
loop.inventory do |inv|
if (inv['id'].occurred_before?)
inv['id'].count += 1
end
end loop
loop.inventory do |inv|
drawn_inv.add(inv['id'] + "/" + inv['id'].count)
end loop
loop.drawn_inv do |inv|
puts "#{inv}"
end loop
Any help on how to replace that line is appreciated!
EDIT: Sorry for not requiring more information on my code. I skipped the less important part at the bottom of the code and displayed commented code instead of actual code, I'll add that now.
EDIT #2: I'll update my description of what it does and what I'm expecting as a result.
EDIT #3: Added pseudo-code.
Thanks in advance,
SteTrezla
You want #each_with_index: http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-each_with_index
You may also want to look at #gsub since it takes a block. You may not need to split this string into an array at all. Basically something like strList.gsub(...){ |match| #...your block }

Excel Extracting specific text using getElements

New to vba programming and was hoping to get some help on a little program I'm having difficulty with. What I would like for this code to do is extract specific data from an element. So in this example I would like to extract the phone number for each person.
I can get the code to print all of the data in the element, but I only want to extract specified information not everything in the element. Any help would be awesome.
Set Elements = IE.Document.getElementById("member-items").getElementsByTagName("p")
'Get information
r = 0
c = 0
For Each Element In Elements
If Element.innerText Like "phone" Then
Sheet1.Range("A1").Offset(r, c).Value = Element.innerText
Debug.Print Element.innerText
r = r + 1
End If
Next Element
Okay I figured it out. I did not realize the text is CAP sensitive. So instead of using "phone" I used "Phone" with a CAP "P" and the code worked perfectly. Rockie mistake. =). Hope this helps any other newbies out there. And I used the following code instead:
For Each Element In Elements
If InStr(Element.innerText, "Phone") Then
Sheet1.Range("a1").Offset(r, c).Value = Element.innerText
Debug.Print Element.innerText
r = r + 1
End If
Next Element

Lotusscript : How to sort the field values (an array of words) by their frequency

I would like to sort the field values (strings) by their frequency in lotusscript.
Has anyone an idea to solve this?
Thanks a lot.
Personally I would avoid LotusScript if you can help it. You are going to run into limitations that cannot be worked around.
Regardless of which route you do take, from a performance point of view it is better to have the View indexes do the work.
So you would create a view. The first column would be as follows.
Column Value: The field you want to check.
Sort: Ascending
Type: Categorized
After this you can access the data using the NotesViewNavigator. The related method call is getNextCategory. This will give you a view entry object which you can call ChildCount on to get totals.
For example (Disclaimer: Code written from memory, not guaranteed to run):
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim vw As NotesView
Dim nav as NotesViewNavigator
Dim entryA As NotesViewEntry
Dim entryB As NotesViewEntry
Set db = sess.CurrentDatabase
Set vw = db.GetView("testView")
vw.AutoUpdate = False
Set nav = vw.CreateViewNav
Set entryA = nav.GetFirst
while entryA not Nothing
Set entryB = nav.GetNextCategory(entryA)
if entryB not nothing then
' Do your processing.
' entryB.childCount will give total.
end if
set EntryA = EntryB
Wend
view.AutoUpdate = True
This way the heavy lifting (string sorting, counting) is handled by the View index. So you only need to process the final results.
To answer the op's (old) question directly, the way to do this in LotusScript is both simple and easy:
dim para as string
dim words as variant
dim fq list as long
'get the text to freq-count
para = doc.text '(or $ from somewhere)
'tidy up para by removing/replacing characters you don't want
para = replace(para, split(". , : ; - [ ] ()"), "")
words = split(para) 'or split(words, "delim") - default is space
forall w in words
if iselement(words(w)) then
fq(w) = fq(w) + 1
Else
fq(w) = 1
End forall
'you now have a count of each individual word in the FQ list
'to get the words out and the word frequencies (not sorted):
forall x in fq
print listtag(x) = x
End forall
Thats it. No issue with LotusScript - quick and easy (and lists can be massive). To get a sorted list, you would have to move to an array and do a sort on it or move to a field and let #sort do the job somehow.

Resources