Hello
it looks like you just give a reference to your curEnt object and not save a copy of it in your array. I did'nt know VBA worked liked that in this case but this behaviour is frequent in object programming languages. For example, it is the same for arguments of a VBA function: you can choose between ByVal and ByRef. ByVal gives a copy af the given variable to the function. Any changes made to this copy don't affect the variable. ByRef gives a reference of the object (you can see it as its adress in memory), the changes made by the function to the variable are permanent, even after the function finishes.
Look in VBA help (F1) the "Set" instruction, it explains that it creates a new instances of a class or if it is used (as you did) with "Nothing" like "Set xyz = Nothing" it deletes the instance. Then when you write "curEnt.Category = ..." a new instance is created. I think your code should work if you replace "set curEnt = Nothing" by "Set curEnt = New Entitlements" and it would be easier to understand.
I was'nt able to reproduce this behaviour. Is "Entitlements" a class or a struct that you defined?
Jean-Hugues
I see that a number of people viewed this but didn't care enough about (or have a solution to) the problem I posted (i admit it wasn't a ton of time true since the initial inquiry). Anywhooo, I figured it out so for those in the future who wish to know.
It was setting the array values to whatever curEnt was last time in the loop, so regardless of what I did, it would set all array items to curEnt's last value. For instance if I did this
If (SubStrCount = 5) Then curEnt.Category = Substr(1) curEnt.Title = Substr(2) curEnt.Id = Substr(3) curEnt.Enttlmnt = Substr(4) curEnt.EntType = Substr(5) Else MsgBox ("Your source text file contains a line with more items than allowed" _ & "Please check the source file or use another one in proper format" _ & "This presentation will not work as expected unless you start over") Exit Function End If 'Me thinks the problem lies right here, but cannot figure out a solution at all Set permList(lineCount) = curEnt curEnt.Category = "" curEnt.Title = "" curEnt.Id = "" curEnt.Enttlmnt = "" curEnt.EntType = "" lineCount = lineCount + 1And after that loop was finished if I printed this:
MsgBox ("for permList(0) the first three elems are: " & permList(0).Category & " :: " _ & permList(0).Title & " :: " & permList(0).Id) MsgBox ("for permList(1) the first three elems are: " & permList(1).Category & " :: " _ & permList(1).Title & " :: " & permList(1).Id) MsgBox ("for permList(2) the first three elems are: " & permList(2).Category & " :: " _ & permList(2).Title & " :: " & permList(2).Id)I'd get "" :: "" :: ""
Despite having set this AFTER I put curEnt into the array and not setting the array's values to those blanks at all. WTF???
The solution?
I set curEnt = Nothing at the top of the loop
Do While Not EOF(iFileNum) 'CRUCUIAL SETTING THIS TO NOTHING...DON'T KNOW WHY Set curEnt = Nothing 'up the line counter to one (we use this for the dynamic array's size) 're dimension preserve the array to up its size by 1 more in prep for a new item 'as well as keep all the items its accumulated so far ReDim Preserve permList(lineCount) As EntitlementsI have no earthly clue why that fixed it...which is terrible I know...someone want to shed some light on me??
Because tho it's fixed, I'm lost as to the reason for it.
kharri5