Code Comments
Programming Forum and web based access to our favorite programming groups.New to DOM2 and playing around with a simple script to see how things work.
<script type="text/vbscript">
Function insertNewText()
Dim newText, para
newText = document.createTextNode("DOM methods are
, are they not?")
para = document.getElementById("example1")
para.appendChild(newText) <-------- error
End Function
</script>
Execution of this code in IE6 produces an 'Object required' error where
indicated. If I change to:
Set para = document.getElementById("example1")
I get a 'type mismatch' with the same line reference.
This script (with the syntax modified of course) works with Javascript.
Is this kind of functionality only available with Javascript or am I
missing something?
Post Follow-up to this messageRay Hinse wrote:
> New to DOM2 and playing around with a simple script to see how things
> work.
>
> <script type="text/vbscript">
> Function insertNewText()
> Dim newText, para
> newText = document.createTextNode("DOM methods are
, are they not?")
> para = document.getElementById("example1")
> para.appendChild(newText) <-------- error
> End Function
> </script>
>
> Execution of this code in IE6 produces an 'Object required' error where
> indicated. If I change to:
>
> Set para = document.getElementById("example1")
>
> I get a 'type mismatch' with the same line reference.
Nodes are objects too.
set newText = document.createTextNode("Hello World")
^^^
> This script (with the syntax modified of course) works with Javascript.
>
> Is this kind of functionality only available with Javascript or am I
> missing something?
Objects can have default methods or properties that are invoked or
returned by simply referring to the object in VB/VBA/VBScript. You must
use the Set operator to assign the object itself to a variable; if
you don't use the Set operator, you assign the default property (or
the return value of the default method) to the variable or you generate
a "Object doesn't support this property or method" error if the object
has no default.
JScript doesn't grok object defaults. Assignments *always* assign the
object itself. Of course, this means that you must explicitly refer
to the objects default property or method if that's what you want.
This annoys VB programmers who never had to explicitly refer to the
default before, and sometimes don't even realize that what they're
referring to is an object, having always gotten the default value.
--
Steve
The greatest lesson in life is to know that even fools are right
sometimes. -Winston Churchill
Post Follow-up to this messageThank you. A very decent explanation. I don't know why I didn't think to do that myself.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.