I'm trying to read the number of characters in column "MRP element data" in tcode MD04.
Below code is giving me 1 but I want it to give 16 or it should give 16 provided that my code is right...If there is one more row with one more Purchase Order it should give 32 etc.
j = 0
Do
session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0750/tblSAPMM61RTC_EZ/txtMDEZ-EXTRA[5," & CStr(j) & "]").caretPosition = 0
objSheet.Cells(i, 2) = Len(Cstr(j))
Exit Do
j =j + 1
Loop
You currently calculate the length of the integer variable j which contains the value 0, it's why you get 1.
The table element you show is a GuiTableControl object. You will find the method GetCell to read the content of a cell, and after that you can calculate the length of its value.
Set tableControl = session.findById("wnd[0]/usr/subINCLUDE1XX:SAPMM61R:0750/tblSAPMM61RTC_EZ")
MsgBox Len(tableControl.GetCell(1,5).Text)
(row 1 = second row; column 5 = sixth column)
Related
I have two columns with data as double.
I'd like to create a vba script that does this:
Create a temporary third column that stores a lower value of each row.
Output min and max of the third column.
Now the problem is not to create this third column, I'd like this operation to be done in memory.
Please help
Thanks
This will show a message box with minimum and a message box with maximum value, assuming the two columns are A and B.
Sub MinMax()
' Count the number of rows in the first column
' Assuming that number of rows in second column equals those in the first column
HowFar = WorksheetFunction.CountA(Range("A:A"))
' Declare an array to store the minimums
Dim Arr() As Double
ReDim Arr(HowFar - 2)
Dim Index As Integer
Index = 0
' Loop through the first and second columns and store the minimums for each row in the array
Dim i As Integer
For i = 2 To HowFar
Minimum = Application.WorksheetFunction.Min(Range("A" & i & ":B" & i))
Arr(Index) = Minimum
Index = Index + 1
Next i
' Get the minimum value in the array
Min = Application.WorksheetFunction.Min(Arr)
' Get the maximum value in the array
Max = Application.WorksheetFunction.Max(Arr)
' MsgBox the two values
MsgBox ("Minimum = " & Min)
MsgBox ("Maximum = " & Max)
End Sub
My requirement is to iterate through a VBA collection , and based on certain
condition update the subsequent records in the same collection.
For example lets say "TMasterList" is a collection which has total of 4 records ,
while 2nd record gets processed in the below loop,
I need to update 3rd and 4th record and then continue with the loop(ie process 3 and 4th).
For Each objEachTmapping In TMasterList
Next
Any suggestions on how to implement it.
Loop over the index, checking the bounds if needed:
Dim i As Long, max As Long
max = TMasterList.Count
For i = 1 To max
TMasterList.Item(i).value = Foo
If i + 1 < max Then TMasterList.Item(i + 1).value = Bar
If i + 2 < max Then TMasterList.Item(i + 2).value = Qux
Next
This assumes that there is a reference in the collection, if its a type it cannot be modified in situ.
Thanks in Advance :) I can get the row count but not the column count using columncount method in uft 12.2. It simples throws an error at AccNoCol=AccNoTB.ColumnCountWrong number of arguments or invalid property assignment: 'AccNoTB.ColumnCount'. I know the column count is 8 here however they are dynamic & there is a risk to hard code the column count in script. Could you plz point out the correct? Thanks again
Set AccNoTB=browser("title:=.*").page("title:=.*").webtable("column names:=;Account No;Account Name;Billing City;Website;Phone;Assigned To;Action","cols:=8")
AccNoRow=AccNoTB.RowCount
AccNoCol=AccNoTB.ColumnCount
AccTBvalue=AccNoTB.GetCellData(AccNoRow,AccNoCol)
MsgBox AccTBvalue`
The column count of each row in the WebTable can differ therefore ColumnCount requires a parameter to specify to UFT which row's column count you're interested in.
A row can have
<table border=1>
<tr><td>One</td></tr>
<tr><td>or</td><td>two</td></tr>
<tr><td>or</td><td>even</td><td>more</td></tr>
</table>
Columns
Two simple ways to get Row and Column counts.
Note that I've removed "cols:=8" from object description, assuming the WebTablt is getting identified by column names.
Set AccNoTB=browser("title:=.*").page("title:=.*").webtable("column names:=;Account No;Account Name;Billing City;Website;Phone;Assigned To;Action")
Two ways to get Rows count
AccNoRow = AccNoTB.GetROProperty("rows") '<-- 1
AccNoRow = AccNoTB.RowCount '<-- 2
Two ways to get Column count
AccNoCol = AccNoTB.GetROProperty("cols") '<-- 1
iRow = 2
AccNoCol = AccNoTB.ColumnCount(iRow) '<-- 2 This way is useful when you have different columns in different rows.
Now lets take the example that #Motti have given. In this case we'll run a loop and get the column count.
Set AccNoTB=browser("title:=.*").page("title:=.*").webtable("column names:=;Account No;Account Name;Billing City;Website;Phone;Assigned To;Action")
AccNoRow = AccNoTB.RowCount
For i = 1 To AccNoRow
AccNoCol = AccNoTB.ColumnCount(i)
Print "Row " & i & " has " && " column/s."
Next
Output:
Row 1 has 1 column/s.
Row 2 has 2 column/s.
Row 3 has 3 column/s.
set a=Browser("OrangeHRM").Page("OrangeHRM_2").WebTable("micclass:=WebTable","html tag:=TABLE")
co=a.RowCount
MsgBox co
'set b=Browser("OrangeHRM").Page("OrangeHRM_2").WebTable("micclass:=WebTable","html tag:=TABLE")
col=b.ColumnCount
MsgBox col
I was wondering how to colour the first 8 rows of a datagridview. I have managed to sort the values in descending order and I wish to have the first 8 rows coloured to highlight the top 8 to the user, and I'm not sure how to go about doing this.
Dim count As Integer
For count = 0 To datagridsort.RowCount - 1
Do
datagridsort.Rows(0).Cells(0).Style.BackColor = Color.Coral
datagridsort.Rows(0).Cells(1).Style.BackColor = Color.Coral
Loop Until count = 8
Next
In the code you posted in your comment, you were never using the count variable. You were only updated the first row every time. Try it like this:
For i As Integer = 0 To Math.Min(datagridsort.RowCount - 1, 7)
For j As Integer = 0 To datagridsort.ColumnCount - 1
datagridsort.Rows(i).Cells(j).Style.BackColor = Color.Coral
Next
Next
I have a form which is 1 list view and a text box.
* list view has a total of 100 rows of data
* list view has 5 columns
* column 3 has only two possible words yes or no
I want to count the number of occurrence of the word yes in column 3
the total row can be count with this code:
''''''''''COUNT TOTAL ADMISSION''''''''''''''
Dim rowcount As Integer = 0
For Each item As ListViewItem In LVfeestatementBA_I.Items
rowcount = CInt(item.SubItems(0).Text) 'Considering every column always have some value
Next
txttotaladBA_I.Text = rowcount.ToString()
any help will be greatfull
EDIT 1
This is a school assignment. As I said my aim is to find out the number of occurrence of a word in column 3. I have database of MS access which is connected with code and provides the data for the list view. The list view has 5 columns and there are a total of 100 rows. The data in col-3 contains only three words gen, occ, and cc. Now in want to count col-3 for the words with code and show the number like (68) in textbox1
EDIT 2
I applied the function provided by thedarkspoon, but it's not showing the result. I just want the result to be shown in textbox1, ex. if total number of words are 78 then at the time of form_load it should show 78 in textbox1. I solved the problem by adding at last textbox1.text = numofyes and change variable from integer to string now its working
I did not quite understand your scenario (you have to be more clear).
Anyway, given a ListView that displays items that each have 3 subitems and we know that the third subitem will have values of either "yes" or "no" we can build a query like (using linq):
var collectionOfListViewItems = listView1.Items.Cast<ListViewItem>();
var numberOfrowsWithTheThirdSubItemTextEqualToYes = (from c in collectionOfListViewItems where c.SubItems[3].Text == "yes" select c).Count();
Without linq you could do a foreach:
var numberOfrowsWithTheThirdSubItemTextEqualToYes = 0;
foreach (ListViewItem item in listView1.Items)
{
if (item.SubItems[3].Text == "yes")
numberOfrowsWithTheThirdSubItemTextEqualToYes++;
}
Ok here you go, I made this a function but you could easily adapt this to a subroutine:
Function countyes()
'Set up a variable to count the number of yes:
Dim numofyes As Integer = 0
'Count the number of yes (Replace listview1 with the name of your listview):
For Each item As ListViewItem In ListView1.Items
'If the Yes/No is in column 3, you are looking in subitem 2:
If item.SubItems(2).Text = "Yes" Then
'Increment the variable by one if the value is yes:
numofyes = numofyes + 1
End If
Next
'Return our total number of Yes that we found:
Return numofyes
End Function
Hope this helps!