JavaScript vs. VBScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Richards

    JavaScript vs. VBScript

    In VbScript, when you have a method, you do
    ..Method A, B, C, D. If you would take some default values, you do
    ..Method A,,,D

    My question is that how you can do this in JavaScript
    ..Method(???)

    Thanks.

    Derek
  • Lasse Reichstein Nielsen

    #2
    Re: JavaScript vs. VBScript

    Derek2122001@ya hoo.com (Derek Richards) writes:
    [color=blue]
    > In VbScript, when you have a method, you do
    > .Method A, B, C, D. If you would take some default values, you do
    > .Method A,,,D
    >
    > My question is that how you can do this in JavaScript
    > .Method(???)[/color]

    This question was asked a few days ago. The answer still is that you
    don't. In Javascript you cannot omit parameters in the middle of the list,
    only from some point on.

    Omitted parameters in Javascript gives the value "undefined" to the
    argument variables, so you can pass "undefined" instead.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Derek Richards

      #3
      Re: JavaScript vs. VBScript

      Here is some syntax.
      expression.Open (FileName, UpdateLinks, ReadOnly, Format, Password,
      WriteResPasswor d, IgnoreReadOnlyR ecommended, Origin, Delimiter,
      Editable, Notify, Converter, AddToMRU)

      In javascript how to omit a few parameters and at the same time,
      change some default values? Say for the parrameters UpdateLinks,
      ReadOnly and IgnoreReadOnlyR ecommended correspondingly , I would like
      to choose values 2, false and true (in javascript, is true and false
      the same as 0 and 1). How to express them in javascript?
      ..open(captured File, ?,?)




      Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<n0c4pb9h. fsf@hotpop.com> ...[color=blue]
      > Derek2122001@ya hoo.com (Derek Richards) writes:
      >[color=green]
      > > In VbScript, when you have a method, you do
      > > .Method A, B, C, D. If you would take some default values, you do
      > > .Method A,,,D
      > >
      > > My question is that how you can do this in JavaScript
      > > .Method(???)[/color]
      >
      > This question was asked a few days ago. The answer still is that you
      > don't. In Javascript you cannot omit parameters in the middle of the list,
      > only from some point on.
      >
      > Omitted parameters in Javascript gives the value "undefined" to the
      > argument variables, so you can pass "undefined" instead.
      >
      > /L[/color]

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: JavaScript vs. VBScript

        Derek2122001@ya hoo.com (Derek Richards) writes:
        [color=blue]
        > Here is some syntax.
        > expression.Open (FileName, UpdateLinks, ReadOnly, Format, Password,
        > WriteResPasswor d, IgnoreReadOnlyR ecommended, Origin, Delimiter,
        > Editable, Notify, Converter, AddToMRU)
        >
        > In javascript how to omit a few parameters and at the same time,
        > change some default values? Say for the parrameters UpdateLinks,
        > ReadOnly and IgnoreReadOnlyR ecommended correspondingly , I would like
        > to choose values 2, false and true (in javascript, is true and false
        > the same as 0 and 1).[/color]

        No. Javascript has the boolean values true and false that are distict
        from numbers. However, if used in a boolean setting, 0 and 1 convert
        to the booleans false and true respectively.
        [color=blue]
        > How to express them in javascript? .open(capturedF ile, ?,?)[/color]

        expression.Open (capturedFile, 2, false, undefined, undefined, undefined, true)

        This will give the value "undefined" to, e.g., Format, which is the same
        value it would get if the argument is omitted.

        There is no notion of default values in Javascript. An omitted argument
        becomes undefined.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Derek Richards

          #5
          Re: JavaScript vs. VBScript

          I tried the syntax you gave me. Having Visual Studio 6.0 installed, I
          got a Runtime Error: Open Method of Workbooks Class Failed! My
          intention was also to remove the (Read-Only) above the MenuBar on the
          upper left corner when an excel file is opened.

          I also changed to expression.Open (capturedFile, undefined, false,
          undefined, undefined, undefined, true). Still got the same error
          message.

          Do you have any suggestion? Thanks.


          Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<ptgznzs5. fsf@hotpop.com> ...[color=blue]
          > Derek2122001@ya hoo.com (Derek Richards) writes:
          >[color=green]
          > > Here is some syntax.
          > > expression.Open (FileName, UpdateLinks, ReadOnly, Format, Password,
          > > WriteResPasswor d, IgnoreReadOnlyR ecommended, Origin, Delimiter,
          > > Editable, Notify, Converter, AddToMRU)
          > >
          > > In javascript how to omit a few parameters and at the same time,
          > > change some default values? Say for the parrameters UpdateLinks,
          > > ReadOnly and IgnoreReadOnlyR ecommended correspondingly , I would like
          > > to choose values 2, false and true (in javascript, is true and false
          > > the same as 0 and 1).[/color]
          >
          > No. Javascript has the boolean values true and false that are distict
          > from numbers. However, if used in a boolean setting, 0 and 1 convert
          > to the booleans false and true respectively.
          >[color=green]
          > > How to express them in javascript? .open(capturedF ile, ?,?)[/color]
          >
          > expression.Open (capturedFile, 2, false, undefined, undefined, undefined, true)
          >
          > This will give the value "undefined" to, e.g., Format, which is the same
          > value it would get if the argument is omitted.
          >
          > There is no notion of default values in Javascript. An omitted argument
          > becomes undefined.
          >
          > /L[/color]

          Comment

          • Steve van Dongen

            #6
            Re: JavaScript vs. VBScript

            On 15 Oct 2003 10:10:57 -0700, Derek2122001@ya hoo.com (Derek Richards)
            wrote:
            [color=blue]
            >I tried the syntax you gave me. Having Visual Studio 6.0 installed, I
            >got a Runtime Error: Open Method of Workbooks Class Failed! My
            >intention was also to remove the (Read-Only) above the MenuBar on the
            >upper left corner when an excel file is opened.
            >
            >I also changed to expression.Open (capturedFile, undefined, false,
            >undefined, undefined, undefined, true). Still got the same error
            >message.
            >
            >Do you have any suggestion? Thanks.[/color]

            You can try using null but I doubt that will work either. The only
            sure way is to specify a default parameter to an ActiveX method is to
            pass Nothing, and you can use the JArgUtil ActiveX object for that.


            Regards,
            Steve

            Comment

            • Derek Richards

              #7
              Re: JavaScript vs. VBScript

              This is really subtle. After some changes such as changing to null,
              although teh error message is gone and i specified to open in Write
              mode (Read Only is false), it doesn't do the way I wished to open in
              Write mode. Instead, saw (Read Only) above the MenuBar on the upper
              left corner when an excel file is opened. The previously-posted syntax
              is what I found under the Help in Excel's VBA Editor (you may refer to
              it for details of each parameter).


              Syntax

              expression.Open (FileName, UpdateLinks, ReadOnly, Format, Password,
              WriteResPasswor d, IgnoreReadOnlyR ecommended, Origin, Delimiter,
              Editable, Notify, Converter, AddToMRU)


              UpdateLinks is supposed to be a Variant datatype in VBA. How about in
              javascript (simply using undefined to take its default value)? How to
              specify the parameters to open in Write mode?

              Thanks very much.


              Steve van Dongen <stevevd@hotmai l.com> wrote in message news:<eo4rovovk va9kpiccmtq5gdt 08k3cm0gml@4ax. com>...[color=blue]
              > On 15 Oct 2003 10:10:57 -0700, Derek2122001@ya hoo.com (Derek Richards)
              > wrote:
              >[color=green]
              > >I tried the syntax you gave me. Having Visual Studio 6.0 installed, I
              > >got a Runtime Error: Open Method of Workbooks Class Failed! My
              > >intention was also to remove the (Read-Only) above the MenuBar on the
              > >upper left corner when an excel file is opened.
              > >
              > >I also changed to expression.Open (capturedFile, undefined, false,
              > >undefined, undefined, undefined, true). Still got the same error
              > >message.
              > >
              > >Do you have any suggestion? Thanks.[/color]
              >
              > You can try using null but I doubt that will work either. The only
              > sure way is to specify a default parameter to an ActiveX method is to
              > pass Nothing, and you can use the JArgUtil ActiveX object for that.
              > http://torrboy.customer.netspace.net.au/code/jargutil/
              >
              > Regards,
              > Steve[/color]

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: JavaScript vs. VBScript

                Lasse Reichstein Nielsen wrote:
                [color=blue]
                > [...] Javascript has the boolean values true and false that are distict
                > from numbers. However, if used in a boolean setting, 0 and 1 convert
                > to the booleans false and true respectively.[/color]

                The explanation is incomplete. In Boolean expressions or expressions that
                are evaluated as such (like in conditional statements) all numbers different
                from 0 and -0 evaluate to `true':


                [color=blue][color=green]
                >> How to express them in javascript? .open(capturedF ile, ?,?)[/color]
                >
                > expression.Open (capturedFile, 2, false, undefined, undefined, undefined, true)
                >
                > This will give the value "undefined" to, e.g., Format, which is the same
                > value it would get if the argument is omitted.[/color]

                Unfortunately, IE < 5.5 does not implement the `undefined'
                value. However they know `window.undefin ed'. But I would
                choose `null' here instead.
                [color=blue]
                > There is no notion of default values in Javascript. An omitted argument
                > becomes undefined.[/color]

                Correct, and (JFTR) therefore you can specify default values in the function
                body like

                function foobar(arg1, arg2)
                {
                if (!arg2)
                arg2 = "bla";
                }

                or if `arg2' is allowed to be false, 0, -0 or a reference to an object
                (even `null'):

                function foobar(arg1, arg2)
                {
                if (typeof arg2 != "undefined" )
                arg2 = "bla";
                }


                PointedEars

                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: JavaScript vs. VBScript

                  Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
                  [color=blue]
                  > The explanation is incomplete. In Boolean expressions or expressions that
                  > are evaluated as such (like in conditional statements) all numbers different
                  > from 0 and -0 evaluate to `true':
                  >
                  > http://devedge.netscape.com/library/...v.html#1008323[/color]

                  Almost. The number NaN is also falsey. NaN stands for Not-a-Number,
                  which is (counterintuiti vely) a value of type number in Javascript -
                  typeof NaN == "number"

                  To be exact, the following values are converted to false by the
                  Boolean function and in any location that expects a boolean value (if,
                  while, and second argument of for-statements):

                  0, -0, NaN, false, "" (empty string), null, undefined

                  (0 and -0 are really only distinguishable internally, the programmer can't
                  tell the difference).

                  All other values are converted to true.

                  There is a special connection between 0/1 and true/false. If you convert
                  a boolean to a number, it is converted to 0 or 1.
                  [color=blue]
                  > Unfortunately, IE < 5.5 does not implement the `undefined'
                  > value. However they know `window.undefin ed'.[/color]

                  No more than it "knows" window.arglebar gle. The value of a property
                  access of a non-eksisting property is undefined. Which is why a simple
                  line can make sure that "undefined" is a defined variable:
                  window.undefine d = window.undefine d;
                  (browsers where window is the global object only, ofcourse).
                  [color=blue]
                  > But I would choose `null' here instead.[/color]

                  You could use the null value, but it is not the same as not passing
                  the argument. It even has a different type according to the "typeof"
                  operator.

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: JavaScript vs. VBScript

                    Lasse Reichstein Nielsen wrote:
                    [color=blue]
                    > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:[color=green]
                    >> The explanation is incomplete. In Boolean expressions or expressions that
                    >> are evaluated as such (like in conditional statements) all numbers different
                    >> from 0 and -0 evaluate to `true':
                    >>
                    >> http://devedge.netscape.com/library/...v.html#1008323[/color]
                    >
                    > Almost. The number NaN is also falsey. NaN stands for Not-a-Number,
                    > which is (counterintuiti vely) a value of type number in Javascript -
                    > typeof NaN == "number"[/color]

                    ACK
                    [color=blue]
                    > To be exact, [as written in the Guide][/color]

                    Human gateway!!111
                    [color=blue]
                    > There is a special connection between 0/1 and true/false. If you convert
                    > a boolean to a number, it is converted to 0 or 1.[/color]

                    ACK
                    [color=blue][color=green]
                    >> Unfortunately, IE < 5.5 does not implement the `undefined'
                    >> value. However they know `window.undefin ed'.[/color]
                    >
                    > No more than it "knows" window.arglebar gle. The value of a property
                    > access of a non-eksisting property is undefined.[/color]

                    Could be that it does not exist by default, I did not test it but read
                    about the possibility in dcljs a few days ago. It seems appropriate to
                    use window.undefine d since `undefined' is not a reserved word and it is
                    unlikely that it has other meaning (in the DOM.)
                    [color=blue]
                    > Which is why a simple
                    > line can make sure that "undefined" is a defined variable:
                    > window.undefine d = window.undefine d;[/color]

                    Who the heck would do that???ßß
                    [color=blue][color=green]
                    >> But I would choose `null' here instead.[/color]
                    >
                    > You could use the null value, but it is not the same as not passing
                    > the argument.[/color]

                    I know but `undefined' is not either, since arguments.lengt h changes
                    when it is used as last argument. And we are talking about arguments
                    in the middle here.
                    [color=blue]
                    > It even has a different type according to the "typeof" operator.[/color]

                    Of course, and that can be helpful.


                    PointedEars

                    Comment

                    • Lasse Reichstein Nielsen

                      #11
                      Re: JavaScript vs. VBScript

                      Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
                      [color=blue]
                      > Lasse Reichstein Nielsen wrote:[/color]
                      [color=blue]
                      > Could be that it does not exist by default, I did not test it but read
                      > about the possibility in dcljs a few days ago. It seems appropriate to
                      > use window.undefine d since `undefined' is not a reserved word and it is
                      > unlikely that it has other meaning (in the DOM.)[/color]

                      I don't have access to IE<6, so I can't test it. It is quite possible
                      that "undefined" is not a global variable (i.e., a property of the
                      global object, which can also be accessed through the global variable
                      "window"). It is the case for Netscape 3, and I think I heard it fro
                      some other browsers too.

                      It is appropriate to use "window.undefin ed" for a way to get an
                      undefined value, since it will work correctly if "undefined" is
                      defined too.
                      [color=blue][color=green]
                      > > window.undefine d = window.undefine d;[/color]
                      >
                      > Who the heck would do that???ßß[/color]

                      Me. If I target platforms where there might not be a global "undefined"
                      variable, this is the simplest way to make sure there is one. If you want
                      it to work on the global object without assuming the name "window", you
                      can write
                      (function(){thi s.undefined=thi s.undefined;})( )

                      If you are going to write "window.undefin ed" to get an undefined value,
                      you might as well define it once and for all. This assignment is safe
                      if "undefined" exists already. As you say, it is appropriate to use
                      window.undefine d to define undefined :)
                      [color=blue]
                      > I know but `undefined' is not either, since arguments.lengt h changes
                      > when it is used as last argument. And we are talking about arguments
                      > in the middle here.[/color]

                      If we have the function
                      function foo(a,b,c,d,e) { ... }
                      and we only want to pass it the first argument
                      foo(42)
                      then the values of b through e become undefined. That is the behavior
                      expected by omitting arguments, which we can do in Javascript.

                      In Javascript, you cannot omit arguments in the middle. Not even using
                      foo.apply(this,[1,,,,4]);
                      If you test with
                      "3" in arguments
                      then the third argument is declared and has the value undefined.
                      (It is browser dependent whether it is defined when you omit arguments
                      at the end - IE isn't, Opera and Mozilla is)

                      The closest you can get to omitting arguments must be to give them
                      the same value as if they had actually been omitted: undefined.
                      [color=blue][color=green]
                      > > It even has a different type according to the "typeof" operator.[/color]
                      >
                      > Of course, and that can be helpful.[/color]

                      That's a different point, but then the function must be written to
                      recognize the parameter passing convention that null represents omission,
                      not just the null object reference. I think it is misusing null, unless
                      the argument is supposed to always be an object.

                      /L
                      --
                      Lasse Reichstein Nielsen - lrn@hotpop.com
                      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                      'Faith without judgement merely degrades the spirit divine.'

                      Comment

                      • Thomas 'PointedEars' Lahn

                        #12
                        Re: JavaScript vs. VBScript

                        Lasse Reichstein Nielsen wrote:
                        [color=blue]
                        > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:[color=green]
                        >> Lasse Reichstein Nielsen wrote:[/color]
                        >
                        > [snipped because of ACK to known information]
                        >[color=green][color=darkred]
                        >> > It even has a different type according to the "typeof" operator.[/color]
                        >>
                        >> Of course, and that can be helpful.[/color]
                        >
                        > That's a different point, but then the function must be written to
                        > recognize the parameter passing convention that null represents omission,
                        > not just the null object reference. I think it is misusing null, unless
                        > the argument is supposed to always be an object.[/color]

                        Provided that the function takes the middle argument(s) as optional, meaning
                        that it will, to some extent, work if they have not been provided, a
                        conditional statement like

                        if (bar)
                        {
                        ...
                        }
                        else if (...)
                        {
                        ...
                        }
                        else
                        {
                        ...
                        }

                        (where `bar' is a named argument and parts of the code can be omitted, of
                        course) works the same for `undefined', which is risky because it is not
                        backwards compatible in IE, as it works for `null' which is AFAIS
                        cross-browser compatible. So I do not see the point why you insist to use
                        risky `undefined' (even if it's saner according to the specification) when
                        `null' can do exactly the same.


                        PointedEars

                        Comment

                        Working...