Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop and Count

Status
Not open for further replies.

AndyHHHH

Technical User
Mar 20, 2012
2
0
0
US
I am pretty new to the whole VB thing, but I am trying to write a script to pull certain information off of an email. I know I probably could cut and paste but where is the fun in that! Using an IE window I want to pull Sku's and the Qty and drop them into my POS system. I can get it to do the first one, but after that I know I need a loop to keep it going, but also the data that needs to be collected is in a different place on the page. Here is the code...

'Grab a collection of all the table elements in the webpage. The Ship To information resides in the fourth table element (count is zero based)
Set ColInputs = IE.Document.getElementsByTagName("table")
Set x = ColInputs.item(6)

'Grab a collection of all the td elements in the selected table element. The Ship To information resides in the first td element (count is zero based)
Set xData = x.getElementsByTagName("td")
Set skuData = xData.item(1)
Set qtyData = xData.item(2)

strSkuInfo = Trim(skuData.innerHTML)
'MsgBox strSkuInfo
Dim skuDataPart
skuDataPart = strSkuInfo

strQtyInfo = Trim(qtyData.innerHTML)
'MsgBox strQtyInfo
Dim QtyItem
Qtyitem = strQtyInfo

It is all based in the same table field, but the <td> fields will increase by 4 each time. I am not sure how to tell it what to do. I also am not sure how to tell it to stop. Sometimes there is 1 item, sometimes there are 20! Like I said I am still pretty new to this stuff and had a buddy help me to get to this point. Any help on this is greatly appreciated.
 
AndyHHHH,
Two thoughts, code should be close based on your sample.

Option 1
[tt]For TdElement = 0 to xData.length Step 4
...
Next[/tt]

Option 2
[tt]For each TrElement in x.Rows
Set skuData = TrElement.cells(2)
Set qtyData = TrElement.cells(3)
Next[/tt]

Hope this helps,
CautionMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top