Re: Defining Parameter

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Al Dunbar [MS-MVP] (alan-no-drub-spam_at_hotmail.com)
Date: 10/13/04


Date: Wed, 13 Oct 2004 11:51:58 -0600


"Ronen" <eyasso@hotmail.com> wrote in message
news:%23p$5ptSsEHA.3468@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> Is there a way to define in VBS a text like in c/c++ in the following way?
>
>
> #define TDOutput.Print Wscript.echo

Not that I know of...

> This way doesn't work:
>
> Const TDOutput.Print = Wscript.echo

Const assigns a value to a symbol so that common constant values can be
referred to in your script symbolically.

The symbol must be equivalent in form to a variable name. TDOutput and Print
would both be valid, but TDOutput.Print is not. For the construct
"TDOutput.Print" to mean anything in vbscript, TDOutput must have been
already created as an object variable. But a constant cannot depend in any
way on a variable.

The value assigned the constant must be a: "Literal or other constant, or
any combination that includes all arithmetic or logical operators except
Is.". Nowhere in that definition does it allow for any run-time values.
Wscript.echo is not a constant, but the name of a method. And further,
Wscript is the name of an object created at run-time by WSH, and is not part
of vbscript itself.

What you are looking for seems to be a source-level macro or
string-replacement capability. vbscript is quite different from c/c++ in
this and many other respects. Trying to provide a convention in which a
c/c++ programmer might feel more comfortable when working in vbscript (if
that is your goal) seems to me to be a particularly ineffective technique.
IMHO, you'd be better off using vbscripts own particular features directly.
For example, something like this might do what you want here:

    print "this is a test"
    print "the time is " & time & ", and the date is " & date
    wscript.quit

    sub print( arg )
        wscript.echo arg
    end sub

/Al



Relevant Pages

  • Re: constants in global.asa
    ... In VB.NET this is still the "Const" keyword (I don't see what you meant by ... Another option would to use VBScript classes. ... > the same time is mute, because you can't have a VBscript constant with> a scope any greater than page scope. ... not the whole VB.NET language. ...
    (microsoft.public.inetserver.asp.general)
  • Re: vbs output to txt file
    ... Easiest is to code the VBScript to echo output to the console, ... Const OpenAsASCII = 0 ... Set objFSO = CreateObject ...
    (microsoft.public.scripting.wsh)
  • Re: How to discover Win2003 Standard or Ent.
    ... Here is a little vbscript that will go through an OU that you define (Will ... Const WARNING_THRESHOLD = 100 ... objConnection.Open "Active Directory Provider" ... Set colLogicalDisk = _ ...
    (microsoft.public.windows.server.active_directory)
  • Re: Bulk User Import Using a VBScript
    ... here is a VBScript program that creates users in bulk from the ... information in an Excel spreadsheet: ... the program to have the Distinguished Name of the parent container for each ... > Const adLockOptimistic = 3 ...
    (microsoft.public.windows.server.active_directory)
  • Re: Replace astericks with spaces in a text file
    ... I'm a newbie at VBScript and I've posted my code here and need some ... Const ForReading = 1 ... Set LogFile = fso.OpenTextFile(LogName, ForWriting, True) ...
    (microsoft.public.scripting.vbscript)