Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Object 测试Outlook时需要对象的错误_Object_If Statement_Vbscript_Outlook_Qtp - Fatal编程技术网

Object 测试Outlook时需要对象的错误

Object 测试Outlook时需要对象的错误,object,if-statement,vbscript,outlook,qtp,Object,If Statement,Vbscript,Outlook,Qtp,我不熟悉QTP和VBScript,有人能告诉我这个脚本在“If myEmails=Nothing”行上的错误吗?该行表示“需要对象”?此外,任何一般性的反馈或改进建议都将不胜感激,我花了太长时间试图让这个脚本现在工作lol myEmails = "" If emailSubjectToSearch = "[A-Za-z0-9_]" Then Set myEmails = emails.Find("[Subject] = "& emailSubjectToSearch & "")

我不熟悉QTP和VBScript,有人能告诉我这个脚本在“If myEmails=Nothing”行上的错误吗?该行表示“需要对象”?此外,任何一般性的反馈或改进建议都将不胜感激,我花了太长时间试图让这个脚本现在工作lol

myEmails = ""
If emailSubjectToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[Subject] = "& emailSubjectToSearch & "") 
Else
If emailBodyToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[Body] = "& emailBodyToSearch & "") 
Else
If emailSenderNameToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[SenderName] = "& emailSenderNameToSearch & "") 
Else
If emailSentOnToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[SentOn] = "& emailSentOnToSearch & "")
Else
If emailAttachmentToSearch = "[A-Za-z0-9_]" Then 
Set myEmails = emails.Find("[Attachment] = "& emailAttachmentToSearch & "")
End If
End If
End If
End If
End If


If myEmails Is Nothing Then
MsgBox "Email not found"
Else
MsgBox "Email found"
msgbox myEmails
End If

虽然我不知道整个脚本,但是下面的代码片段应该可以工作

myEmails = ""
If emailSubjectToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[Subject] = "& emailSubjectToSearch & "") 
ElseIf emailBodyToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[Body] = "& emailBodyToSearch & "") 
ElseIf emailSenderNameToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[SenderName] = "& emailSenderNameToSearch & "") 
ElseIf emailSentOnToSearch = "[A-Za-z0-9_]" Then
Set myEmails = emails.Find("[SentOn] = "& emailSentOnToSearch & "")
ElseIf emailAttachmentToSearch = "[A-Za-z0-9_]" Then 
Set myEmails = emails.Find("[Attachment] = "& emailAttachmentToSearch & "")
End If

If IsNull(myEmails) Then
MsgBox "Email not found"
Else
MsgBox "Email found"
msgbox myEmails
End If

在VBScript中对
null
引用的测试是由
无需执行的。
Is
运算符与其他语言中的Javascript类似

Dim myObject ' uninitialized primitive with value empty (do not confuse with "" or 0)
Set myObject = new Regexp  ' Now it has an object

Dim yourObject
Set yourObject = Nothing

If myObject Is Nothing then
    MsgBox "MyObject is Nothing" ' won't be displayed
End if
If yourObject Is Nothing then
    MsgBox "YourObject is Nothing" ' this is displayed
End if

Set yourObject = New RegExp
MsgBox (myObject Is yourObject) ' displays False

Set yourObject = myObject
MsgBox (myObject Is yourObject) ' displays True

Set myObject = Nothing
MsgBox "myObject: " & (myObject Is Nothing) & _
     & ", yourObject: " & (yourObject Is Nothing)
' Displays myObject: True, yourObject: False
使用

If Not (myObject Is Nothing) Then ...
构造以测试变量是否包含非空对象

并使用

If IsObject(myObject) Then ...

用于测试变量是否包含基元或对象的构造

IsNull
仅用于数据库连接和字段。它不能用于没有引用的对象。将
IsNull
与对象一起使用可能会导致意外行为。我尝试了IsNull方法,该方法使msgbox作为电子邮件弹出,但没有填充,出于某种原因,它不是由它的外观设置的,但我无法理解为什么它不是由IF-ELSE语句设置的。我的目标是在IF-ELSE语句中设置myEmails。我是否必须在它进入IF-ELSE之前将其设置为某个值,以便将其更改为其中的某个值?我也尝试过执行下面的语句,而不是ELSE-IF语句,但在设置行上得到了对象变量not SET error。Dim myEmails设置myEmails=emails.Find(“[Subject]=”&emailSubjectToSearch&“SearchText”)&(“[Body]=”&emailBodyToSearch&“SearchText”)&(“[SenderName]=”&EmailSenderNameSearch&“SearchText”)&(“[SentOn]=”&EmailSentonSearch&“SearchText”)&(“[AttachmentToSearchText]=”&EmailAttachmentToSearchText”)我实际上怀疑这与此有关,因为如果我在下面添加一个msgbox电子邮件,就会出现“无效的过程调用或参数”错误
code
Set olApp=CreateObject(“Outlook.Application”)Set olns=olApp.GetNameSpace(“MAPI”)Set Inbox=olns.GetDefaultFolder(6)Set emails=Inbox.Items
code