Vbscript VBS以列格式输出

Vbscript VBS以列格式输出,vbscript,Vbscript,我正在尝试将.vbs输出放入列中。但是,当我尝试编写代码将输出组织到列中时,我继续得到一个错误-无效的过程调用或参数:“Space” 我想在这方面寻求帮助,谢谢 Call FindPCsThatUserLoggedInto Sub FindPCsThatUserLoggedInto() strUser = InputBox("Enter First Name") strLast = InputBox("Enter Last Name") Const ADS_SCOPE_SUBTREE =

我正在尝试将.vbs输出放入列中。但是,当我尝试编写代码将输出组织到列中时,我继续得到一个错误-无效的过程调用或参数:“Space”

我想在这方面寻求帮助,谢谢

Call FindPCsThatUserLoggedInto

Sub FindPCsThatUserLoggedInto()

strUser = InputBox("Enter First Name")
strLast = InputBox("Enter Last Name")

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

's = "Name" & Chr(9) & "Account Name"  & Chr(9) &  "Location" & Chr(10) & Chr(13)
's = s & "----" & Chr(9) & "------------"  & Chr(9) &  "--------" & Chr(10) & Chr(13)
s = RightJustified("Name", 10) & _
  RightJustified("Account Name", 15) & _
  RightJustified("Location", 15) & _
  vbCrLf

objCommand.CommandText = "SELECT ADSPath FROM 'LDAP://dc=hc,dc=company,dc=com' WHERE givenName = '" & strUser & "*' AND sn = '" & strLast & "*'"

Set objRecordSet = objCommand.Execute

If objRecordSet.Recordcount > 0 Then

    objRecordSet.MoveFirst

    Do Until objRecordSet.EOF

        Set objUser = GetObject(objRecordSet.Fields("ADSPath").Value)

        's = s & objUser.DisplayName & Chr(9) & objUser.samaccountname  & Chr(9) &  objUser.PhysicalDeliveryOfficeName & Chr(10) & Chr(13)

       ' objRecordSet.MoveNext
       s = s & _
  RightJustified(objUser.DisplayName, 10) & _
  RightJustified(objUser.samaccountname, 15) & _
  RightJustified(objUser.PhysicalDeliveryOfficeName, 15) & _
  vbCrLf

    Loop

    MsgBox s

Else

    MsgBox "No users matching that criteria exist in the HC domain in AD."

End If

End Sub

Function RightJustified(ColumnValue, ColumnWidth)
RightJustified = Space(ColumnWidth - Len(ColumnValue)) & ColumnValue
End Function
这是我添加的代码,用于将输出组织到列中:

s = RightJustified("Name", 10) & _
  RightJustified("Account Name", 15) & _
  RightJustified("Location", 15) & _
  vbCrLf

以下是我的输出:

我猜这是一个运行时错误,因为您的数据超过了指定的大小

RightJustified(objUser.DisplayName, 10) & _
RightJustified(objUser.samaccountname, 15) & _
RightJustified(objUser.PhysicalDeliveryOfficeName, 15) & _
vbCrLf
也许需要这样的改变:

Function RightJustified(ColumnValue, ColumnWidth)
  If Len(ColumnValue) > ColumnWidth Then
     ColumnValue = Left(ColumnValue,ColumnWidth)
  End If
  RightJustified = Space(ColumnWidth - Len(ColumnValue)) & ColumnValue
End Function

哪个对
rightjustized
的调用导致了错误,当错误发生时,
ColumnValue
的值是多少?我将列宽值从10更改为20,它工作了-但是,输出文本没有对齐。有办法解决这个问题吗?我还以为你应该这么做呢,这真管用!但是文本在外面没有对齐-到处都是-我如何组织文本?我认为RightJustized应该这样做您不能依靠
MsgBox
来对齐,您应该通过窗口或某种类型的报告显示。您的解决方案有效,因此我将您的解决方案标记为:)。我也有我得到的输出的图片,所以也许你可以告诉我发生了什么。谢谢是的,您没有对齐,因为字体对每个字母大小的处理不同(注意小写字母上的夸张差异),您无法像在控制台类型的应用程序中那样对齐GUI中的文本。您需要使用DataGridView或报表控件…我将尝试一下,看看是否可以让它工作。
Function RightJustified(ColumnValue, ColumnWidth)
  If Len(ColumnValue) > ColumnWidth Then
     ColumnValue = Left(ColumnValue,ColumnWidth)
  End If
  RightJustified = Space(ColumnWidth - Len(ColumnValue)) & ColumnValue
End Function