QTP row and column count is always 1 - excel

I am writing a piece of code to copy data from a web table to an excel sheet. I don't understand why I am getting row count and column count 1. Is there something else that I need to add?
Here is my code:
Dim XL
Set XL=createobject("Excel.Application")
XL.Workbooks.Open "D:\QTP\RailwaysforSurat.xlsx"
Set nsheet = XL.Sheets.Item(1)
row=Browser("title:=.*").Page("title:=.*").WebTable("html tag:=TABLE", "index:=0").GetROProperty("rows")
msgbox row
cols=Browser("title:=.*").Page("title:=.*").WebTable("html tag:=TABLE", "index:=1").GetROProperty("cols")
msgbox cols
This not complete code. I have trouble getting rows and columns count. Please help!
P.S. I am using this website for the testing "http://www.indianrail.gov.in/cgi_bin/inet_trnnum_cgi.cgi"

I noticed that you are using Descriptive Programming techniques to identify the WebTable, but you're using extremely generic descriptions for everything. Perhaps that's just scrubbed for the sake of posting publicly, but the important thing that I notice is that your code to read Rows is trying to find a table with Index of 0 and your code to read Cols is trying to find a table with index of 1...
This means you are accessing two different tables. Are you sure that your descriptions are finding the table that you think you want?
My suggestion is to:
1) bring up the page in your browser so that you can see the table.
2) Bring up QTP and open the GuiSPY
3) Click the pointing hand over a cube button to begin spying
4) Click on something inside the table you are trying to work with.
GuiSPY will snap back and show a hierarchy of objects that it found. Next, you want to positively identify what level in that hierarchy is the table at... I would...
5) starting at the top (Browser), select the top row and click "Highlight in Application" and watch what gets lit up.
6) go down the hierarchy list clicking the next item in the hierarchy and clicking "Highlight in Application" until you see it flash on the exact table you're trying to target.
7) Once you have isolated the table, click the button for "Copy the identification properties to the clipboard" button, then close GuiSPY.
8) Open a notepad, or just use QTP's editor window itself and paste in what GuiSPY copied to clipboard.
Ok, you now have a complete list of everything QTP was able to see about the specific table you want to detect. From here, you want to look through the list of properties and find one (or two) that would positively identify that table every time.. For example, on this very page, the table that holds your question could be identified as:
WebTable("text:=I am writing a piece of code to copy data")... (*note I've shaved it down because it's automatically a Regex string... With some cleanup, it could be:
Browser("StackOverFlow.Com").Page("Question 36663629").WebTable("text:=I am writing a piece of code to copy data"))
Now replace your .WebTable("html tag:=TABLE", "index:=0") with that data you've selected, and try it again. Hopefully you can lock in on the exact table you're expecting and get the info you need.

The indianrail page did not open so cannot see the table you are testing. But QTP provides default methods for rows and columns, try using that and see if it works.
NumRows = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").RowCount
NumColumns = Browser("Mercury Tours").Page("Search Results").WebTable("OutboundFlights").ColumnCount(1)
ColumnCount takes row number as parameter

Not sure what tables you are looking at, but if it is Services and information then the rows/cols value for those table is 1.The whole web page is consisted of concatenated web tables. So its going to be little tricky to capture that information. Try using a child object method and count the number of links within the web table, its going to look something like this -
Set oWebEdit=Description.Create
oWebLink("micclass").value="Link"
Set olink = Browser("title:=.*").Page("title:=.*").WebTable("").childobjects(oWebLink)
olink.count
msgbox olink.count
'Then initiate a for loop
For i = 0 to olink.count-1
' Get the link name
olink. count(i).GetRoproperty("name")
'Initiate an array and save the link names
If get link name does not work then you can use childitem method.
Also make sure you are using the correct index for the tables or define some other properties as well.
P.S. If you are going to use DP in future and haven't already then read about Childitems/childobjects methods.They come in real handy while using DP.

Related

Adding Entry to Table - Adding onto Existing Entry

I am trying to figure out a way to add data to an existing table, where it can identify a value (like name or ID#) and add in a new piece of data into that row for the individual.
See Pic 1: The person using this guide will click "yes" or "no" if they want to move the person forward. I want to record that yes/no in their database. (Note: each new candidate gets their HR Guide with their name on it. If you are listed on the Short list (see pic 2), you will get a HR Guide created for you. So the name of the tab is unpredictable, which is why things like vlookups or other formulas will not work.)
Here is the image of where I want the input to go. Based on the name matching in column C, I want it to input the Yes/No in Column I
I have no VBA code to share as I have no clue where to start. I have looked around trying to find a solution or something to work off of, but cannot find something that is close enough for me to figure it out (usually that works for me, but not this time...). So any help/direction you can provide would be VERY helpful! Thanks in advance.

Garbage Data Checker Using Excel VBA

My team and I have created a consolidator tool that consolidates data from worksheets uploaded using a button. However, there's an added enhancement that our leads would like to have.
I don't know if it's possible in VBA but what they wanted is a button that checks and highlights "garbage data" (for example: if First Name column contains a blank or if it contains ajsajdj or something similar), it will prompt the user and ask them if they want to delete it.
We already have the code for the consolidator tool (and it's working perfectly) however, this feature is headache inducing as I don't know if it's possible. I would really like to ask suggestions regarding this as I'm really new to VBA and programming.
Maybe, I would be enlightened on what next step I should take.
Let's see how a human would validate that
He would look at the name ajsajdj and think "I have never seen this name in my life before so it must be nonsense data". But he might fail because the fact that he never came accross this name doesn't mean it's not an existing name (parents can be inventive sometimes).
So what a human actually does is comparing the ajsajdj with a list of names (he has in mind because of his experience in life).
Now a program can do the same
You can write a code that compares ajsajdj with a list of valid names. But here we are at the same point where the human can fail too. The list will never be complete because tomorrow parents invent a new name (that you don't have in that list).
Conclusion
This task cannot be coded unless you define a rule for either valid or invalid data. Some programs look like they could do magic, but actually it is only working because of the rules you give them.
I do automated auditing of this type prolifically so I would approach it like this;
Your 'audit macro' is basically an iterator with many quality checks - is 'name' = "", etc. You can run this auto macro either.
On a single line of data each step of the consolidation
After the consolidation has completed.
The first is easiest to use, and works like this:
After your consolidation step run 'auditing macro' on line of data just brought in.
If an issue is found, write the line of data to a separate Tab leaving column A blank; not to your consolidation. At the end of your consolidation give user a warning message if there have been any issue lines found at the end of the consolidation
User skim reads data on separate tab, puts 1s for 'keep' in Column A.
User clicks a button to run a macro which adds the rows with a '1' against them back to your full data set (e.g. on the end if order doesn't matter).
Equally you could approach this by running the audit when the consolidation is totally complete; in this case you'd need to delete or otherwise track rows which may be removed if a user chooses not to keep them.
I like this approach because it is non-blocking; user can leave your consolidator to run without supervising and then deal with exceptions at their convenience. Also you can write/edit as many tests as you want without fundamentally changing your consolidator at all; you can then also start for example counting the number of each issue per import and putting this into a report for continuous improvement... there are options to extend.
In terms of pseudocode its an iterator full of if-else blocks, with a single 'there is an issue' flag, which if it's 1 causes the row to be treated as an issue;
For rowCount = startRow to endRow
' startRow and endRow correspond to lines of data you just imported
'Test 1
if (Some condition e.g. cells(rowCount ,2).value = "") then
issueFlag = 1
End if
'Test n...
if (Some condition e.g. cells(startRow,2).value = "") then
issueFlag = 1
End if
next rowCount
if issueFlag = 1 then
'CODE TO PASTE DATA
'Set some flag/variable which then triggers a Error Message at the end of the whole consolidation or audit
End if
You can put a Exit For at the end of the IF block so if the issueFlag is triggered you immediately exit and skip all further tests.

Click through multiple rows on a webpage in Blue Prism

I have run into an issue trying to retrieve data from a table on the surface of a web page. In each row of the table there is a link that leads to more details about the information in each row. See image The automation needs to decide whether or not to copy the row information based on criteria that is only given within the link.
Part of where I'm stuck is due to the fact that the number of rows in the table can vary, so I can't just specify each link as it's own element. So I need my bot to:
Start at the first row of information
Click the details link
Decide whether or not the information from the correlating row is needed
Go back to the place where the table is and copy down info if needed
Go to the next row and repeat steps 1-4 for the rest of the table
I believe I have a handle on step 3 and 4, along with 2 if clicking an element doesn't change with iterating through the table.
Thanks!
Just create a loop, that will iterate it self every time whenever you will go back to the table after copy info from the row.
So I would do something like that:
1.Click the details link
2.Decide whether or not the information from the correlating row is needed
3.Go back to the place where the table is and copy down info if needed
4.Go to the next row and repeat steps 1-4 for the rest of the table
5.Check if there is a next row. Yes? Loop to step 1. No? End.

Can Excel 2013 print different PrintTitleRows to each page?

I may be trying to do the impossible. What I need is to dynamically set the PrintTitleRows for each printed page in Excel. My worksheet is created dynamically and there are multiple (yet similar) sections of different row lengths and I want to show the section name and description titles on the top of the following page if the section overflows to multiple pages. The section names will not always be the same though the column titles will. The section name is on the row above the description titles.
Section name and description titles
Currently, I am calling my PageSettings sub and then executing the ExportAsFixedFormat, so I am guessing this can't be done.
I have spent the last few hours searching the Microsoft site, Stackoverflow.com and the web in general with no questions or hits related to this question.
Thanks in advance for any insight you may have.
The answer in no and is based on my experience. The PrintTitleRows and PrintTitleColumns are a one time setting which I did in my PageSettings sub. Once ExportAsFixedFormat starts running, it never hits the PageSettings sub again.
PrintTitleRows is a one time setting that places the same row (or rows) at the top of every printed page but I needed different rows.
The best I found way to achieve this is to add the necessary rows to the worksheet after each page break to make the report look the way I want when printed. I then hide these header rows from the user and display them when I print.

Data entry user form, copy paste with variation data

I'm working on a user form in excel vba. The purpose of the user form is to make data entry more efficient. The data that is being entered is for shoe products. Basically a "parent" of the data is made in one row. The proceeding rows, or what I refer to as children/variations, have the exact same data except certain fields(columns) will be variations of the parent and each variation will have a unique identifier.
For example: say we're entering data for "shoe123". The parent data would be like this
Title Sku
Shoe123 S123
Then the children would be in the row underneath with the same data except the variation size will be tagged at the end of some fields as well as a unique identifier for each variation. Theyd look something like this.
Title Sku
Shoe123 10.5 s123 10.5
Shoe123 11 s123 11
Uniqueid
09876543311
09876543321
So at this point I have been able to enter all the parent data in the form and transfer it to the appropriate column. I'm trying to figure out two things.
How can I code the user form to allow the user to enter the number of variations to create? and then based on the number the user enters, populate that number of combo boxes with pre filled size selections with text boxes next to each combo box to enter the unique identifier?
How would I copy and paste all the parent data with the variation data for each size selected as well as the unique identifier for each variation?
so far I'm thinking I'll need to use arrays for the copy and paste part. I just need some direction. Any help is greatly appreciated!
Thanks Everyone
I understand from your question that you are trying to create a database. If this is correct I would advice you to try and create this in Access. In Access it is a lot easier to link parent data to children. It will also safe you all the time you would need in Excel to code the userforms, etc. as this is (almost) use-ready provided in Access.
If you are determined to create this in Excel, perhaps you could show the vba-code you have so far?

Resources