Skip to main content
M.Hasanin
Inspiring
April 18, 2018
Answered

Nested for (for Inserting Continues Numbers in Text Fields)

  • April 18, 2018
  • 1 reply
  • 1828 views

Hi Brothers and Professionals..

I'm Trying to make a Nested for (for repeating numbers) into fields, I have 16 fields named as (SN1-SN2...SN16), i want the user to enter a Number like 20 and i want to Script to Continues Repeating this Number from 20 to 36 (as Example)..i write the following code into Button But when i hit the Button and Enter the Starting Number it Doesn't work at all, even no error message, its my first time to try Nested for twice so i don't know what is the problem, please help me if you can , thanks in advance:

// Dialog Definition

var oDlg = {

    strName: "", initialize: function(dialog) {

        dialog.load({"usnm":this.strName});

    },

    commit: function(dialog) {

        var data = dialog.store();

        this.strName = data["usnm"];

    },

    description: {

        name: "Test Dialog", elements: [ {

            type: "view", elements: [

                { name: "Please Enter Starting Number ?", type: "static_text", },

                { item_id: "usnm", type: "edit_text", char_width: 3 },

                { type: "ok_cancel", },

            ]

        },]

    }

};

// Dialog Activation

oDlg.strName = "";

    if( "ok" == app.execDialog(oDlg)) {

   var DesNum = oDlg.strName;

   var MaxNum = DesNum+16

for (var i=1 ;i>=16 ;i++){

   for (var x=DesNum ;x>=MaxNum ;x++) {

              this.getField("SN"+i).value = x;

            }

}

}

This topic has been closed for replies.
Correct answer Bernd Alheit

also i tried to enter (17) and after long time it fills all the 16 fields with the same number (17)


Use something like this:

for (var i=1 ;i<=16 ;i++) this.getField("SN"+i).value = DesNum + i - 1;

1 reply

try67
Community Expert
Community Expert
April 18, 2018

Look closely at your first for-loop (line #27)...

M.Hasanin
M.HasaninAuthor
Inspiring
April 18, 2018

Because its 16 Text Fields formatted as Numbers, so i make the loop from 1=1 to 16 and the other one should showing continues numbering from the Entered number,, but i didn't get it, what the wrong in line 27

Mohammad Hasanin
try67
Community Expert
Community Expert
April 18, 2018

Since you're making the same mistake in the line after it I think it's a problem of understanding, not of execution.

The second part of the for-loop definition is not a stop-condition, but a running-condition. When that expression is false, the loop stops, not the other way around, as you have it set up...