Redim Preserve Help!

usiddiqi

New member
Local time
Today, 14:38
Joined
Jul 14, 2005
Messages
6
Hi guys,

Can anyone of u tells me what is the problem with the following code:

Code:
Dim feld() As String
Dim cnt as integer

Public Sub more_Click()
    If Trim(txtFeld.Value) <> "" And Trim(obType.Value) <> "" Then
        cnt = cnt + 1
        If cnt > UBound(feld, 1) Then
            ReDim Preserve feld(cnt, 2)    ----------- line 1        
        End If
        
        feld(1, cnt) = txtFeld.Value
        feld(2, cnt) = obType.Value
    Else
        msgbox "Please enter feild name Or select data type"
    End If
End Sub
I found error on line 1 "index outside of the valid range"
When i use without preserve then it works fine!!

Any kind of hint or help will be greatly appreacited

Yours,
Umer Siddiqi
 
Last edited by a moderator:
As taken from the help file (I suggest you look there first):

"If you use the Preserve keyword, you can resize only the last array dimension and you can't change the number of dimensions at all."

Example:
Code:
ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)
 
thanks, modest, it works
 
You might want to post your updated code. The problem is if you leave off the Preserve, your data won't be saved in the array. I think there are some algorithms on this forum to help solve your problem.
 

Users who are viewing this thread

Back
Top Bottom