首页 > 解决方案 > 卡在签名文件生成的 IF 语句上

问题描述

我正在尝试创建一个签名脚本,但我还不能完全解决这个问题。如果在 AD 中为该用户输入了移动值,我想打印“|M”,If否则只需继续执行脚本的其余部分。(我知道我的If陈述行不通,但我想我会把它留在那里,以明确我想要什么。)

'Contact line
objSelection.Font.Size = 8
objSelection.Font.Color = RGB(0,0,0)
objSelection.TypeText "P: " & strPhone
objSelection.TypeText " | D: " & strDirect

If strmobile = hasvalue Then
    objSelection.typetext " | M: " & strMobile
    If strmobile = empty Then
    EndIf

    objSelection.TypeText " | E: " & strEmail
    objSelection.TypeText " | W: " & strWebsite
    objSelection.TypeText Chr(11)

标签: if-statementvbscriptxml-signature

解决方案


如有疑问,请阅读文档

' Block syntax: 
If condition Then
   [statements]
[ElseIf condition-n Then
   [elseifstatements]] . . .
[Else
   [elsestatements]]
End If 

使用块语法时,每个If语句必须由相应的End If. 此外,它是End If,不是EndIf

如果你想在strmobile有值的时候插入一些东西而不做任何事情,否则你会这样表达:

If Not IsEmpty(strmobile) Then
    objSelection.typetext " | M: " & strMobile
EndIf

请注意EmptyNull, 和空字符串 ( "") 在 VBScript 中是不同的值,因此strmobile您可能需要根据实际值相应地调整检查。


推荐阅读