2011-07-31 1 views
0

여기서 내가 잘못 될 부분을 이해하려고합니다. 다음 스크립트는 항상 배열의 끝에 빈 항목을 반환합니다. 왜? 나는 그것이 레코드 세트에 문제가 있다고 생각하지 않는다. 어떤 아이디어?연결 및 분할 반환 ubound (array) + 1 items

function allServers 
    Set adoCommand = CreateObject("ADODB.Command") 
    Set adoConnection = CreateObject("ADODB.Connection") 
    adoConnection.Provider = "ADsDSOObject" 
    adoConnection.Open "Active Directory Provider" 
    Set adoCommand.ActiveConnection = adoConnection 

    Set objRootDSE = GetObject("LDAP://RootDSE") 

    strDNSDomain = objRootDSE.Get("defaultNamingContext") 
    strBase = "<LDAP://" & strDNSDomain & ">" 
    strFilter = "(&(objectCategory=computer)(operatingsystem=*server*)(!userAccountControl:1.2.840.113556.1.4.803:=2))" 
    strAttributes = "name,distinguishedname,dnshostname" 
    strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree" 
    adoCommand.CommandText = strQuery 
    adoCommand.Properties("Page Size") = 100 
    adoCommand.Properties("Timeout") = 30 
    adoCommand.Properties("Cache Results") = False 

    Set adoRecordset = adoCommand.Execute 
    dim strList, i 
    Do Until adoRecordset.EOF 
     strList = strList & adoRecordSet.Fields("name").Value & "," 
    adoRecordset.MoveNext 
    loop 
    adoRecordset.Close 
    adoConnection.Close 

    arr = split(strList, ",",-1,1) 
    allServers = arr 
end function 

arr = allservers 
For i = 0 to UBound(arr) 
    wscript.echo i & ":" & arr(i) 
next 

답변

0

루프 :

Do Until adoRecordset.EOF 
    strList = strList & adoRecordSet.Fields("name").Value & "," 
    adoRecordset.MoveNext 
loop 

이 strList의 끝에 ","마지막/뒤/종료를 둔다. Split()은 ","를 구분 기호 (종결자가 아님)로 취급하므로 결과 배열에 허위 마지막 비어있는 요소가 있습니다.

이렇게하려면 루프에서 "," & value을 연결하고 Mid()를 사용하여 앞의 ","을 압축 할 수 있습니다. 하지만 "SELECT COUNT"또는 Recordset.Count를 사용하여 루프 앞에 배열의 크기를 지정하고 해당 요소에 값을 할당하거나, 더 나은 - Recordset.GetRows()를 사용하여 직접 (2 차원이지만) 배열을 직접 가져 오지 않고 -> 아니 연결, 아니 분할, 아무 문제.

+0

답장을 보내 주셔서 감사합니다. 루프에서 값을 지정하기로했습니다. Active Directory 공급자가 .Count를 지원하지 않는 것 같습니다. – yajohn