rowcount in Forloop does not update when row is deleted - vbscript

I am trying to run this code in QTP which is for deleting records from a grid. This code
dgRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
For i = 1 To dgRows
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").SelectCell i-1,0
'row of data grid begins with 0, hence i -1
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfButton("DELETE").Click
Swfwindow("PWC - [PWC]").SwfWindow("Region Master").SwfWindow("RegionMaster").SwfButton("Insert").Click
deleteCode = closePrompt()
If deleteCode = 15 Then 'closePrompt returns 15 when record is successfully deleted
i = i - 1 'As record is deleted, grid has lost one record and for loop will exit early by one record or throw error.
dgoRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
End If
Next
This piece of code runs from 1 to number of rows in a grid (dgRows).
If there are 3 rows, it will run thrice and delete records if possible. If 1 record is deleted,
the grid loses a record. Hence I am trying to adjust the value of i and dgRows by the code
i = i - 1 'As record is deleted, grid has lost one record and
for loop will exit early by one record or throw error.
dgoRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
'Updating new value of dgRows so that QTP does not click on a row for value of i that does not
exist.
I try to illustrate the issues I am facing with this piece of code
dgRows = SwfWindow("PWC - [PWC]").SwfWindow("Region
Master").SwfTable("dgMaster").RowCount
After row is deleted, it does not dynamically get the no of rows in the grid when the for loop iterates. Hence i value becomes equal to 3 rows but actually in the grid there is one row as 2 records have been deleted, thus QTP tries to click on a cell with i value 3 but doesn't find it and throws an error.
Can anyone tell me why doesn't ("dgMaster").RowCount update itself or how to update it when the for loop runs next?

In VBScript a for loop only evaluates the limit once.
Proof:
limit = 4
For i = 1 to limit
limit = limit - 1
document.write(i & " - " & limit & "<br>")
Next
Output:
1 - 3
2 - 2
3 - 1
4 - 0
You should use a While loop instead
dgRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
i = 1 ' I would use 0 but I'm keeping the code as close to original as possible
While i <= dgRows
i = i + 1
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").SelectCell i-1,0
'row of data grid begins with 0, hence i -1
SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfButton("DELETE").Click
Swfwindow("PWC - [PWC]").SwfWindow("Region Master").SwfWindow("RegionMaster").SwfButton("Insert").Click
deleteCode = closePrompt()
If deleteCode = 15 Then 'closePrompt returns 15 when record is successfully deleted
i = i - 1 'As record is deleted, grid has lost one record and for loop will exit early by one record or throw error.
dgoRows = SwfWindow("PWC - [PWC]").SwfWindow("Region Master").SwfTable("dgMaster").RowCount
End If
WEnd

Related

How to filter the max value of a column in powerquery

I´m trying to find a way to filter my (Semana) column by its MAX value, every week new data is added to my table and I just need to visualize the last week data.
I´ve tried Table.Max and List.Max but I can´t solve the problem
let
Origen = Folder.Files("D:\DOCUMENTS\Cartera"),
#"Personalizada agregada4" = Table.AddColumn(#"Tipo cambiado2", "MetaMora", each if [Días Atraso] <= 14 then 0 else [#"MORA CAP + INTS"]),
#"Filas filtradas1" = Table.SelectRows(#"Personalizada agregada4", each ([Semana] = 30)) *** I change this value manually according to the max value in the table ***
in
#"Filas filtradas1"
I need that the code automatically update the Max value from the [Semana] column.
Like this:
let
Origen = Folder.Files("D:\DOCUMENTS\Cartera"),
#"Personalizada agregada4" = Table.AddColumn(#"Tipo cambiado2", "MetaMora", each if [Días Atraso] <= 14 then 0 else [#"MORA CAP + INTS"]),
max = List.Max(#"Personalizada agregada4"[Semana]),
#"Filas filtradas1" = Table.SelectRows(#"Personalizada agregada4", each [Semana] = max)
in
#"Filas filtradas1"

Not able to select the 2nd row in a webtable usng description lanugauge in UFT

I have written the below piece of code to pick a row from web table to process it. The code picks/opens the first row successfully, however, when it is trying to double click the second row, it errors out with an error "Unspecified error". The web table has 7 rows, nevertheless, it is failing. Can some one point out what could be the reason for the failure please?
Set objDesc = Description.Create
objDesc("micclass").Value = "WebTable"
objDesc("html tag").Value = "Table"
Set objList = Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").ChildObjects(objDesc)
oCount = objList.Count
For k =0 To oCount - 1
colName = objList(k).GetRoproperty("cols")
If Trim(colName) = 21 Then 'This is the right table
objList(k).Highlight
rows= objList(k).GetROProperty("rows")
For i = 1 To rows
x = objList(k).ChildItem(i,1,"WebElement",0).GetROProperty("abs_x")
y = objList(k).ChildItem(i,1,"WebElement",0).GetROProperty("abs_y")
Wait(2)
Set obj = CreateObject("Mercury.DeviceReplay")
obj.MouseDblClick x,y,LEFT_MOUSE_BUTTON
Call ClickVerifyElement(Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").WebEdit("ben_elig_dte"), "ben_elig_dte", "WebEdit", Parameter("elig_date"))
Call ClickVerifyElement(Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").WebList("emp_state_withd_opt_decode"), "emp_state_withd_opt_decode", "WebList", Parameter("withhold_ind"))
Browser("3 - Employee Assign Benefits").Page("3 - Employee Assign Benefits").Frame("APPFRAMEWORK").WebButton("Save").Click
Next
Exit For
End If
Next

VB6 MSFlexGrid - Unable to set columns and rows count at runtime

I have a Visual Basic 6 form with a MSFlexGrid control inside, which takes data from a record set(ADODB) and displays them.
Before starting the copy of data to the FlexGrid, I'm trying to set the rows count, depending on records count. Also I have a collection which contains columns' names, then I can get the number of columns from here.
The following is a code snippet:
v_colsCount = UBound(aCols) + 2 // aCols = array with columns' names
v_regCount = rs.RecordCount // rs = my ADODB record set
myFlexGrid.Rows = 0 // for cleaning rows from a previous display
myFlexGrid.Rows = IIf(v_regCount > 0, v_regCount + 1, 2)
myFlexGrid.Cols = v_colsCount
myFlexGrid.FixedRows = 1
myFlexGrid.FixedCols = 0
There are 7532 rows and 52 columns. The problem comes when I run the application and try to execute this part of the code (fill the FlexGrid with data from the record set):
For iRow = 1 To v_regCount
For iCol = 0 To v_colsCount -2
sAux = ConvStr(rs.Fields(aCols(iCol)).Value)
myFlexGrid.TextMatrix(iRow, iCol) = sAux
I notice that
v_regCount = 7532 but v_colsCount = 2 ,
and I get an error ("Substring out of range"). If I swap the settings order (i.e. if I set myFlexGrid.Cols after set myFlexGrid.Rows), then
v_regCount = 0 and v_colsCount = 52
I don't understand why I can't set rows and columns count at the same time.
Any ideas?
Thanks in advance

UFT - AUT is a web application and UFT is not recogning the webtable rowcount at runtime after deleting rows

The rowcount remains constant, which means the Do Loop is never exited.
Does anyone have any suggestions on how to resolve this?
Do
a = Browser(browser).Page(page).WebTable("webtable").RowCount
noOfRows = a - 1
Browser(browser).Page(page).Link("Delete").Click
Loop While noOfRows > 0
you can check with for loop as follows
Dim iCount
sRow = Browser(browser).Page(page).WebTable("webtable").RowCount
for iCount = 0 To sRow-1
Browser(browser).Page(page).Link("Delete").Click
Next
It will first find no of rows on page and For loop is use to delete them.

ruby multiple loop sets but with limited rows per set

Alrightie, so I'm building an CSV file this time with ruby. The outer loop will run up to length of num_of_loops, but it runs for an entire set rather than up to the specified row. I want to change the first column of a CSV file to a new name for each row.
If I do this:
class_days = %w[Wednesday Thursday Friday]
num_of_loops = (num_of_loops / class_days.size).ceil
num_of_loops.times {
["Wednesday","Thursday","Friday"].each do |x|
data[0] = x
data[4] = classname()
# Write all to file
#
csv << data
end
}
Then the loop will run only 3 times for a 5 row request.
I'd like it to run the full 5 rows such that instead of stopping at Wed/Thurs/Fri it goes to Wed/Thurs/Fri/Wed/Thurs instead.
class_days = %w[Wednesday Thursday Friday]
num_of_loops.times do |i|
data[0] = class_days[i % class_days.size]
data[4] = classname
csv << data
end
The interesting part is here:
class_days[i % class_days.size]
We need an index into class_days that is between 0 and class_days.size - 1. We can get that with the % (modulo) operator. That operator yields the remainder after dividing i by class_days.size. This table shows how it works:
i i % 3
0 0
1 1
2 2
3 0
4 1
5 2
...
The other key part is that the times method yields indices starting with 0.

Resources