Pasing a document object to a Sub procedure 
Author Message
 Pasing a document object to a Sub procedure

Hello, the problem it's simple:

What kind of object is the window.document? I've saw that it's an
"Automation"....

This is because i've got a Sub procedure that goes through the
document's elements and puts a handler on the onclick event,and if a
new window opens i would like to re-use this procedure to goes through
this window.document's elements.

Thanks a lot again for all the responses to my laters messages.



Tue, 06 Jul 2004 02:41:17 GMT  
 Pasing a document object to a Sub procedure

msgbox typename(window.document) '==> HTMLDocument

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Hello, the problem it's simple:

> What kind of object is the window.document? I've saw that it's an
> "Automation"....

> This is because i've got a Sub procedure that goes through the
> document's elements and puts a handler on the onclick event,and if a
> new window opens i would like to re-use this procedure to goes through
> this window.document's elements.

> Thanks a lot again for all the responses to my laters messages.



Tue, 06 Jul 2004 04:52:35 GMT  
 Pasing a document object to a Sub procedure
Ok, HTMLDocument object but if i try to put this inside de argument of
the Sub an error appears:

     - Different types when calling MeterHandler(..)

Let's paste some code, this is the Sub procedure (part of it):

Sub MeterHandlers(Documento As HTMLDocument)

    'Inicializar los handlers para los links
    i = 0    
    Do While i <= (Documento.links.length - 1)

      Set Documento.links(i).onclick = GetRef("Enlaces")
      i = i + 1
    Loop
'Lot of code that i don't put
End Sub

And i'm calling this Sub procedure using:
MeterHandlers(oIE.document)

Where oIE it's an InternetExplorer Object.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 06 Jul 2004 05:33:19 GMT  
 Pasing a document object to a Sub procedure
VBScript does not support strongly typed variables, only variants.  If you want to sanity check to make sure you handle the type of object(s) you expect, use

Sub MeterHandlers(Documento)

    If TypeName(Documento) = "HTMLDocument" then
        'continue processing
    else
        'throw an error or whatever seems appropriate...
    end if

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Ok, HTMLDocument object but if i try to put this inside de argument of
> the Sub an error appears:

>      - Different types when calling MeterHandler(..)

> Let's paste some code, this is the Sub procedure (part of it):

> Sub MeterHandlers(Documento As HTMLDocument)

>     'Inicializar los handlers para los links
>     i = 0    
>     Do While i <= (Documento.links.length - 1)

>       Set Documento.links(i).onclick = GetRef("Enlaces")
>       i = i + 1
>     Loop
> 'Lot of code that i don't put
> End Sub

> And i'm calling this Sub procedure using:
> MeterHandlers(oIE.document)

> Where oIE it's an InternetExplorer Object.

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Tue, 06 Jul 2004 05:48:29 GMT  
 Pasing a document object to a Sub procedure
He,he, still having the same error!

  MeterHandler.document ***<---Sub call.

And then, the Sub Source:

Sub MeterHandlers(Documento) <---As you can see i'm using Variant type!

    'Inicializar los handlers para los links
    i = 0    
    Do While i <= (Documento.links.length - 1)

      Set Documento.links(i).onclick = GetRef("Enlaces")
      i = i + 1
    Loop

End Sub

Strange...uh?:D

Ibor Rodrguez Barredo

Spain

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 06 Jul 2004 06:09:17 GMT  
 Pasing a document object to a Sub procedure

Quote:
> He,he, still having the same error!

>   MeterHandler.document ***<---Sub call.

What is this supposed to be???

I suggest to put together a simplified but otherwise complete example of what you are trying to do and post the whole example.  

Trying to figure out what you are trying to do from postings of bits and pieces of incomplete code with no context is impossible ;-)...

--
Michael Harris
Microsoft.MVP.Scripting
--



Tue, 06 Jul 2004 06:15:59 GMT  
 Pasing a document object to a Sub procedure
Yerp!I small mistake! ;).

Obviously it's not : MeterHandlers.document! ;D

It's :

   MeterHandlers oIE.document

Where oIE its an InternetExplorer Object. ;).

MeterHandlers it's a Sub procedure call from another VBscript.

I Think that this is all the code we need :), but if you prefer i can
paste "all" the code (a lot of....boring code).

Ibor Rodrguez Barredo

Spain

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 06 Jul 2004 06:33:13 GMT  
 Pasing a document object to a Sub procedure
set ie = createobject("internetexplorer.application")
ie.navigate "about:blank"
do until ie.readystate = 4 : wscript.sleep 1 : loop

mysub ie.document

x = "abc"

mysub x

wscript.quit

sub mysub(doc)
  if typename(doc) = "HTMLDocument" then
    msgbox "it's a document object: " & typename(doc)
  else
    msgbox "it's **not** a document object: " & typename(doc)
  end if
end sub

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> Yerp!I small mistake! ;).

> Obviously it's not : MeterHandlers.document! ;D

> It's :

>    MeterHandlers oIE.document

> Where oIE its an InternetExplorer Object. ;).

> MeterHandlers it's a Sub procedure call from another VBscript.

> I Think that this is all the code we need :), but if you prefer i can
> paste "all" the code (a lot of....boring code).

> Ibor Rodrguez Barredo

> Spain

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Tue, 06 Jul 2004 07:00:58 GMT  
 Pasing a document object to a Sub procedure
This Is the main script, filename: mainscript.wsf

<job>
 <script language="VBScript" source="subprueba1.Vbs"/>
 <script language="VBScript">
  Dim oIE
  Set oIE = WScript.CreateObject("InternetExplorer.Application","oIE_")
  oIE.Visible = True
        Do While True
                'Duerme 10 minutos y haz el bucle de nuevo.
                WScript.Sleep 36000000
                WScript.Quit (1)
        Loop
        Sub oIE_DocumentComplete(Byval pDisp, URL)
                MeterHandlers oIE.document
        End Sub
 </script>

</job>

And this Is the subprueba1.vbs file:

Option Explicit

Sub MeterHandlers(Documento)
  WScript.Echo typename(Documento)

End Sub

Why the hell Is an Error On the MeterHandlers procedure? (Error: Types
doesn't coincide . MeterHanlers(...), Code:800a00D, Origin :Microsoft
VBscript error in execution)

Thanks a lot.I'm going crazy with this! {:S

Ibor Rodrguez Barredo

Spain

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Tue, 06 Jul 2004 20:21:19 GMT  
 Pasing a document object to a Sub procedure
 <script language="VBScript" source="subprueba1.Vbs"/>

should be

 <script language="VBScript" src="subprueba1.Vbs"/>

And you never navigate IE to any document...

  Dim oIE
  Set oIE = WScript.CreateObject("InternetExplorer.Application","oIE_")
  oIE.navigate "http://www.microsoft.com"

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> This Is the main script, filename: mainscript.wsf

> <job>
>  <script language="VBScript" source="subprueba1.Vbs"/>
>  <script language="VBScript">
>   Dim oIE
>   Set oIE = WScript.CreateObject("InternetExplorer.Application","oIE_")
>   oIE.Visible = True
> Do While True
> 'Duerme 10 minutos y haz el bucle de nuevo.
> WScript.Sleep 36000000
> WScript.Quit (1)
> Loop
> Sub oIE_DocumentComplete(Byval pDisp, URL)
> MeterHandlers oIE.document
> End Sub
>  </script>

> </job>

> And this Is the subprueba1.vbs file:

> Option Explicit

> Sub MeterHandlers(Documento)
>   WScript.Echo typename(Documento)

> End Sub

> Why the hell Is an Error On the MeterHandlers procedure? (Error: Types
> doesn't coincide . MeterHanlers(...), Code:800a00D, Origin :Microsoft
> VBscript error in execution)

> Thanks a lot.I'm going crazy with this! {:S

> Ibor Rodrguez Barredo

> Spain

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Wed, 07 Jul 2004 00:51:36 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Session Dictionary object within a Sub procedure

2. accessing sub procedure on a different webpage

3. Getting Variable Array into Sub Procedure

4. Newbie - Passing a string to a sub procedure

5. Sub Procedure Parameters

6. Passing an array to a Sub procedure

7. Does Vbscript Sub Procedure support

8. sub procedure

9. sub procedure

10. menus and sub-menus and sub-sub-menus

11. Help: Postscript documents from Clipper procedure

12. Pasing values

 

 
Powered by phpBB® Forum Software