locked
What does vbScript argument "[in]" mean?? RRS feed

  • Question

  • I must have written hundreds, mostly small, some rather big, vbScripts over the years, but I can't remember ever having seen an argument described as [in] or [in, optional] before.

    Or maybe I just haven't bothered before, but now that I do bother it's turning out to be a waste of time trying to google it since google doesn't care for non-alphanumerics like ][ etc or for that matter, all the ubiquitous itsy-bitsy particles like 'in'.

    I happened upon this annoying [in] and also [in, optional] when looking up the Shell.ShellExecute method at
    docs.microsoft.com/en-us/windows/desktop/shell/shell-shellexecute

    but without a mention what in the world 'in' stands for. Does it stand for an 'in' variable? Rather silly in that case since it's an argument so yeah, its an 'in' variable, as opposed to an 'out' like a return value or a pointer to some data..?

    So if anyone knows of a confirmed official source that explains this I'd like a link to it, please.

    Thanks!


    • Edited by TheRealZwaa Wednesday, November 21, 2018 6:57 PM
    Wednesday, November 21, 2018 6:56 PM

Answers

  • But the description is for VB and not VBScript. 

    The following is a VB method definition.  Yes it almost states a VBScript version BUT?

    Shell.ShellExecute( _
      ByVal sFile As BSTR, _
      [ ByVal vArguments As Variant ], _
      [ ByVal vDirectory As Variant ], _
      [ ByVal vOperation As Variant ], _
      [ ByVal vShow As Variant ] _
    ) As Integer

    Note the optional and note that the first parameter is a BSTR.  In VBScript all parameters are Variant and all returns are Variant.  The person who updated this just copied the VB docs.  It is misleading.  The doc gives a correct call structure for JScript and VB but not for VBScript.

    All variables and constants in VBScript are Variants.  The COM marshaler does convert the first variant to a BSTR because all string variants in VBScript are wrappers around BSTR.

    InVBScript we do not declare arguments an in/out Any Variant can receive a value or send a value. 

    Of course knowing this is good but many users see this document and assume VBScript supports the syntax like this.

    Set shell = CreateObject("Shell.Application")
    Dim return As Integer
    return = shell.ShellExecute(....)

    Which won't work.

    The documentation is useful and not misleading once you understand how that works.  The original documentation was much better.

    Perhaps the easiest thing to say is that the [in/out/optional] are just hints and not declarations in vbscript. We cannot do this:

    function Test(ByVal p1 [in], ByVal P2 [out,optional]}

    That only works in VB.

    Do you see my point?


    \_(ツ)_/



    • Edited by jrv Thursday, November 22, 2018 1:14 AM
    • Marked as answer by TheRealZwaa Thursday, November 22, 2018 3:16 AM
    Thursday, November 22, 2018 1:10 AM

All replies

  • The only "In" I know of is used in For Each loops. For example:

    For Each objDisk In colDisks

    Edit: Documentation for "For Each /Next":

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-each-next-statement

    Edit: Looking at the document you linked, I don't believe [in] or [in, optional] is part of the language. Rather it must indicate that the parameter described is an input value (as you guessed), and perhaps also optional. Maybe there is a Doc for documentation syntax explaining this.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)



    Wednesday, November 21, 2018 7:17 PM
  • In a syntax description, the [in] means "this is an input parameter." Most parameters are this kind. Optional means what it says.

    If you see [out], it means that the parameter is an output parameter (that is, it receives a value when the function completes). (You will see [out] in a number of WMI object methods.) Output parameters are typical when a method needs to return multiple kinds of data (e.g., a string and also an error code).

    I don't have a "confirmed official source," but that is indeed what they mean.


    -- Bill Stewart [Bill_Stewart]


    • Edited by Bill_Stewart Wednesday, November 21, 2018 7:47 PM
    Wednesday, November 21, 2018 7:42 PM
  • VBScript does not have "in", "optional" or "out" declarations.  What you are seeing is not VBScript documentation or code. It is for VB.Net  and was posted in that document by the new guys doing their best to screw up all of the finally fixed MSDN and TechNet documentation.


    \_(ツ)_/

    Wednesday, November 21, 2018 7:57 PM
  • The [in], [in, optional], and [out] indicators are not part of the language syntax itself. They are part of the syntax description to aid the programmer in describing what kind of parameter is in use. (jrv is correct that these indicators are not language-specific.) For example:

    https://docs.microsoft.com/en-us/previous-versions/windows/desktop/regprov/enumkey-method-in-class-stdregprov

    In this example, the EnumKey method has 3 parameters: hDefKey (a unit32 input parameter), sSubkeyName (a string input parameter), and sNames (an output array).


    -- Bill Stewart [Bill_Stewart]

    Wednesday, November 21, 2018 11:56 PM
  • But the description is for VB and not VBScript. 

    The following is a VB method definition.  Yes it almost states a VBScript version BUT?

    Shell.ShellExecute( _
      ByVal sFile As BSTR, _
      [ ByVal vArguments As Variant ], _
      [ ByVal vDirectory As Variant ], _
      [ ByVal vOperation As Variant ], _
      [ ByVal vShow As Variant ] _
    ) As Integer

    Note the optional and note that the first parameter is a BSTR.  In VBScript all parameters are Variant and all returns are Variant.  The person who updated this just copied the VB docs.  It is misleading.  The doc gives a correct call structure for JScript and VB but not for VBScript.

    All variables and constants in VBScript are Variants.  The COM marshaler does convert the first variant to a BSTR because all string variants in VBScript are wrappers around BSTR.

    InVBScript we do not declare arguments an in/out Any Variant can receive a value or send a value. 

    Of course knowing this is good but many users see this document and assume VBScript supports the syntax like this.

    Set shell = CreateObject("Shell.Application")
    Dim return As Integer
    return = shell.ShellExecute(....)

    Which won't work.

    The documentation is useful and not misleading once you understand how that works.  The original documentation was much better.

    Perhaps the easiest thing to say is that the [in/out/optional] are just hints and not declarations in vbscript. We cannot do this:

    function Test(ByVal p1 [in], ByVal P2 [out,optional]}

    That only works in VB.

    Do you see my point?


    \_(ツ)_/



    • Edited by jrv Thursday, November 22, 2018 1:14 AM
    • Marked as answer by TheRealZwaa Thursday, November 22, 2018 3:16 AM
    Thursday, November 22, 2018 1:10 AM
  • Wow, I did not expect this activity. I would've been happy if anyone had said anything within a week..

    Apparently it's an engaging question and totally justifiable :-D

    And who knows, this thread might serve others who like me wants to know all the tid-bits of the language.

    So thank you for your thorough probing of the subject matter, much obliged. I wanna weigh in on a coupla points:

    Yes, I'm used to MS messing up VBScript documentation with Visual Basic(VB), as implied this is old news and I've learned to live with that, for the most part it's not difficult to apply the VB documentation onto the VBScript counterparts. In fact I'm so used to it that I didn't think of the BSTR type, good observation with that one. So this turned out to be more of a VB question than a VBScript one then but still, good to know what they mean by [in] , the term 'optional' was kinda obvious but I just mentioned it because all of the arguments except for one states optional in conjunction with in. Incidentally, as for 'out' I'm versed in C so I'm used to data explicitly being stuffed as 'out' at the address of a pointer first being received(the receiving part of course being a necessity in any language but implicitly though, with strings first and foremost) as an 'in' argument so that makes for both in and out simultaneously, what do they call that, something naughty? :-D

    So anyway, the whole concept of this pernickety for something that's so obvious is just silly to me, they would've been better off not adding the 'in' at all in the first place, it's just confusing(hence the interrest in the subject, perhaps).

    Still, now we all know the ins and outs of VB and VBScript arguments ;-)

    Cheers!

    Anders

    Thursday, November 22, 2018 4:11 AM