There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox firewall format freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware motherboard mouse network networking outlook outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Accessing the Web via VB6 (Automation Error!)


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
philipp's Avatar
Junior Member with 8 posts.
 
Join Date: Jan 2004
28-Jan-2004, 05:17 PM #1
Angry Accessing the Web via VB6 (Automation Error!)
Hi.
I am trying to read a website into a variable so I can run parsing scripts in Visual Basic 6.0

I am using:

Dim Web As New SHDocVw.InternetExplorer
Dim Doc As New MSHTML.HTMLDocument

Web.Navigate "http:// website "
Set Doc = Web.Document

(I have references and instances of the following classes installed on my form)
- Microsoft Internet Controls (shdocvw.dll)
- Microsoft HTML Object Library (MSHTML.TLB)

When I run the above code, I get an Automation Error for the last line.
What am I doing wrong ???

Help appreciated.
Thanks
Phil.
coderitr's Avatar
Distinguished Member with 3,080 posts.
 
Join Date: Oct 2003
29-Jan-2004, 09:43 PM #2
I found something quite by accident. I placed the code you posted into a new form in VB in a button click event procedure. If I just click the button with no breakpoints, I get the same error you did. If I set a breakpoint on the line that's generating the error and wait a couple of seconds before running it, it goes right through. It appears that the navigate method takes a couple of seconds to set up the document object. I have no idea what that means.
coderitr's Avatar
Distinguished Member with 3,080 posts.
 
Join Date: Oct 2003
29-Jan-2004, 09:44 PM #3
Welcome to TSG by the way.
philipp's Avatar
Junior Member with 8 posts.
 
Join Date: Jan 2004
30-Jan-2004, 12:18 AM #4
Coderitr,
I have noticed that too, its driving me nuts !

Im trying to teach myself VB, but it seems someone up there has other ideas.

Thanks for sharing my pain anyway.
Phil.
ciener's Avatar
Junior Member with 7 posts.
 
Join Date: Jan 2004
31-Jan-2004, 11:16 AM #5
try
you can use two controls one being winsocket or inet.

Here is winsock

Winsock1.Connect "www.google.com", 80

Private Sub Winsock1_Connect()
'Once the winsock has connected to the server we send our request.
'GET tells the server we are GETting the html
'the / just tells it to send the default page, usually index.html, .htm, .php or what have you.
'The HTTP/1.0 tells it that we are using HTTP version 1
'Then we let the server know it has the whole request by sending 2 vbCrLf's

Winsock1.SendData "GET / HTTP/1.0" & vbCrLf & vbCrLf

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'Once the server starts returning data we need to handle it.
'As some pages can be large they will be returned in several packets.
'So we need a buffer to store all the packets in. So ....

Static buf As String

'Now we tell the Winsock to make the packet into a string called Wdata

Winsock1.GetData Wdata, vbString

'We add the packets to the buffer.

buf = buf & Wdata

'We need to check once all the html has arrived.
'So we check the buffer for the closing HTML tag.
'As some sites use capitals for tags and others use lowercase we use Lcase.
'This makes the buffer lowercase while we check it.
'If it's there we call the Parse Sub routine and pass the buffer to it.
If InStr(1, LCase(buf), "</html>") Then Parse (buf)

Private Sub Parse(Data As String)
'In here we are going to get the page title from the html.
'We them use the title for the forms caption.
'The integers a and b are used for finding the start and end of the title.

Dim a, b As Integer

'We no longer need the connection so we close winsock.

Winsock1.Close

'Now we find the title of the page.
'We make a = the start of the title by locating the <title> tag.
'We then add the length of the tag to it as the title starts
'at the end of the tag not the start.

a = InStr(1, LCase(Data), "<title>") + 7

'Then using a as the starting point we make b = the end of the title by locating </title>.

b = InStr(a, LCase(Data), "</title>")

'Now we make the title of the page the form's caption.
'The title is in the string called Data.
'It starts at a and it's length is b - a.

Form1.Caption = Mid(Data, a, b - a)

'Now we display all the returned data in our text box.
'The information at the start are the headers.
'These tell use the server type, the time and date on the server, etc.

Text1.Text = Data

End Sub

thats one way you can do that.

The other way is inet = Internet transfer control

test = Inet1.OpenURL("www.google.com")
Text1.Text = test

thats all the code.. much easer to use this.



Good luck hope this helps.
philipp's Avatar
Junior Member with 8 posts.
 
Join Date: Jan 2004
08-Feb-2004, 07:00 PM #6
Ciener,
Thanks for that.

The Inet option works well.

Thanks to all.
Phil.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:40 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.