Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 652
  • Last Modified:

Debug.Print members of an array

I inherited some code that populates an array, but I don't think it is doing waht it should - how do I debug.print the members of an array?  Attached is the module, but where would I put the Debug.Print so I can see each member as it is added to the array?
Sub fillPortfolioURLStringArray(ByVal s_namedRange As String)
'/******************************************************************************
' Grab all the URL strings in the named range (s_namedRange) passed, and store them in
' an array for use in the main subprocedure.
'/******************************************************************************
On Error GoTo ERROR_HANDLER
Dim wkb_currentWorkbook     As Workbook     ' This current application workbook with controls, URLs and dashboard.
Dim intCounter              As Integer      ' Counter in the array population loop
Dim intValidRangeMembers    As Integer      ' Capture the distinct number of validated members in the array so we can dimension
Dim intRowAddress           As Integer      ' Refer to the row number of any non-blank cell storing a URL in the
                                            ' appropriate named range.
Dim intIndex                As Integer      ' Used to populate the array index
Dim strCheckString          As String       ' Capture to check for string anomalies
    'Activate the first range to pump into an array
    wksSpec.Activate
    wksSpec.Range(s_namedRange).Activate
    ' Determine how many cells are populated in our total range and dimension our array index to that number.
    ' (Note - this will work because it is a one dimension array and would not if the array were multi-dimensioned)
    intIndex = Range(s_namedRange).Cells.Count
    ReDim s_blackRockURL(intIndex)
    ' Initialize our counter variables
    intCounter = 1       ' Simple counter
    intRowAddress = 1    ' Represents the row address for the URL cell. If a range cell is populated by
                        ' an empty string, we want to pass it by, not store it, and continue through
                        ' the range array.
    Do Until intCounter > intIndex
        ' If the URL in the range is not a zero-length string, then save it as a member of the array.
        ' If so, advance to the next range cell and try again.
        ' Let's make sure the cell storing the URL is populated.
        ' If not, let's advance but not increment our array members.
        strCheckString = Range(s_namedRange).Cells(intValidRangeMembers, 1).Value
                If strCheckString <> "" Then
                    s_blackRockURL(intCounter) = Range(s_namedRange).Cells(intRowAddress, 1)
                    'Tally of the number of validated array members in the range.
                    intValidRangeMembers = intValidRangeMembers + 1
                    intRowAddress = intRowAddress + 1
                    intCounter = intCounter + 1
                    Else
                        intRowAddress = intRowAddress + 1
                End If
    Loop
    'Since we now have a tally of how many members belong to the portfolio type passed in,
    'redimension our array to correspond to only those members.
    ReDim Preserve s_blackRockURL(intValidRangeMembers)
ERROR_HANDLER:
    If Err.Number <> 0 Then
        wksSpec.Protect Password:=s_PSWD    ' Reprotect Settings worksheet
        Set wkb_currentWorkbook = Nothing   ' Tidy up
        Call SlowDown
     End If
End Sub

Open in new window

0
ssmith94015
Asked:
ssmith94015
2 Solutions
 
SiddharthRoutCommented:
This is the line where the items are stored in an array

s_blackRockURL(intCounter) = Range(s_namedRange).Cells(intRowAddress, 1)

If you want, what is stored then do this

Debug.Print Range(s_namedRange).Cells(intRowAddress, 1)

before that line.

Sid
0
 
pteranodon72Commented:
The array gets each assignment on line 33 of the code that you show.
After line 33, you can add:
Debug.Print intCounter, s_blackRockURL(intCounter)

Another possibility is to use the watch pane in the debugger. If you put a breakpoint in the sub, highlight s_blackRockURL within the code and press Shift-F9. Then you can add a watch and see the values change as you step through the code with F8.

Hope this helps,

pT72
0
 
ssmith94015Author Commented:
Both worked and as they actually suited different problems and amounts of data, I am going to split.  Thank you.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now