Solved

Redim of Public Array Within Class Results in Loss of Dimensions

Posted on 2013-06-20
4
449 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
ID: 39262298
Can you post some piece of code?
0
 

Author Comment

by:lep1
ID: 39262373
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
ID: 39287320
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2015 Redefinition errors 4 51
execute SQL Stored Procedure 1000 times from vb.net 3 35
PL SQL Developer 7 34
VB.NET 2008 Publish Error 2 27
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 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