Microsoft KB Archive/197968

= How To Iterate Script Objects Using JavaScript =

Article ID: 197968

Article Last Modified on 7/2/2004

-

APPLIES TO


 * Microsoft Visual InterDev 6.0 Standard Edition

-



This article was previously published under Q197968



SUMMARY
In some cases, you may find it convenient to loop through a large number of script objects created by Design-Time Controls (DTCs). Although you cannot index these objects in an array, you can use the JavaScript eval function directly or indirectly to achieve the same result. This article demonstrates how you can loop through the script objects using JavaScript.



MORE INFORMATION
The following code constructs the three textbox script objects in a loop and then initializes them in a loop. (You may find it easier to convert a Textbox DTC to runtime text permanently first and customize its runtime code.)  function _initTextbox1 {    for (i=1; i<=3; i++) {     eval('Textbox' + i + '.setStyle(TXT_TEXTBOX);') eval('Textbox' + i + '.setMaxLength(20);') eval('Textbox' + i + '.setColumnCount(20);')

}  }

function _Textbox1_ctor {     for (i=1; i<=3; i++) CreateTextbox('Textbox' + i, _initTextbox2, null);

}

<%     for (i=1; i<=3; i++) eval ('Textbox' + i + '.display;') %> The following code segment clears the three textboxes in a loop: 

function Button1_onclick { var i;  for (i=1; i<=3; i++) eval("Textbox" + i + ".value='';") }   Since eval is a JavaScript intrinsic function and not available in VBScript, you will have to use it indirectly if you are programming in VBScript. To clear the three textboxes in a loop in VBScript, you may use the following code, which introduces an additional function evalit:  Sub Button1_onclick Dim i     For i = 1 to 3 evalit "Textbox" & i & ".value = " & " 'howdy' " Next End Sub 



function evalit(str) {     eval(str); }   This is similar to the sample given in JavaScript, except the VBScript code calls the eval method indirectly by calling the JavaScript function evalit.

Keywords: kbhowto kbscript kbctrl KB197968

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.