Solved

Redim of Public Array Within Class Results in Loss of Dimensions

Posted on 2013-06-20
4
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

734 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