vba unexpected 'if then' behavior

TullTigger

New Member
Joined
Dec 7, 2009
Messages
7
Hello,
I'm building class modules for the first time & experiencing some unexpected behavior.
I'm hoping that a new set of eyes can tell me what I'm doing wrong, or tell me that this is a VBA bug.
I'm working in XP, using Excel 2002/VBA 6.3.

Here is the method in my class module:

Code:
Function WaitForStringInRect(ByVal WaitString As String, _
                            Optional ByVal sRow As Integer = 1, Optional ByVal sCol As Integer = 1, _
                            Optional ByVal eRow As Integer = 24, Optional ByVal eCol As Integer = 80, _
                            Optional ByVal TimeOut As Variant = lngTIMEOUT, _
                            Optional ByVal bWaitForIr As Boolean = True, _
                            Optional ByVal bCaseSens As Boolean = False) As Boolean
On Error GoTo errProc
'''''''''''''''''''''''''
Dim autECLPSObj As Object
'''''''''''''''''''''''''
Set autECLPSObj = CreateObject("PCOMM.autECLPS")
    autECLPSObj.SetConnectionByName Me.SessionID
'''''''''''''''''''''''''
WaitForStringInRect = autECLPSObj.WaitForStringInRect(WaitString, sRow, sCol, eRow, eCol, TimeOut, bWaitForIr, bCaseSens)
Debug.Print WaitForStringInRect
If Not WaitForStringInRect Then
    Debug.Print "Timeout Occurred when waiting for string: " & WaitString
End If
errProc:
'''''''''''''''''''''''''
Set autECLPSObj = Nothing
End Function

(the PCOMM.autECLPSObj dll is a set of automation objects for our AS400 system.)

After running this method in a standard module, I get this result in the immediate window:
True
Timeout Occurred when waiting for string: MENU-110

For some reason VBA isn't recognizing that "WaitForStringInRect" is True when it evaluates the If Not Then...
When stepping thru the code & hovering over WaitForStringInRect, the value shows true before executing that part of the statement.

Any ideas what is going on here?

Thanks in advance for your time.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Update:
This code constuction did behave as expected.
I don't know what the logical difference is...but at least it is working.

Code:
If autECLPSObj.WaitForStringInRect(WaitString, sRow, sCol, eRow, eCol, TimeOut, bWaitForIr, bCaseSens) Then
    WaitForStringInRect = True
Else
    WaitForStringInRect = False
    Debug.Print "Timeout Occurred when waiting for string: " & WaitString
End If
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top