Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

VBScript & document.CreateTextNode()
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?



Report this thread to moderator Post Follow-up to this message
Old Post
Ray Hinse
08-06-04 08:55 AM


Re: VBScript & document.CreateTextNode()
Ray 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

Report this thread to moderator Post Follow-up to this message
Old Post
Steve Fulton
08-06-04 01:55 PM


Re: VBScript & document.CreateTextNode()
Thank you. A very decent explanation.

I don't know why I didn't think to do that myself.



Report this thread to moderator Post Follow-up to this message
Old Post
Ray Hinse
08-06-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

VBScript archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:18 AM.

 

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.