Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 12th, 2007, 10:47 AM
Ocean Ocean is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 7 Ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 17 sec
Reputation Power: 0
Looping through code

I have a need to write some code in VBA for Word.
I already have some code that goes to a website downloads a football table and then pastes/formats it in Word automatically.
This works fine for the first table, but there there are 4tables I need in total. Each one has its own web page.
How can I loop through each web page and download each table and the sequentially paste/format them into the word document.

I have a counter that goes up, and makes this:
httppage = "http://www.footyresults.com/league" & League & ".html"
So this returns
http://www.footyresults.com/league1.html
http://www.footyresults.com/league2.html
http://www.footyresults.com/league3html
http://www.footyresults.com/league4html

I want this to be used in the code that determines the webpage to go to.

Any suggestions as to how i can loop through the main internet download table code, but each time reassigning the "httppage" to the next html page?
I do not want to repeat the full code for each table !
Any suggestions would be really appreciated...
Thanks

Reply With Quote
  #2  
Old November 12th, 2007, 06:16 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 57 m 26 sec
Reputation Power: 181
I'd probably look at using the webbrowser control to pull the page source from each of the web pages.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old November 13th, 2007, 06:08 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
Can you post the code that you have so far. If it works for the first one, I'm sure it can be adapted to loop through all four, without replicating the code four times!!

Reply With Quote
  #4  
Old November 13th, 2007, 06:04 PM
Ocean Ocean is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 7 Ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 17 sec
Reputation Power: 0
Hi

Here is the code:

Option Explicit
Dim ie As InternetExplorer
Dim doc As HTMLDocument
Dim tr As HTMLTableRow
Dim td As HTMLTableCell
Dim tbl As HTMLTable
Dim blc As HTMLBlockElement
Dim doctbl As Table


Private Sub CommandButton1_Click()
Dim nrow As Integer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://www.skysports.com/football/league/0,19540,11660,00.html"

Do
DoEvents
Loop While ie.readyState <> READYSTATE_COMPLETE

Set doc = ie.Document
Set tbl = doc.getElementById("ss-stat-sort")

nrow = tbl.Rows.Length - 1
'Exit Sub
Set blc = tbl.all.tags("caption").Item(0)

ActiveDocument.Range.InsertAfter blc.outerText


Dim myrange As Range
Set myrange = ActiveDocument.Content
myrange.Collapse direction:=wdCollapseEnd



Set doctbl = ActiveDocument.Tables.Add(myrange, nrow, 10)
Dim i As Integer, x As Integer
x = tbl.Rows.Length - 1
Dim col As Integer, j As Integer
For i = 2 To x
Set tr = tbl.all.tags("tr").Item(i)
col = tr.all.tags("td").Length - 2
For j = 2 To col
Set td = tr.all.tags("td").Item(j)
doctbl.Cell(i, j).Range.Text = td.outerText
Next
DoEvents
Next

doctbl.Columns(2).Width = 140
For i = 3 To 10
doctbl.Columns(i).Width = 30
Next
End Sub


I want to then do the other tables, eg,

http://www.skysports.com/football/league/0,19540,11687,00.html
then,
http://www.skysports.com/football/league/0,19540,11749,00.html
etc...

I would like to have them sequentially listed one under the other.... if possible.
Any help would be very much appreciated. Thanks

Reply With Quote
  #5  
Old November 14th, 2007, 04:32 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 1,932 sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 4th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 6 Days 22 h 36 m 35 sec
Reputation Power: 1243
In your original post you seem to indicate that the page names will simply increment by one each time, but I can't see any evidence of this in your latest post. Are the suffixes 11687,00 and 11749,00 random or are they fixed?

If the names of the pages are going to include a number that increments, you should be able to put your code in a loop:
Code:
Private Sub CommandButton1_Click()
Dim nrow, intCounter As Integer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

'This assumes that your pages will be named following the convention ..../football/league/[unique number]

For intCounter = 1 To 4
     ie.navigate "http://www.skysports.com/football/league/" & intCounter & ".html"

     Do
          DoEvents
     Loop While ie.readyState <> READYSTATE_COMPLETE

     'etc.....

Next
End Sub

If however, your page names do not follow the same convention, you could store the names of the pages in an array:
Code:
Private Sub CommandButton1_Click()
Dim nrow, intCounter As Integer
Dim pagenames(4) As String
pagenames(0) = "0,19540,11687,00"
pagenames(1) = "0,19540,11749,00"
'etc..

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

For intCounter = 1 To 4
     ie.navigate "http://www.skysports.com/football/league/" & pagenames(intCounter) & ".html"

     Do
          DoEvents
     Loop While ie.readyState <> READYSTATE_COMPLETE

     'etc.....

Next
End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Looping through code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT