For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2006 > Collection Problem Part 3 - Object variable not set









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Collection Problem Part 3 - Object variable not set
Bookreader

2006-04-26, 6:56 pm

When this code gets to the line
varLinksSearched.Add strLink
I get an error that says
Object variable or with variable not set

varLinksSearched is defined as a global collection as follows.

Please tell me what I am doing incorrectly.

Thanks.
-----------------------------------------------------------------------

Dim varLinksSearched As Collection

Private Sub getLinks(strLink As String)
On Error GoTo ErrorHandler

Dim objLink As HTMLLinkElement
Dim objMSHTML As New MSHTML.HTMLDocument
Dim objDoc As New MSHTML.HTMLDocument
Dim numChar As Integer
Dim varLink As Variant
Dim x As Integer

'Get document from URL
Set objDoc = objMSHTML.createDocumentFromUrl(strLink,
vbNullString)

'Wait for virtual browser to return
While objDoc.readyState <> "complete"
DoEvents
Wend

For Each objLink In objDoc.links
numLinks = numLinks + 1
Next

varLinksSearched.Add strLink


Exit Sub

ErrorHandler:
MsgBox "Error in getLinks " & Err.Number & " " & Err.Description
End Sub
Ken Halter

2006-04-26, 6:56 pm

"Bookreader" <Bookreader127@yahoo.com> wrote in message
news:qggv42ld7hq58sba7ik4q4a8518nlifqv0@
4ax.com...
> When this code gets to the line
> varLinksSearched.Add strLink
> I get an error that says
> Object variable or with variable not set
>
> varLinksSearched is defined as a global collection as follows.
>
> Please tell me what I am doing incorrectly.


Where's the 'Set varLinksSearched = New Collection' ?

You can even do something like....

Public varLinksSearched As New Collection

....and it'll be instantiated "on demand". There's excessive overhead
involved though so I always choose to Declare and Instantiate on two lines.

btw... imo, you should always explicitly declare scope whenever possible. In
the Declarations section, that would mean declaring everything as either
Private or Public... "Dim", by itself, leaves alot to be desired.... as far
as readability is concerned.

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com