none
Why does the VBA code block indicate a "True" condition even though the condition is not so? RRS feed

  • Question

  • I seem to have an issue with my script.  The attached block of code to verify the behavior of the checkboxes has a statement:

    Set ErrorMsgWindow=DotNETForm(“OSS_Stat_Imp_ErrMsg”), which is set to “Nothing”.  In the following conditional statement block:

    If ErrorMsgWindow.Exists Then

                    TestLog.Comment “This message box should not be displayed.”

    ErrorMsgWindow.Attach

    DotNETButton(“Name=btnOK”).Click

    Else

                    TestLog.Comment “Button is inactive”

    End If

    The property “Exists” has no value as the object value is set to “Nothing”.  Yet the code proceeds into the “if” conditional as if ErrorMsgWindow.Exists were set to “True”, which it isn’t.

    Please explain and/or advise why this is happening and how this should be recoded to make it work.  Thank you.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    Wednesday, May 9, 2012 9:20 PM

All replies

  • BTW--The attached block of code is actually the excerpt stated in the original post.

    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    Wednesday, May 9, 2012 9:21 PM
  • The IF isn't controlling the code, the failure of the if test means control drops down to teh next line. If an Object might be Nothing then you must first test for that before trying any other test. EG:

    If Not ErrorMsgWindow Is Nothing Then
        If ErrorMsgWindow.Exists Then
           TestLog.Comment _
                 “This message box should not be displayed.”
            ErrorMsgWindow.Attach
            DotNETButton(“Name = btnOK”).Click
        Else
            TestLog.Comment “Button Is inactive”
        End If
    End If
    


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Proposed as answer by Ray Brack Tuesday, May 22, 2012 1:09 PM
    Thursday, May 10, 2012 6:56 AM
  • Hi John,

    Did Rod's reply resolve your issue?

    Tuesday, May 22, 2012 1:09 PM
  • Sorry for the delayed response as I have not worked on that particular script for awhile.  However, I did have something similar in another script, and I applied the recommended code that Rod provided me.

    Unfortunately, I cannot say that it worked, not because the block of code didn't work, but because a statement prior to this block failed before TestPartner even reached it.  The code in question is as follows:

                        iCount = 0
                        GStation_Ready = False
                        Set OSS_Log_Prompt = Window(OSS_Counter_Log)---This is the statement where I get the run-time error "Failed to find the attached name"
                        Do While GStation_Ready = False
                            If Not (OSS_Log_Prompt Is Nothing) Then
                                If OSS_Log_Prompt.Exists Then
                                    TestLog.Comment OSS_Counter_Log & " displayed"                      'Prompt displayed for viewing log file
                                    GStation_Ready = True
                                    OSS_Log_Prompt.Attach
                                    Button("Caption=&Yes").Click
                                    Call shmdl_Save_Log_File(strResultsFolder, Vendor & "_OSS_Counter_Log_" & Technology & "_" & DataSwitch & "_" & intA)
                                Else
                                    Sleep 1
                                    iCount = iCount + 1
                                    TestLog.Comment OSS_Counter_Log & " not displayed"                  'Prompt not displayed for viewing log file
                                End If
                            Else
                                Sleep 1
                                iCount = iCount + 1
                                TestLog.Comment "No OSS log viewing prompt exists yet..." & iCount & " seconds elapsed."
                            End If
                        Loop

    OSS_Counter_Log is the name of the prompt window that displays when the application finishes processing, and it allows the user to view the log file if preferred.

    Please advise how I can avoid getting such run-time errors when performing that "Set" statement.  I cannot use the "Exists" property as mentioned in my initial problem description.  Thanks.


    John J. Bottiger (QA Engineer, Gladiator Innovations LLC)

    Friday, July 13, 2012 10:36 PM