Visual Basic > Visual Basic Forums > Visual Basic Interop and Upgrade > Does the declare of arrays in structure are correct ?
Ask a questionAsk a question
 

AnswerDoes the declare of arrays in structure are correct ?

  • Wednesday, October 28, 2009 1:47 PMksw1973 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Does the declare of arrays in structure are correct ? ?
    Has it other better solution ? instead of using redim for multi-arrays type in structure?


    Public Class Form_Main

        Public Structure hiddenneuron
            Public ot, da As Single                ' ot - output, da - delta
            Public bs, dbs, ubs As Single       ' bs - bias, dbs - dbias, ubs - bias update value
            Public wt(), dwt(), uwt() As Single ' wt - weight, dwt - dweight, uwt - weight update value
            Public er, per As Single               ' er - error, per - preious error
            Public se(), pse() As Single          ' se - slope, pse - preious slope
        End Structure

        ' net elements
        Public il() As inputneuron                ' il - input layer
        Public hl(,) As hiddenneuron            ' hl - hidden layer
        Public ol() As outputneuron             ' ol - output layer
        Public ot() As Single                       ' ot - desire output
        Public Const maxlayer As Integer = 3    ' maxium hidden layer
        Public lsize As Integer                     ' number of hidden layer

        Public Sub init_gobal()
            isize = 2         ' test
            hsize(0) = 2    ' test
            osize = 1        ' test - should be reading from config file

            lsize = 0
            For l = 0 To maxlayer - 1
                If hsize(l) > 0 Then lsize += 1
            Next

            ReDim il(isize - 1)
            ReDim ol(osize - 1)
            ReDim ot(osize - 1)

            For l = 0 To lsize - 1
                ReDim hl(l, hsize(l) - 1)
                If l = 0 Then
                    wsize = isize - 1
                Else
                    wsize = hsize(l - 1) - 1
                End If
                For n = 0 To hsize(l) - 1
                    ReDim hl(l, n).wt(wsize)
                    ReDim hl(l, n).dwt(wsize)
                    ReDim hl(l, n).uwt(wsize)
                    ReDim hl(l, n).se(wsize)
                    ReDim hl(l, n).pse(wsize)
                Next
            Next

            wsize = hsize(lsize - 1) - 1
            For n = 0 To osize - 1
                ReDim ol(n).wt(wsize)
                ReDim ol(n).dwt(wsize)
                ReDim ol(n).uwt(wsize)
                ReDim ol(n).se(wsize)
                ReDim ol(n).pse(wsize)
            Next
        End Sub
    End Class

Answers

All Replies