add data at runtime in multiple rows in QTP/UFT - datatable

I would like to add data at runtime in multiple rows but instead it creates a new column and add data to that. I've used below code.
For i = 1 To 2 Step 1
datatable.SetCurrentRow(i)
Dim f_name,l_name
f_name=Datatable.Value("todayDate","date") + Datatable.Value("MonthName","date")
l_name=datatable.Value("This_Year","date")
Datatable.AddSheet("Emp_name").AddParameter"Emp_first_Name",f_name
Datatable.AddSheet("Emp_name").AddParameter"EMP_Last_Name",l_name
Next

AddParameter will add a new parameter each time - that's why you're seeing duplicate columns.
There's lots of ways around this - one way is to set up your table+headers before the loop then add the content with the loop.
for example:
Datatable.AddSheet("Emp_name")
Datatable.GetSheet("Emp_name").AddParameter "Emp_first_Name",""
Datatable.GetSheet("Emp_name").AddParameter "EMP_Last_Name",""
For i = 1 To 2 Step 1
datatable.SetCurrentRow(i)
Dim f_name,l_name
f_name="hello"
l_name="world"
Datatable.GetSheet("Emp_name").SetCurrentRow i
Datatable.Value("Emp_first_Name", "Emp_name") = f_name
Datatable.Value("EMP_Last_Name", "Emp_name") = l_name
Next
Output looks like this:

Related

How to check if array value exists in Cell?

I am new to vbscript and I am creating a script to reduce my day by day duplicate efforts. I have a column in an excel sheet which holds values. There are certain cells under this column where multiple values exists. Now I have an array which has some values which needs to be looked up / searched within each row under this column and delete the row if array values are not present within the row.
I tried to search the array values in the rows using InStr function and it worked if cell contains only one value. Code is attached below.
This sub is not working as expected if cell contains multiple values. e.g. Project 1 [ALT + ENTER] Dummy Project
Hence I tried to use Find and Search methods. I am unable to get the expected results using these methods too.
Fix Version/s
Row 1 - Project 3 a
Row 2 - Project 2 'spaces at the end
Row 3 - Project 4
---------
Project 1
Row 4 - Project 5
Row 5 - Project 1
Find method - No rows deleted
Replace method - Getting syntax error where I used Search method in place of InStr function as below,
If objWorksheet1.Cells(iDelCnt, fixVerColNum).Search(objWorksheet1.Cells(iDelCnt, fixVerColNum).Value, projectFilter(jDelCnt)) <> 0 Then
Please assist. Thanks in advance.
Expected - I expect row 'x' to be deleted if array value doesn't exists in Cells(x,y)
Dim objExcel, objWorkbook, objWorksheet1
Dim iDelCnt, jDelCnt, projectFilter, lRow, fixVerColNum, tempCell, deleteCounter, InStrTest
Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Visible = True
Set objWorkbook = objExcel.Workbooks.Open(filePath) ' Location of the file on drive
Set objWorksheet1 = objWorkbook.Worksheets(1)
projectFilter = Array("Project 1","Project 2", "Project 3")
fixVerColNum = objExcel.Match("Fix Version/s", objWorksheet1.Range("A1:T1"), 0) 'Identify "Fix Version(s)" column number
lRow = objWorksheet1.Range("A1").CurrentRegion.Rows.Count
deleteCounter = 0
For iDelCnt = lRow to 2 Step -1
For jDelCnt = LBound(projectFilter) to UBound(projectFilter)
If InStr(1, objWorksheet1.Cells(iDelCnt, fixVerColNum).Value, projectFilter(jDelCnt), 1) <> 0 Then
deleteCounter = 1
Exit For
Else
deleteCounter = 0
End If
Next
If deleteCounter = 0 Then
objWorksheet1.Rows(iDelCnt).EntireRow.Delete
End If
Next

How to click a particular Row in WpfCalendar of Flights Reservation Application in UFT

As per need, I want to select the Second Row from FlightsGrid Image shown below.
Applying below Code, I am getting RowCount as 6 but not able to click on 3rd Row.
Set ODesc = Description.Create
oDesc("micclass").value = "WpfTable"
Set objchild = WpfWindow("HPMyFlightSampleApplication").WpfTable("Table_FlightsGrid")
objCount = objchild.rowcount
objCount(2).click
Image from Flight Reservation Application:
The WpfTable object is not a collection, it doesn't support indexing. Did you try using its SelectRow method?
First, why are you using DP here if you are able to get row count of table.
Following two lines will give you row count of the table:
Set objchild = WpfWindow("HPMyFlightSampleApplication").WpfTable("Table_FlightsGrid")
objCount = objchild.rowcount
Second, try using its SelectRow method to select required row.
As #Motti suggested, you can use SelectRow. Or if you want to go more in depth and want to select particular cell (which will eventually select the entire row), you can use SelectCell like this way:
'Rows and Columns indexes are 0-based
iCols = WpfWindow("devname:=HPE MyFlight Sample Application").WpfTable("devname:=flightsDataGrid").ColumnCount
iRows = WpfWindow("devname:=HPE MyFlight Sample Application").WpfTable("devname:=flightsDataGrid").RowCount
sFlightNum = "12274 NW"
For i = 0 To iRows
If WpfWindow("devname:=HPE MyFlight Sample Application").WpfTable("devname:=flightsDataGrid").GetCellData(i, 4) = sFlightNum Then
WpfWindow("devname:=HPE MyFlight Sample Application").WpfTable("devname:=flightsDataGrid").SelectCell i, 4
Exit For
End If
Next
Here is the screenshot:

Lotus Notes 7 - Auto-calculation for one column from an editable view - InViewEdit event

I have a problem that gives me some headaches lately. I hope I can find a solution with your help.
I have a view : "vwTest" which is embedded on a form. It is an editable view. The view has 3 columns: Number , Cost , Difference. All the 3 columns have as their default values some field names which exist on a form called "fmTest", the field names are: Number , Cost , Difference.
On the main form ( which contains the view ) there is a field ( computed ) called: TotalValue.
The view has 2 actions: AddLine and DeleteLine.
What I want to do is:
Let say TotalValue = 5000
user complete the first line of the view:
Number | Cost | Difference
1 | 50 | 4950 => The 3rd column value to be calculated automatically as the difference between 5000 ( TotalValue ) and 50 ( the value of the 2nd column )
user complete the second line of the view:
2 | 60 | 4890 => the 3rd column value to be calculated automatically as the difference between the last 3rd column value from the view and 60 ( the current value of the 2nd column )
I think that's like a recursive algorithm.
The value of TotalValue exists, it is a Number type field.
Hope to find a solution and resolve this problem! I really appreciate your help and time!
After every save you have to cylce through all entries belonging to "this" main document and recalculate the totals. I assume, that the "lines" are response- documents to the main document and that the Embedded view is categorized by the unid of the main document...
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim viewEmbedded as NotesView
Dim viwNav as NotesViewNavigator
Dim ve as NotesViewEntry
Dim docLine as NotesDocument
Dim docMain as NotesDocument
Dim dblTotal as Double
Set db = ses.CurrentDatabase
Set docMain = ... 'somehow get the main document, therefor I would need your current code
dblTotal = docMain.TotalValue(0)
Set viewEmbedded = db.Getview( "vwTest" )
viewEmbedded.AutoUpdate = False
Set viwNav = viwEmbedded.CreateViewNavFromCategory( docMain.UniversalID )
Set ve = viwNav.getFirst()
While Not ve is Nothing
Set docLine = ve.Document
dblTotal = dblTotal - docLine.Cost(0)
If dblTotal <> docLine.Difference(0) then
docLine.Difference = dblTotal
Call docLine.Save( true, true )
End If
Set ve = viwNav.getnextDocument(ve)
Wend
Why the loop? What if someone modifies the first line after a second one and a third one have been created? then the total for 2, 3 and all subsequent lines has to change.
This code was not typed in Designer and might contain typos. It does NOT contain any error- handling and can produce Replication / Save- Conflicts if not used carefully..
Hope that helps

Lotus Notes - multiple IF formula statements

I'm new in Lotus Notes programming and I need your advices and your help.
My main form contains a table with 8 rows and 2 columns. ( there are 16 cells ) Every each cell has a numeric field. My fields name are :
txt_n1 and txt_i1 ( for 1st row )
txt_n2 and txt_i2 ( for 2nd row )
....
txt_n8 and txt_i8 ( for 8th row )
What I want to do is:
I have a view called vwMarketing with just one column. I want this view to display only those docs. in which there is at least one or more rows which its cells contains equal values.
So, if let say txt_n4 = txt_i4 => OK
row(k) (where k=1..8) : if cell 1 value is 5 and cell 2 value is 5 => OK.
There could be more than one row with this property, important is to exist at least one, and the values not to be null.
I hoped i was pretty clear, thanks !
PS: Actually, the formula statement i want to be in the column, so if it is OK => "A" and if not => "" ( in the view property, I checked : Don't show empty categories )
if you have small amount of documents in the view, then as u were suggested use Selection Formula to exclude documents with wrong condition.
you can add computed item/flag into your documents, field will compute if the document should be displayed in the view or not. then you will not have performance issue. i.e.
but code you need should look like that (that will check if documents is fine to be displayed in view or not), if you use it in view - just put after all Select _res = 1 otherwise if you decide to use flag into document (to increase performance) then Select youritem = 1
_res := 0;
#For(i:=1;i<=8;i:=i+1;
_post := #Text(i);
_txt_n := #GetField("txt_n"+_post);
_txt_i := #Text(#GetField("txt_i"+_post));
#If( (_txt_n=_txt_i) & (_txt_n!="");
#Do( _res := 1; i:=9);
0
)
);
_res
I would solve it slightly different:
Create a hidden text field on your form called 'DisplayInView' (or similar).
Modify the view selection: SELECT DisplayInView="Yes"
Add the code below to the PostSave event of your form:
Dim thisdoc As NotesDocument
Dim isSame As Boolean
isSame = False
Set thisdoc = source.Document
'*** Loop through all fields in document and compare the field pairs
Forall i In thisdoc.Items
If Left(i.Name,5) = "txt_n" Then
If i.Text = thisdoc.GetItemValue( Replace(i.Name,"txt_n","txt_i") )(0) Then
isSame = True
Exit Forall
End If
End If
End Forall
If isSame Then
Call doc.ReplaceItemValue("DisplayInView","Yes")
Call doc.Save(True,False)
End If
I haven't tested it, but I believe it should work.

Make only one row show after search in FlexGrid VB6

So i have FlexGrid in my VB6 project I'm working on. It has names on each row, and I have a drop down so the user can select what name they want to see more info for, here is what I have.
Dim target_name As String
Dim r As Integer
' Get the name.
target_name = Combo1
If Len(target_name) = 0 Then Exit Sub
' Search for the name, skipping the column heading row.
target_name = LCase$(target_name)
For r = 1 To MSFlexGrid1.Rows - 1
If LCase$(MSFlexGrid1.TextMatrix(r, 0)) = _
target_name Then
' We found the target. Select this row.
MSFlexGrid1.Row = r
MSFlexGrid1.RowSel = r
MSFlexGrid1.Col = 0
MSFlexGrid1.ColSel = MSFlexGrid1.Cols - 1
' Make the row visible.
MSFlexGrid1.TopRow = r
Exit Sub
End If
Next r
That works well, but it shows everything below that name too, I would like it to single out only the name selected.
Any help would be great.
What's the data source of your grid? You can place the filter on the data grid data source, so that as the user chooses the name from your drop down only the selected persons details are returned from the datasource to the grid.
Not exactly what you were asking, but its how I would achieve the result you are wanting.
P.S. I have used FlexGrid in VB6 and I don't know of a way to do what you are asking on the grid (might be there but I never noticed it).

Resources