redimension multidimensional arrays in Excel VBA

后端 未结 4 1159
难免孤独
难免孤独 2021-01-28 02:59

Take a look at the following code. What my problem is is that I can\'t figure out how to redimension the n integer and the b integer. What I\'m doing is the array sent1 is alr

4条回答
  •  温柔的废话
    2021-01-28 03:37

    In case anyone has this problem here is how I solved it:

    
    Function find_sentences_complex(instring As String) As Variant
    
    Dim xorr As String: xorr = ChrW(&H22BB)
    Dim triple_bar As String: triple_bar = ChrW(&H2261)
    Dim idisj As String: idisj = ChrW(&H2228)
    Dim cond As String: cond = ChrW(&H2192)
     Dim x As Integer, y As Integer, z As Integer, b As Integer
    Dim total As Integer, paren_closure As Integer, marker As Boolean
     Dim n As Integer
    
    Dim sent1() As Variant, sent3() As Variant
    
    'Dim final1d As Integer, final2d As Integer
    Dim b_arr() As Integer
    Dim b_max As Integer
    
    
    
    
       Dim temp_string As String
    
            For x = InStr(instring, "(") To Len(instring) Step 1
    
               temp_string = Mid(instring, x, 1)
    
                If Mid(instring, x, 1) = "(" Then
    
                    If marker = False Then
                    z = x
                    marker = True
                    End If
    
                total = total + 1
                ElseIf Mid(instring, x, 1) = ")" Then
                total = total - 1
    
    
                    If total = 0 Then
                    marker = False
                    b = b + 1
                    paren_closure = x
                    ReDim Preserve sent1(b)
                    sent1(b) = Mid(instring, z, (x - z) + 1)
                    End If
                End If
            Next
    
     Dim temp_sent1 As String
    total = 0
    marker = False
    
    
    
    b = 0
    
    
    Dim sent2()
    ReDim sent2(UBound(sent1), 5)
    
     For n = 1 To UBound(sent1)
     temp_sent1 = sent1(n)
     temp_sent1 = Mid(temp_sent1, 2, Len(temp_sent1) - 2)
     b = 0
        For x = 1 To Len(temp_sent1)
    
    
    
               temp_string = Mid(instring, x, 1)
    
                If Mid(temp_sent1, x, 1) = "(" Then
    
                    If marker = False Then
                    z = x
                    marker = True
                    End If
    
                total = total + 1
                ElseIf Mid(temp_sent1, x, 1) = ")" Then
                total = total - 1
    
    
                    If total = 0 Then
                    marker = False
                    b = b + 1
                    paren_closure = x
                    'ReDim Preserve sent2(n, b)
    
                    sent2(n, b) = Mid(temp_sent1, z, (x - z) + 1)
    
                    End If
                End If
            Next
    
            'this part of the code redimensions the side of the array
    
            ReDim Preserve b_arr(n)
            b_arr(n) = b
    
    
    Next
    
    b_max = MaxValOfIntArray(b_arr)
    ReDim Preserve sent2(UBound(sent1), b_max)
    
    
    
    
    
    
    
    
    
    End Function
    
    Public Function MaxValOfIntArray(ByRef TheArray As Variant) As Integer
    'This function gives max value of int array without sorting an array
    Dim i As Integer
    Dim MaxIntegersIndex As Integer
    MaxIntegersIndex = 0
    
    For i = 1 To UBound(TheArray)
        If TheArray(i) > TheArray(MaxIntegersIndex) Then
            MaxIntegersIndex = i
        End If
    Next
    'index of max value is MaxValOfIntArray
    MaxValOfIntArray = TheArray(MaxIntegersIndex)
    End Function
    
    

提交回复
热议问题