vb script question

Ashala

One of Freddy's beloved
Joined
Oct 22, 2004
Messages
771
helloes

i pretty new to vbs and im trying to create a script that counts the 3 first letters in the computername

i was told it looked something like this

document.write(left(name,3))

where name is the variable that contains the computers name, but when i try to run this, it just says the variable "Document" is not defined.

could anyone help a noob finish his work ?
 

kirennia

Part of the furniture
Joined
Dec 26, 2003
Messages
3,857
Have not worked with VB before but one common trait I'm sure it shares with other languages; be careful of case-sensitivity. Don't know if it's just because you wrote on the forum but 'document' as per your statement and 'Document' as per your not found variable will mean completely different things.
 

Ashala

One of Freddy's beloved
Joined
Oct 22, 2004
Messages
771
tried it and it still fails, thanks tho =)
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,443
Name is pretty generic, try using something stupid like R2D2
 

Gahn

Resident Freddy
Joined
Jan 16, 2004
Messages
5,056
helloes

i pretty new to vbs and im trying to create a script that counts the 3 first letters in the computername

i was told it looked something like this

document.write(left(name,3))

where name is the variable that contains the computers name, but when i try to run this, it just says the variable "Document" is not defined.

could anyone help a noob finish his work ?

In which context you using Document?
And am pretty sure (even tho i crossed to Javascript / c# years ago) that's Document.Write in Vb.
 

Ashala

One of Freddy's beloved
Joined
Oct 22, 2004
Messages
771
the script so far looks like this...

Option Explicit
Dim name, drivename
name="821222"
drivename=Document.Write(left(name,3))

wscript.echo "drivename"


im gonna use some diffrent variables in the final version and obviously some more text but this is where im stuck, it says that "Document" is not a defined variable
 

Ashala

One of Freddy's beloved
Joined
Oct 22, 2004
Messages
771
the noob became a master in the end ( or a lesser noob )

turns out i didnt need the document.write function to cut of a section of a text, just :

dim name
name="1234"
left(name,3)
msgbox name

123

thanks for your time =)
 

kirennia

Part of the furniture
Joined
Dec 26, 2003
Messages
3,857
It's probably still worth working out how the console command works none-the-less...I'm interested in what the problem was anyway :D

Is it because the Document.Write command doesn't know how to display the converted 'Left' command? Does it work if after having worked it out, you just do Document.Write(name); or even *Document.Write(left(name, 3) + ""); I know the '+ ""' is a bit of a cheat in a couple of languages...c#/java if I remember right so that may have done something as well.

*Just looked at it a bit...does VB have a different way of declaring variables then? It looks like there is only a dim declaration or private/public if you want to set the access, completely removing the dim part from the declaration...

I'd assume that makes the language quite slow...
 

Ashala

One of Freddy's beloved
Joined
Oct 22, 2004
Messages
771
im not really sure about most of the things you asked Kirennia but i was told that document.write is a fucktion much like msgbox that should print something to the screen, why it failed in my setup, im not sure, as im not sure how the document.write function is suppose to be presented.
:ninja:
 

ST^

Can't get enough of FH
Joined
Dec 22, 2003
Messages
2,351
I think VBS Document.Write is only for use in the script tags of a HTML page. In other VBS stuff, 'document' is not defined. And it won't make a message box, it'll just write the result into the current document (being a HTML document).
 

phlash

Fledgling Freddie
Joined
Dec 24, 2003
Messages
195
Correct ST^, the 'document' object only exists when the script is running within a web page context, otherwise you should be using the wscript object for input/output as demonstrated in the working program... :)

I can thoroughly recommend the MSDN library documentation on scripting here:

Microsoft Windows Script Technologies

Take a look at the 'VB Script' and 'Windows Script Host' sections
 

Syri

FH is my second home
Joined
Jan 4, 2004
Messages
1,019
Document.write is used to write text into the html code of a document, if the vbscript is part of a webpage, in much the same way javascript can be used. So for example, you could write the entire html body by using :-
document.write "<body><b>Heading</b><br><br>Written by vbscript"
If you write a separate vbscript file though, and get windows to just run the script outside a webpage, the document object is not created.
I believe that's right anyway, not used vbscript for several years, as it's a horrible and vastly under-supported scripting language.
 

Users who are viewing this thread

Top Bottom