Ken H.
asked on
Loop Issue - Too Many Loops
Need help fixing my loops.
I have a table which populates a gridview with data from two separate log files. Each storage system folder contains these log files and my loop needs to cycle through every folder in a specific directory and pull out these log files.
The problem is when I add the second file that pulls data the table size triples. It seems 3 iterations are performed on each folder. I'm not sure how to code this correctly. I could hack it with another gridview with just the entries from the 2nd log but i really want them all in one gridview.
Code below.
I have a table which populates a gridview with data from two separate log files. Each storage system folder contains these log files and my loop needs to cycle through every folder in a specific directory and pull out these log files.
The problem is when I add the second file that pulls data the table size triples. It seems 3 iterations are performed on each folder. I'm not sure how to code this correctly. I could hack it with another gridview with just the entries from the 2nd log but i really want them all in one gridview.
Code below.
For Each slotConfigInfo As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_SlotConfigInfo.log", SearchOption.AllDirectories)
For Each versionInfo As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_VersionInfo.log", SearchOption.AllDirectories)
Dim slotConfigData As String() = IO.File.ReadAllLines(slotConfigInfo)
Dim versionInfoData As String() = IO.File.ReadAllLines(versionInfo)
Dim systemName As String = slotConfigData(4).Substring(14)
Dim systemID As String = slotConfigData(6).Substring(12)
Dim systemModel As String = slotConfigData(8).Substring(15)
Dim systemSerialNumber As String = slotConfigData(14).Substring(23)
Dim cpuCount As String = slotConfigData(30).Substring(23)
Dim memorySize As String = slotConfigData(32).Substring(14)
Dim ontapVersion As String = versionInfoData(2).Substring(24, 9)
'Declare 1 Row for data
Dim Row1 As DataRow
Try
'Declare new row
Row1 = Table1.NewRow()
'Fill row with data - Item property is used to set the field value
Row1.Item(filerName) = systemName
Row1.Item(filerModel) = systemModel
Row1.Item(Ontap) = ontapVersion
Row1.Item(sysID) = systemID
Row1.Item(sysSerial) = systemSerialNumber
Row1.Item(sysMem) = memorySize
Row1.Item(sysCPU) = cpuCount
Table1.Rows.Add(Row1)
Catch ex As Exception
End Try
Next
Next
'Bind grid to DataTable
gridFilerProperties.DataSource = Table1
gridFilerProperties.DataBind()
ASKER
One next to the other I cannot add the data from the second log to the same row of the gridview. I end up having to create a new row to place that data. There must be some way I can loop all of this data from two separate files into one table and place the data in the column I want to display it.
I'm not sure what I would gain by the count. Could I nest the for loop and count the number of folders in the "Storage System" directory and force the loop to stop at that number of iterations? If so can you give me example code?
Thanks!
I'm not sure what I would gain by the count. Could I nest the for loop and count the number of folders in the "Storage System" directory and force the loop to stop at that number of iterations? If so can you give me example code?
Thanks!
Well, first question.. How to how know that the info taken from one version file is going with another config file ? Because from the code you posted, it seems to be random.
When this will be answered, I'll be able to tell you how to do it.
When this will be answered, I'll be able to tell you how to do it.
ASKER
I know it's pulling the data correctly because the data in both files matches up with the appropriate system for all 3 entries in my test system. Because it is pulling the files correctly I would assume its looping through reading the files based on folder name alphabetically or something like that but I can't say for sure.
If there is a more programmatic way such as getting all the directory names in the Storage System directory and then calling each of those values in a new loop.... I'm not really sure what to do here because i need data from two files in each row.
If there is a more programmatic way such as getting all the directory names in the Storage System directory and then calling each of those values in a new loop.... I'm not really sure what to do here because i need data from two files in each row.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That looks like a good way to call the data, but it still leaves me with the issue of how do i code a loop that combines the data from each iteration into the same row of a table?
For every subfolder in the Storage System directory both of these log files will always be present.
For every subfolder in the Storage System directory both of these log files will always be present.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for the super thorough answer djon2003!! I am currently not coding in .NET 4 though I could I am using VS2010 now. Both of these are valuable information i'm going to keep for reference. Thank you again!
So the loops should be one next the other, or another way.