loop problem

Avatar

Avatar

eugzl

Avatar

eugzl

eugzl

17-04-2018

I would like to create loop to check data entered by user into TextField with all array values in global variable. I tried like this:

var i = 0; 

for (i = 0; i < 3; i++) { 

     if (txtName.rawValue == _Name[i]) { 

          xfa.host.messageBox("Your NAME is correct."); 

     } 

if (i == 3) { 

     xfa.host.messageBox("Your NAME is wrong."); 

where:

      _Name = eval(Names.value) is global variable array value

and

    txtName is TextField where user type data.

When I run the execute that code I got the second message pop up first and then first message . How to fix the problem?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372

Avatar

_Bruce_Robertson

MVP

Total Posts

1.8K

Likes

268

Correct Answer

372
_Bruce_Robertson
MVP

17-04-2018

Hi,

I think you just need a break statement after "Your NAME is correct" message, this will stop the loop and so at the end of the value of I will never be 3.

so;

for (i = 0; i < 3; i++) {  

     if (txtName.rawValue == _Name[i]) {  

          xfa.host.messageBox("Your NAME is correct.");  

          break;

     }  

}

Bruce

Answers (0)