Initilizing Arrays

melegant

Regular
Joined
Feb 2, 2003
Messages
52
Location
NY
I hope I am using the right forum for this question..

So, I am using VB.NET, and I have a Control Manipulation Class that I am coding.

I want to create an array as a property, where it's size is dynamic. This way I can in a form just add text boxes to the array and then call a method and do what I wish with the arrary. For example let's say I wanted to check a bunch of text boxes for nulls before I send the information to a database.

However I can't quite figure out how to do this...I can set up an arrary of text boxes as a property just fine, it's the dynamic size that's throwing me.

Visual Basic:
Private MarrTxt(dynamic size...) as Textbox

Public Property arrTXT() as TextBox
Get
Return MarrTXT()
End Get etc...
 
Is the form design going to be constant ??

i.e. Do you just want to loop through the controls checking for Nulls?

And Control array are dead and gone RIP

Andy
 
ok, i had some code here..but then i found this class on the Inet...


(I re tooled it a bit or .net)

Visual Basic:
Public Class iArrDynamic
    Inherits iControlManip

    Private aData

    Public Sub New()
        ReDim aData(0)
    End Sub

    Public Property Data(ByVal iPos)
        Get
            'Make sure the end developer is not requesting an
            '"out of bounds" array element
            If iPos < LBound(aData) Or iPos > UBound(aData) Then
                Exit Property    'Invalid range
            End If
            Data = aData(iPos)
        End Get
        Set(ByVal Value)
            'Make sure iPos >= LBound(aData)
            If iPos < LBound(aData) Then Exit Property
            If iPos > UBound(aData) Then
                'We need to resize the array
                ReDim Preserve aData(iPos)
                aData(iPos) = Value
            Else
                'We don't need to resize the array
                aData(iPos) = Value
            End If
        End Set
    End Property

    Public ReadOnly Property DataArray()
        Get
            DataArray = aData
        End Get
    End Property

    Public Function StartIndex()
        StartIndex = LBound(aData)
    End Function

    Public Function StopIndex()
        StopIndex = UBound(aData)
    End Function

    Public Sub Delete(ByVal iPos)
        'Make sure iPos is within acceptable ranges
        If iPos < LBound(aData) Or iPos > UBound(aData) Then
            Exit Sub    'Invalid range
        End If

        Dim iLoop
        For iLoop = iPos To UBound(aData) - 1
            aData(iLoop) = aData(iLoop + 1)
        Next

        ReDim Preserve aData(UBound(aData) - 1)
    End Sub
    '****************************************
End Class

the only question is the re dim buisnass..
 
Last edited:
Back
Top