473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.ActiveSheet.Cells(indexRow, 1) != "RECORD");
indexRow+=2;

RecordCount = 0;

do
{

var xlSourceDoc = mExcelApp.ActiveSheet.Cells(indexRow, 2);
var xlRefNumber = mExcelApp.ActiveSheet.Cells(indexRow, 3);
var xlFYR = mExcelApp.ActiveSheet.Cells(indexRow, 4);
var xlClass = mExcelApp.ActiveSheet.Cells(indexRow, 5);
var xlNNNNN = mExcelApp.ActiveSheet.Cells(indexRow, 6);
var xlAAAA = mExcelApp.ActiveSheet.Cells(indexRow, 7);
var xlLLLL = mExcelApp.ActiveSheet.Cells(indexRow, 8);
var xlFFF = mExcelApp.ActiveSheet.Cells(indexRow, 9);
var xlLineDollarAmt = mExcelApp.ActiveSheet.Cells(indexRow, 10);
var xlLineUnits = mExcelApp.ActiveSheet.Cells(indexRow, 11);
var xlLineDesc = mExcelApp.ActiveSheet.Cells(indexRow, 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
Jul 20 '05 #1
4 6653
In article <2e**************************@posting.google.com >,
wo***********@yahoo.com enlightened us with...
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.

<snip>

if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
== "undefined"))


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.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #2
kaeli <in********************@NOSPAMatt.net> writes:
In article <2e**************************@posting.google.com >,

if ((xlSourceDoc == "") || (xlSourceDoc == null) || (xlSourceDoc
== "undefined"))


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.


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
In article <u1**********@hotpop.com>, lr*@hotpop.com enlightened us
with...

Where it makes a difference is when you access properties of objects.


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

Did I misread the code?

var xlSourceDoc = mExcelApp.ActiveSheet.Cells(indexRow, 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
-------------------------------------------------
Jul 20 '05 #4
> Where it makes a difference is when you access properties of objects.

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

Did I misread the code?

var xlSourceDoc = mExcelApp.ActiveSheet.Cells(indexRow, 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
-------------------------------------------------


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
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: os2 | last post by:
hi in bd.php i do: <?php $serveur = "localhost"; $utilisateur = "root"; $motDePasse = ""; $base = "laboiteaprog";
7
by: melty | last post by:
This line of code make an "Undefined index" error on my PC, however it is okay on my friend's PC. Anyone has this experience? $somevar = $_REQUEST;
7
by: Coder Droid | last post by:
I decided to run some code with errors set to E_ALL, just to see what I would run across. It caught a few things, but 90% or better of the messages were of the 'undefined' kind: PHP Notice: ...
20
by: rhino | last post by:
This worked before October now it does not work. I think I know where the trouble is but I don't know how to fix it. function findVerse() { var d = new Date(); var str; if( (...
4
by: Chris Beall | last post by:
If you want your code to be bulletproof, do you have to explicitly check for the existence of any possibly-undefined variable? Example: window.outerHeight is defined by some browsers, but not...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
7
by: Marcelo | last post by:
Hi everybody, I don't understand why I am having a problem in this code. The problem is that my pointer *phist in main method, it is declared. Then I send the pointer to my method, and this...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
22
by: V S Rawat | last post by:
(bringing the discussion here for php.general) I am on xpsp3, wampserver 2.0, having apache 2.2.8, php 5.2.6, MySQL 5.0.51b. http://localhost/ is E:\wamp\www\ I have put the first php script...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.