Debug.Print members of an array

Posted on 2011-02-16
Last Modified: 2012-05-11
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.
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
    ' 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
                        intRowAddress = intRowAddress + 1
                End If
    '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)
    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

Question by:ssmith94015
LVL 30

Accepted Solution

SiddharthRout earned 250 total points
ID: 34911708
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.

LVL 14

Assisted Solution

pteranodon72 earned 250 total points
ID: 34911764
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,


Author Closing Comment

ID: 34912194
Both worked and as they actually suited different problems and amounts of data, I am going to split.  Thank you.

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
We were having a lot of "Heartbeat Alerts" in our SCOM environment, now "Heartbeat" in a SCOM environment for those of you who might not be familiar with SCOM is a packet of data sent from the agent to the management server on a regular basis, basic…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now