0

重新发布的工作代码

(我试图从我的 ActiveX 组件中获取数组,但没有运气。当我运行脚本时,我得到空的消息框,但我知道数组在那里:)

var objMain, objAdapt, lgCount, stMsg = "";

objMain = new ActiveXObject("nnetcom.oMain");

objMain.UnlockComponent("xxx-xxxxx-xxxxx-xx");

objAdapt = new ActiveXObject("nnetcom.oNetworkAdapter");

objAdapt.GetNetworkAdapters(); // Collects Network Adapters

vrAdapters = objAdapt.cName; // cName holds collected Network Adapter names

var vrAdaptVB = new VBArray(vrAdapters);

var vrAdaptJS = vrAdaptVB.toArray();

for (lgCount in vrAdaptJS) {
  stMsg = stMsg + vrAdaptJS[lgCount] + '\r\n'; 
}

WScript.Echo(stMsg);

objAdapt = null
objMain = null
4

3 回答 3

2
var vrAdaptVB = new VBArray(vrAdapters);

var vrAdaptJS = vrAdaptVB.toArray();

stMsg = "";

for (lgCount = 0; lgCount < vrAdaptJS.length; ++lgCount) {
 stMsg = stMsg + vrAdaptJS[lgCount] + '\r\n';
}
于 2012-04-23T20:09:26.480 回答
0

根据汉斯的评论,

for (lgCount in vrAdapt)
{
    stMsg = stMsg + vrAdapt[lgCount] + '\r\n';
}

应该:

for (lgCount in vrAdapt)
{
    stMsg = stMsg + lgCount + '\r\n';
}

因为 lgCount 是元素,而不是索引。

我的错。这个例子有效:

var list = {a:1,b:2,c:3,d:4,e:5};
var msg = "";
for (i in list) {
    msg = msg + list[i]; 
}
//msg = 12345

msg = "";
for (i in list) {
    msg = msg + i; 
}
//msg = abcde

var list = [1,2,3,4,5];
msg = "";
for (i in list) {
    msg = msg + i; 
}
//msg = 01234

msg = "";
for (i in list) {
    msg = msg + list[i]; 
}
//msg = 12345
于 2012-04-22T18:14:27.913 回答
0

或者我第一次发布的答案最简单的方法是:

var vrAdaptVB = new VBArray(vrAdapters);

var vrAdaptJS = vrAdaptVB.toArray();

stMsg = "";

for (lgCount in vrAdaptJS) {
 stMsg = stMsg + vrAdaptJS[lgCount] + '\r\n'; 
}

这个例子也适用于我!

列出网络适配器工作示例

于 2012-04-25T10:18:48.550 回答