Solved

Debug.Print members of an array

Posted on 2011-02-16
3
603 Views
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.
'/******************************************************************************
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
Comment
Question by:ssmith94015
3 Comments
 
LVL 30

Accepted Solution

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

Sid
0
 
LVL 14

Assisted Solution

by:pteranodon72
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,

pT72
0
 

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

914 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

22 Experts available now in Live!

Get 1:1 Help Now