Variables Out of Scope in Basic Watch Window

The watch window is showing passed and local variables as being out of scope when they should be in scope.
I have placed breakpoints in the code and simplified it but it still occurs.
Also I do not see the myTest sub in the categories window even though it is in the edit window.
Sub Main
myTest(1,0,0,“Horiz”)
End Sub

Sub myTest (sheetNum As Long, startRowNum As Long, startColNum As Long, direction As String)

’ Dim Doc As Object 'hold document reference
’ Dim Sheet As Object 'hold sheet reference
’ Dim rowCell As Object 'holds the cell in the row that is being checked for an empty value
’ Dim colCell As Object 'holds the cell in the column that is being checked for an empty value
’ Dim rowSize As Long
’ Dim colSize As Long
’ Dim colNum As Long
’ Dim rowNum As Long
’ Dim longestRow As Long
’ Dim longestCol As Long

’ Doc = ThisComponent 'references the document that the macro is part of
REM Sheet = Doc.Sheets(sheetNum) 'references the sheet
’ rowSize = 0
’ colSize = 0 'these both start at 0 because arrays start at 0
’ colNum = 10 'set the column and row numbers to the initial value
’ rowNum = 10
’ longestRow = 0
’ longestCol = 0

dim i,j,cnt
for cnt = 1 To 10
	i = i + 1
	j = i + 1
next cnt

End Sub

The above is coded properly but did not come out in this editor properly. I am knew to using it.

The myTest sub now appears in the object window because I am now not in a breakpoint but the variables are still out of scope. :frowning:

Hello,

The reason you are not seeing anything is because the routine has not been called nor stopped at the breakpoint. That is why the variables are out of scope. Here is your nearly same call with the execution at a breakpoint:

Notice a few items. The arrow is pointing to where the execution of the code is at the breakpoint and a few lines down there is another breakpoint but not stopped there. The other point, and realize this setup is using different icons than yours, but both the Run and the Stop icon are active. The macro is in execution mode. Finally in lower right section (Calls) you can see where the routine was called from.

Your screen simply shows the IDE waiting for something to happen.

Yes I see what you mean. And I found that the debugger would start the execution from the test subroutine and not from the Main subroutine where it was called from. Therefore it would not have the data for the arguments. Thanks for your help. It was one of those pesky problems that seem to defy logic until I looked at it from your answer.

Debugger starts execution from the subroutine where cursor currently is when you start the debugging session from the IDE.

Thanks Mike. I should have mentioned that.

On another level, I didn’t think of it because I didn’t realize it would run without the parameters (of course I didn’t try it either). Run from a form it produces an error:

Message: wrong number of parameters!