Working wih redimensioned array with User defined type

The Actual problem in all this was the redim preseve in the DLL does not work properly .

1. I define an User define type in Dll
and an array of the user defined type

Public type udt
  t1 as s tring
  I1 as integer
end type
Private myarr() as udt

2. the function in Dll component does some thing like this

Public function X() as boolean

for i = 1 to 50
   Redim Preserve myarr(i)
   '****** this statemenmt causes the
   '****  general protection fault

   myarr(i).t1 = "test" & i
   myarr(i).I1 = i

next i
end function

** this function is directly accessed from a standard project which has forms

3. The same procedure works well in the devlopment environment but fails when u actually make the dll and refrence it from the project..

4. The question arises how do you work with redimentioning array's having structures i mean user defined type in it. The whole exercise  is actually for populating a tree structure using a binary tree algorithm . Well this works fine when you dimension it at the begining ( ie; if it is a fixed type of array)

ie; dim myarr(1000) as udt

Any help in this reagard is apprciated ..

Who is Participating?
mcriderConnect With a Mentor Commented:
Try this:

ReDim myarr(0) as as udt
for i = 1 to 50
   Redim Preserve myarr(i) as udt
   myarr(i).t1 = "test" & i
   myarr(i).I1 = i

next i

jaggi06Author Commented:
Yes I missed that and tried to redimension and preserve the array with value

ie; redim preserve myarr(0)

Thank you for exactly pinning at the right point ..

Thanks for the points! Glad I could help!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.