Initilizing Arrays

melegant

Well-known member
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 its 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 lets say I wanted to check a bunch of text boxes for nulls before I send the information to a database.

However I cant quite figure out how to do this...I can set up an arrary of text boxes as a property just fine, its the dynamic size thats throwing me.

Code:
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)

Code:
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 dont 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 by a moderator:
Back
Top