Solved

Redim of Public Array Within Class Results in Loss of Dimensions

Posted on 2013-06-20
4
442 Views
Last Modified: 2013-06-29
I am using Redim in a class on a two-dimensional array that is defined as public in a "declarations" module.  However, depending on where the program flow is after the Redim, there can be a loss of dimensions.  The pattern is that when I instantiate another object (class) within this class, then run the small process in that new object and come back the dimensions of the public array are lower.  Thus if the new object was never instantiated to go out and do work, the results are confirmed that loss of elements doesn't occur.

For my example, the Redim is A(20,1) but after using the instantiated class to do a small outside job (outside of this class we are in -->with the Redim) the dimensions are A(19,0).

There are rules for Redim based on where it is used, so my question is how can I retain declaring a public array in a declaration module, and then use Redim on those arrays within instantiated objects (classes) without losing dimensions?
0
Comment
Question by:lep1
4 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
Comment Utility
Can you post some piece of code?
0
 

Author Comment

by:lep1
Comment Utility
Sure:

Module mymod()
    Public A(,) As single
End Module

In button 1:
Dim obj as New Test

Class Test
Sub New
     Call test()
End Sub

Sub test()
   Redim A(20,1)
   'Here is where A will have dimensions (20,1)
    Dim myobj as As New ClassB
   'Here is where A will have dimensions (19,0)
End Sub
End Class

Class ClassB
Sub New()
Msgbox("hello")
End Sub
End Class
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
Comment Utility
I recreated the code you posted, in VS2008, with some adjustments (below), but upper bound did not change.

Form:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim obj As New Test
    End Sub

    Class Test
        Sub New()
            Call test()
        End Sub

        Sub test()
            ReDim A(20, 1)
            'Here is where A will have dimensions (20,1)
            MsgBox(A.GetUpperBound(0))
            Dim myobj As New ClassB
            MsgBox(A.GetUpperBound(0))
            'Here is where A will have dimensions (19,0)
        End Sub
    End Class

    Class ClassB
        Sub New()
            MsgBox("hello")
        End Sub
    End Class

End Class

Open in new window


Module:
Module mymod
    Public A(,) As Single
End Module

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

6 Experts available now in Live!

Get 1:1 Help Now