Ask Your Question
0

Variables Out of Scope in Basic Watch Window

asked 2018-11-20 07:16:22 +0100

ninja35 gravatar image

updated 2018-11-21 02:47:00 +0100

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 Subimage descriptionimage description

edit retag flag offensive close merge delete

Comments

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

ninja35 gravatar imageninja35 ( 2018-11-20 07:18:44 +0100 )edit

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. :-(

ninja35 gravatar imageninja35 ( 2018-11-20 07:32:52 +0100 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2018-11-21 03:35:50 +0100

Ratslinger gravatar image

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:

image description

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.

edit flag offensive delete link more

Comments

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.

ninja35 gravatar imageninja35 ( 2018-11-21 05:05:14 +0100 )edit
1

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

Mike Kaganski gravatar imageMike Kaganski ( 2018-11-21 06:17:08 +0100 )edit

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!
Ratslinger gravatar imageRatslinger ( 2018-11-21 06:33:54 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-11-20 07:16:22 +0100

Seen: 97 times

Last updated: Nov 21 '18