How to click on webtable specific row - hp-uft

I have this code that clicks on first row and column one just fine.
Set oExcptnDetail = Description.Create
oExcptnDetail("micclass").value = "WebElement"
oExcptnDetail("html tag").value = "TD"
Set chobj=Browser("").Page("").WebTable("Code").ChildObjects(oExcptnDetail)
chobj(0).Click
How can I click on a specific row using above code?
I used childitem that did not work.
set objLink = Browser("bb").Page("bb").WebTable("Name_2").ChildItem(4, 1, "WebElement",0)
Update 1
I tried the below code. It did not click row 3 col 1.
Set desc = Description.Create
desc("html tag").value = "TR"
Set rows = table.ChildObjects(desc)
desc("html tag").value = "TD"
Set cells = rows(3).ChildObjects(desc)
Set TableCell = cells(1)
Browser("").Page("").WebTable(TableCell).Click

UFT's ChildItem function returns elements contained within cells, this means that it won't return the TD that is the cell, only its descendants.
In order to get the cell itself you should use WebTable.Cell, this is a relatively new functionality in UFT and you may not have it. If you don't you should be able to write a helper function like this (note I'm writing this without checking it out, it may need additional work and error handling):
Function TableCell(table, nRow, nCol)
Set desc = Description.Create
desc("html tag").value = "TR" ' Or "T[RH]" to capture TH too
Set rows = table.ChildObjects(desc)
desc("html tag").value = "TD"
Set cells = rows(nRow).ChildObjects(desc)
Set TableCell = cells(nCol)
End Function
Then you can use RegisterUserFunc to use it as WebTable.Cell if you wish.
Then you can use it thus:
TableCell(Browser("").Page("").WebTable("Code"), 4, 1).Click
Or if you used RegisterUserFunc to register it as Cell:
Browser("").Page("").WebTable("Code").Cell(4, 1).Click

Related

Show multiple buttons in Data grid view

I needed to add two buttons inside a single column in data grid view in Visual Foxpro, , but only one active appears in the column.
the two buttons could be shown in each cell of that column.
Is it possible to show both buttons?
I needed to add two buttons inside a single column in data grid [...] Is it possible to show both buttons?
Yes, you can put a Container object into the Grid.Column and put two Buttons into the Container. Minimal, Reproducible Example:
LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN
DEFINE CLASS TestForm as Form
AutoCenter = .T.
PROCEDURE Load
LOCAL i
CREATE CURSOR temp (test Int)
FOR i = 1 TO 10
INSERT INTO temp VALUES (i)
ENDFOR
GO TOP
ENDPROC
ADD OBJECT Grid1 as Grid WITH ;
RecordSource = 'temp', ColumnCount = 1, RowHeight = 30
PROCEDURE Grid1.Init()
WITH This.Column1
.Width = 200
.AddObject('Container1','TestContainer')
.Container1.Visible = .T.
.CurrentControl = 'Container1'
.Sparse = .F.
ENDWITH
ENDPROC
ENDDEFINE
DEFINE CLASS TestContainer as Container
Width = 200
Height = 27
ADD OBJECT Button1 as CommandButton WITH ;
Height = 24, Caption = "Button1"
PROCEDURE Button1.Click
MESSAGEBOX(This.Caption)
ENDPROC
ADD OBJECT Button2 as CommandButton WITH ;
Height = 24, Left = 100, Caption = "Button2"
PROCEDURE Button2.Click
MESSAGEBOX(This.Caption)
ENDPROC
ENDDEFINE

Unable to allow row selection on click over mshflexgrid control in vb6

The form that has mshflexgrid control is not allowing to select the row on which the mouse click has done. Sometimes it allows selection of previous row and not the row which is been clicked
I have tried adding one to the property .RowSel of mshflexgrid to allow the row selection, it is not working for second row selection.
Private Sub MSHFlexGrid1_Click()
last_row_selected = MSHFlexGrid1.RowSel
If last_row_selected <> 1 Then last_row_selected = last_row_selected + 1
With MSHFlexGrid1
If (boolShift And vbShiftMask) = vbShiftMask Then
SelectionOneAfterTheOther
ElseIf (boolShift And vbCtrlMask) = vbCtrlMask Then
SelectUnSelectGridRow
Else
UnSelectAllGridRows
.Row = last_row_selected
.ColSel = .Cols - 1
.CellBackColor = vbHighlight
.CellForeColor = vbHighlightText
End If
End With
MSHFlexGrid1.Refresh
End Sub
It seems that the .RowSel property isn't taking correct value for selection of row
The result needs to be proper selection of row on which it is clicked.
In your grid Click event, try something like this:
With MSHFlexGrid1
If .Row = .RowSel Then
.Col = .Cols - 1
.ColSel = 0
End If
End With
You may need to set SelectionMode on the grid control also. The above code should work if set to flexSelectionFree
Have you set the SelectionMode property? If not, you get to it by clicking "Custom" in the properties window. This opens a dialog where SelectionMode is one of the available properties.

Different color for sorting in SSRS

I have a customer who would like some color formatting in an SSRS report. I cannot utilize grouping due to the customer requirements. I have the report sorting by Main Tank and would like the sorts to alternate in color. So it would have several rows of Tank A all be grey then several rows of Tank B all be white. I'm using this currently but it only works on the first row of each sort
=iif(
Fields!Tank.Value=previous(Fields!Tank.Value),
"Transparent",
"Red"
)
Any help would be great.
You can use custom code to get the required logic. Using a custom function in your code that returns the color based on the the Tank value.
Go to Report menu, Report Properties / Code tab and in the text area put this code:
Dim prevColor As String = "Transparent"
Public Function GetColor(ByVal flag As Integer) As String
If flag = 1 Then
If prevColor = "Transparent" Then
prevColor = "Gray"
Else
prevColor = "Transparent"
End If
End If
Return prevColor
End Function
Now in the cell background-color property use this expression:
=Code.GetColor(iif(Fields!Tank.Value=previous(Fields!Tank.Value),0,1))
It will color the background as below:
UPDATE: The above logic colors correctly only the first, third, fifth columns and so on. It is caused by multiple calls to the GetColor function and overwritting of the global variable prevColor.
I managed to solve that issue by passing the row number to the function. This is the updated function:
Dim prevColor As String = "Transparent"
Dim rowNum As Integer = 0
Public Function GetColor(ByVal flag As Integer, ByVal nRow As Integer) As String
If flag = 1 And rowNum <> nRow Then
If prevColor = "Transparent" Then
prevColor = "Gray"
Else
prevColor = "Transparent"
End If
End If
rowNum = nRow
Return prevColor
End Function
Note the function receives a new argument so the expression for calling has changed:
=Code.GetColor(iif(Fields!Tank.Value=previous(Fields!Tank.Value),0,1),
RowNumber("DataSet3"))
Replace "DataSet3" by the actual name of your dataset.
It should generate the following tablix:
Let me know if this helps.
I would handle this in your query by adding a column that returns a 0 or 1 to define the color - idea sketch: use rank to get numbers that correlate to the sort order and then use MOD 2 to get a 0 or 1. If you post a sample query, we can help figure out the specifics.

How to set default drop down list value from another drop down list in sheets?

Here is what I am trying to do. I have a list that populates a drop down list created by data validation. I then query the data to populate a second list based on the first drop down value. Everything works except I would like to set the first value in the second drop down to be the default value. In other words if I change the value in the first drop down my second drop down now shows an error until I select the drop down and change the value to a correct value. I would like to set it to the first correct value when the first drop down is changed. My reason for this is I dont want someone to forget to change the second drop down and get a value that is not even in the range.
Please help I am new to this kind of thing.
thanks
https://docs.google.com/spreadsheets/d/1U2_0Ku1bCLfDh_v2XyE9aQMSfdYmlVfX_8SKmQay48g/edit?usp=sharing
Here is what I have so far. It works except anytime the sheet is edited the value is reset. I only want it to reset when Cell A2 changes.
function onEdit() {
var ss = SpreadsheetApp.getActive()
var sheet = SpreadsheetApp.getActiveSheet();
// IF(cellContent has changed) then clear B2
// else do nothing.
sheet.getRange('B2').clearContent();
var value = sheet.getRange('H2').getValue();
sheet.getRange('B2').setValue(value);
}
I figured it out and this seems to work just fine.
function onEdit() {
var sheet = SpreadsheetApp.getActiveSheet();
var cell = sheet.getActiveCell();
var cellR = cell.getRow();
var cellC = cell.getColumn();
var cellValue = cell.getValue();
var active_spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var value = active_spreadsheet.getRange('H2').getValue();
if (cellR == 2 && cellC == 1) {
sheet.getRange('B2').clearContent();
sheet.getRange('B2').setValue(value);
}
}

Excel - Find All Cells Containing Value and Change Background Color

How do I find all cells containing a text value such as merchant_id and change the background color of those cells to a specific color?
This macro will use the current selected range and check each cell for merchant_id. Then mark it maroon if true. To pick a particular color, the best way is to record a macro and see what values it creates. Take those numbers and replace the contents of the With block
Sub MarkCellsInSelection()
For Each c In Selection
If c.Value = "merchant_id" Then
With c.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
End If
Next
End Sub

Resources