Problem With an Undefined Variable

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

    Problem With an Undefined Variable

    I am having a problem when a field is spaces being undefined. I wasn't
    sure if the problem was Excel or Javascript, so I thought I would post
    here first.

    The users are able to select from a drop down list either a
    pre-existing Excel spreadsheet or a blank spreadsheet where they can
    enter the data. When they click the Store button I am using Javascript
    to validate the fields. If a particular field is not entered or has
    invalid data, then an error message will appear on the screen. In this
    case, I was testing for a blank field and did not get the error
    message I was expecting. So I put in some Response.Write statements to
    display what was in the field and in this case is where it came back
    as undefined. If there is data in the field, then the field displays
    correctly. The following is an example of the code:

    do
    {
    indexRow+=1;
    }
    while (mExcelApp.Acti veSheet.Cells(i ndexRow, 1) != "RECORD");
    indexRow+=2;

    RecordCount = 0;

    do
    {

    var xlSourceDoc = mExcelApp.Activ eSheet.Cells(in dexRow, 2);
    var xlRefNumber = mExcelApp.Activ eSheet.Cells(in dexRow, 3);
    var xlFYR = mExcelApp.Activ eSheet.Cells(in dexRow, 4);
    var xlClass = mExcelApp.Activ eSheet.Cells(in dexRow, 5);
    var xlNNNNN = mExcelApp.Activ eSheet.Cells(in dexRow, 6);
    var xlAAAA = mExcelApp.Activ eSheet.Cells(in dexRow, 7);
    var xlLLLL = mExcelApp.Activ eSheet.Cells(in dexRow, 8);
    var xlFFF = mExcelApp.Activ eSheet.Cells(in dexRow, 9);
    var xlLineDollarAmt = mExcelApp.Activ eSheet.Cells(in dexRow, 10);
    var xlLineUnits = mExcelApp.Activ eSheet.Cells(in dexRow, 11);
    var xlLineDesc = mExcelApp.Activ eSheet.Cells(in dexRow, 12);

    if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
    == "undefined" ))
    {
    mError = 11;
    mResults = showErrorMsg();
    break;
    }
    RecordCount+=1;
    indexRow+=1;
    }
    while (RecordCount < xlRecCnt);

    In showErrorMsg() is where I have my error messages and mError = 11
    returns a particular message.

    Being fairly new to both Excel and Javascript, I am at a lost as to
    how to correct the problem. Does anyone have an idea what I need to
    do? TIA for any help!

    Mike
  • kaeli

    #2
    Re: Problem With an Undefined Variable

    In article <2ec1fa48.03072 81023.6f3818e8@ posting.google. com>,
    wolverine1654@y ahoo.com enlightened us with...[color=blue]
    > I am having a problem when a field is spaces being undefined. I wasn't
    > sure if the problem was Excel or Javascript, so I thought I would post
    > here first.
    >[/color]

    <snip>
    [color=blue]
    >
    > if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
    > == "undefined" ))[/color]

    Test for null first, then undefined, then for spaces. Order matters. It
    can't test for spaces if it doesn't exist or is undefined. It can't test
    for "undefined" if the object ref is null.

    HTH


    -------------------------------------------------
    ~kaeli~
    Black holes were created when God divided by 0.
    Not one shred of evidence supports the notion
    that life is serious.


    -------------------------------------------------

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Problem With an Undefined Variable

      kaeli <infinite.possi bilities@NOSPAM att.net> writes:
      [color=blue]
      > In article <2ec1fa48.03072 81023.6f3818e8@ posting.google. com>,[color=green]
      > >
      > > if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
      > > == "undefined" ))[/color]
      >
      > Test for null first, then undefined, then for spaces. Order matters. It
      > can't test for spaces if it doesn't exist or is undefined. It can't test
      > for "undefined" if the object ref is null.[/color]

      It doesn't matter. There is no significant difference between comparing
      to "null" and to "undefined" or the empty string. You can write
      null == "undefined"
      and it is false.

      In fact, when you use "==" for comparison, some of the cases are
      equivalent, since "==" performs type conversion before converting.
      This conversion means that
      null == undefined
      (however, in the code above, it is not the value "undefined" that is
      compared to, but the string containing the word "undefined" ).

      Where it makes a difference is when you access properties of objects.
      You cannot access the properties of the values "null" or "undefined" .
      Other values are converted to objects when you try, but those two
      are not.
      The following are legal, and give the result "undefined" .
      ("dims").foo
      (2).foo
      (false).foo
      These two are illegal, and give an error (an Exception of type
      TypeError):
      null.foo
      undefined.foo

      /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

      • kaeli

        #4
        Re: Problem With an Undefined Variable

        In article <u196ieb7.fsf@h otpop.com>, lrn@hotpop.com enlightened us
        with...[color=blue]
        >
        > Where it makes a difference is when you access properties of objects.[/color]

        Which is as far as I can tell, what the OP was doing.

        Did I misread the code?

        var xlSourceDoc = mExcelApp.Activ eSheet.Cells(in dexRow, 2);
        ....
        if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
        == "undefined" ))

        That is a cell, isn't it, which is an object with properties, including
        a value, color, etc?

        -------------------------------------------------
        ~kaeli~
        Black holes were created when God divided by 0.
        Not one shred of evidence supports the notion
        that life is serious.


        -------------------------------------------------

        Comment

        • Mike

          #5
          Re: Problem With an Undefined Variable

          > Where it makes a difference is when you access properties of objects.[color=blue]
          >
          > Which is as far as I can tell, what the OP was doing.
          >
          > Did I misread the code?
          >
          > var xlSourceDoc = mExcelApp.Activ eSheet.Cells(in dexRow, 2);
          > ...
          > if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
          > == "undefined" ))
          >
          > That is a cell, isn't it, which is an object with properties, including
          > a value, color, etc?
          >
          > -------------------------------------------------
          > ~kaeli~
          > Black holes were created when God divided by 0.
          > Not one shred of evidence supports the notion
          > that life is serious.
          > http://www.ipwebdesign.net/wildAtHeart
          > http://www.ipwebdesign.net/kaelisSpace
          > -------------------------------------------------[/color]

          Yes, this is a reference to a particular cell. IndexRow gets added to
          keep track of what row is currently being processed on the
          spreadsheet. I reversed the order of above If statement and tested for
          null, then undefined, then spaces and I still got the same result. Is
          there another way to reference a cell which is an object with
          properties? Thanks!

          Mike

          Comment

          Working...