I am currently writing a powerpoint presentation that is an interactive survey. It takes in a file of data, and adds it to a big dynamic array. When the user answers questions it picks the data from the array and populates an excel spreadsheet for a final output of a spreadsheet of that data. The problem I am having is taking in the data. I take file line by line, and each line is separated by commas another function rips that line apart to store each string chunk in the class Entitlements variables. I then want to put this Entitlements object into the array. It always puts only the last line for all the lines when it finishes. What am I doing wrong?
'Name: GetLinesFromText 'Returns: nothing 'Description: This opens the file reads it line by line and sends it to be parsed. It then 'stores the parsed results into the permissionslist array for later use ' Sub GetLinesFromText() Dim sFileName As String Dim iFileNum As Integer Dim sBuf As String Dim curEnt As New Entitlements 'For parsiing the line into separate strings ReDim Substr(0) As String Dim SubStrCount As Integer Dim lineCount As Integer Dim wordCount As Integer Dim i As Integer lineCount = 0 wordCount = 0 ' edit this: sFileName = REPORT_DATA_FILE ' does the file exist? simpleminded test: If Len(Dir$(sFileName)) = 0 Then MsgBox ("You didn't input a file at all. Please make sure the package was unzipped to the C: drive directly") Exit Sub End If iFileNum = FreeFile() Open sFileName For Input As iFileNum 'while not at the end of the file Do While Not EOF(iFileNum) '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 Entitlements 'Set permList(lineCount) = Nothing 'use line input to get the line Line Input #iFileNum, sBuf ' now you have the next line of the file stored in sBuf ' rip apart sBuf into individual strings, storing the count of them ' in SubStrCount. This will be needed to iterate to the right number SubStrCount = ParseString(Substr(), sBuf, ",") ' the below process will store the sub-strings in permList: ' Get the first string. That's a heading topic entitlement If (SubStrCount = 5) Then curEnt.Category = Substr(1) curEnt.Title = Substr(2) curEnt.Id = Substr(3) curEnt.Enttlmnt = Substr(4) curEnt.EntType = Substr(5) 'plug in the item at the count - 1 position for the 0 based array 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 Sub End If If (lineCount = 1) Then MsgBox ("XXXfor permList(0) the first three elems are: " & permList(0).Category & " :: " _ & permList(0).Title & " :: " & permList(0).Id) End If MsgBox (lineCount) 'Me thinks the problem lies right here, but cannot figure out a solution at all Set permList(lineCount) = curEnt MsgBox ("for permList(0) the first three elems are: " & permList(0).Category & " :: " _ & permList(0).Title & " :: " & permList(0).Id) lineCount = lineCount + 1 'IT JUST KEEPS OVERWRITING ALL MY ROWS TO THE ONE THAT WAS LAST 'MsgBox ("The Current ent details are: " & curEnt.Category & " :: " _ ' & curEnt.Title & " :: " & curEnt.Id & " :: " _ ' & curEnt.Id & " :: " & curEnt.Enttlmnt & " :: " _ ' & curEnt.EntType) Loop ' we've reached the end of the file now ' close the file Close iFileNum 'after all of this the array now stores the values we will need to fill in the 'excel sheet with data 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) End Sub
If anyone can help me I'd greatly appreciate it. I've been banging my head on it for a week or two now.