Skip to main content
Information Mgmt
New to Lotus
How to buy
Live demos
Technical library
Forums & community
Java™ technology
Open source
SOA and Web services
Web development
My developerWorks
About dW
Submit content

developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum



Sign in to participate PreviousPrevious NextNext

RE: the for is stopping for some reason... my help please..
Stan Rogers 17.Nov.11 10:32 AM Lotus Notes
Domino Designer 7.0.2 FP2 Windows 2000

This isn't an easy function to clean up all by itself, Paul. For instance, we don't know what the DebrX variables are when this is called -- whether they are field names or field objects.

In any case, JavaScript doesn't have "variable variables", so this part can't work:

if ( "Type"+ n != "" || parseFloat("Type" + n) > 0 )

The expression "Type" + n will always evaluate to a string, so when n is 1, you've got the equivalent of:

if ( "Type1" != "" || parseFloat("Type1") > 0 )

Obviously, that's not what you want. You have a choice here. One is to use eval() to turn the string into the code it represents, but eval() is almost never the right option unless you are programming in a functional style (returning a function from a function -- explaining what that means is beyond the scope of this forum, but if you have three or four hours to kill, you can watch the first four lectures of Structure and Interpretation of Computer Programs and have your mind blown). The simpler option is to set up your "Type" variable as an array:

var Type = new Array();
Type[1] = Debr1.value;
Type[2] = Debr2.value;
//and so on

That means your test for the if() loop becomes:

if ( Type[n] != "" || parseFloat( Type[n] ) > 0 )

Now, I have to say that the "n" is really bothering me. It's perfectly valid, but it's unconventional. One should always try to keep to the Principle of Least Astonishment when coding so the person maintaining the code has to think as little as possible. There's a convention for iterator variables (the counters in a for-loop) going back to the dawn of time that says they should be named "i", "j" or "k"; "i" being used for the outer loop, "j" for a loop nested inside the "i" loop, and "k" for a loop nested inside the "j" loop (let's hope you don't see many "k" loops). I see that you're sending an "i" to this function, but I don't see it used anywhere.

You're also making the "n" a global variable because you haven't used the var keyword in the declaration in the for loop. When you use var, you make the variable a local to the loop, so it won't interact with the rest of your code:

for (var i = 0; i < someValue; i++) {...}

Finally, there's the little matter of the test for your for loop:

for(n = 1; n == 5; n++);

The loop can only run while the test (the second term in the parentheses) is true. When n is one, it's not 5, so the loop can't start. It should be:

for (var i = 0; i < 5; i++) {...}

(Feel free to go back to "n" if you absolutely have to -- you'll hurt my feelings, but you won't really hurt the code.)

the for is stopping for some reason... (paul visor 17.Nov.11)
. . RE: the for is stopping for some re... (Stan Rogers 17.Nov.11)
. . . . RE: the for is stopping for some re... (paul visor 17.Nov.11)
. . . . . . RE: the for is stopping for some re... (Stan Rogers 17.Nov.11)
. . . . . . . . RE: the for is stopping for some re... (paul visor 17.Nov.11)
. . . . . . . . . . RE: the for is stopping for some re... (paul visor 17.Nov.11)
. . . . the for is stopping for some reason... (paul visor 17.Nov.11)
. . . . . . RE: the for is stopping for some re... (paul visor 17.Nov.11)

Document Options

  Document options
Print this pagePrint this page

Search this forum

Forum views and search

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Advanced search

Sign In or Register

 Sign In or Register
Sign in
Forgot your password?
Forgot your user name?
Create new registration

Member Tools

RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds


Forum use and etiquette
Native Notes Access
Web site Feedback

Lotus Support

 Lotus Support
IBM Support Portal - Lotus software
Lotus Support documents
Lotus support by product
Lotus support downloads
Lotus support RSS feeds


IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Connections Cloud Developers
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

Lotus Forums

 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
IBM Connections
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
Lotus Enterprise Integration
Lotus Protector
Lotus Quickr
Lotus SmartSuite