Solved

Debug.Print members of an array

Posted on 2011-02-16
3
610 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 how to use a scrolling table in Microsoft Excel using the INDEX function.

813 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

13 Experts available now in Live!

Get 1:1 Help Now