我还不是特别擅长VBA。我收到标题中的错误,该错误指向以If NamePart =
开头的行,并突出显示=
符号。谁知道为什么?
Public Enum NamePart
EnvironmentDefined
FullName
FirstName
LastName
End Enum
Public Function GetUser(Optional ByVal part As NamePart = EnvironmentDefined) As String
Dim result As String
Dim sysInfo As Object
Dim userInfo As Object
If NamePart = EnvironmentDefined Then
GetUser = Environ$("USERNAME")
Exit Function
End If
Set sysInfo = CreateObject("ADSystemInfo")
Set userInfo = GetObject("LDAP://" & sysInfo.UserName)
Select Case NamePart
Case FullName
result = userInfo.FullName
Case FirstName
result = userInfo.GivenName
Case LastName
result = userInfo.LastName
Case Else
result = Environ$("USERNAME")
End Select
GetUser = result
End Function
Private Sub Command363_Click()
Call GetUser
MsgBox "Username: " & GetUser
End Sub
答案 0 :(得分:2)
public String toJsonObject() throws IOException{
String jsonInString = "";
ObjectMapper mapper = new ObjectMapper();
//Object to JSON in String
try {
// Will only include non null objects
mapper.setSerializationInclusion(Inclusion.NON_NULL);
jsonInString = mapper.writeValueAsString(this);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return jsonInString;
}
是一个枚举,这意味着将它用于比较你可能想要询问枚举中的任何一个项是否等于某个值。
NamePart
也
If part = NamePart.EnvironmentDefined Then
请注意,在Select Case part
Case NamePart.FullName
result = userInfo.FullName
Case NamePart.FirstName
result = userInfo.GivenName
Case NamePart.LastName
result = userInfo.LastName
Case Else
result = Environ$("USERNAME")
End Select
之后点击.
时,会显示所有枚举选项。