I'm working on a reporting section of code for an inventory app I'm making for my office.
I call a text file, read every line into an array then populate information pages with what has been pulled from the text file.
For reporting, I want to read every text file in the directory, reading each one into a multidimensional array.
Thus I can call and report on each item, i.e.
ItemArray(i,2) would be all systems with Windows 2008 EE
I have code that lists all files in the desired directory and counts each file, so I eventually get counts of how deep I need the first level of the jagged array to be. but not until after code execution.
Basically how can I write each array of data to the jagged array.
MainMenu Public ItmOptions As New List(Of String) Public ItemArray()()
Public Sub ReadFileForReports() Dim oRead As System.IO.StreamReader Dim i As Integer = 0 'Items.Clear() ' Try opening INI file Try oRead = IO.File.OpenText(MainMenu.DirRoot & MainMenu.DirEnviroment & MainMenu.DirCategory & MainMenu.LoadFile) Catch e5 As Exception ' No INI found MsgBox("No INI File found") Exit Sub End Try While oRead.Peek <> -1 MainMenu.ItmOptions.Add(oRead.ReadLine()) End While oRead.Close() oRead.Dispose() MainMenu.ItmOptions.ToArray() End Sub Public Sub GatherReportsArray() Dim TempCategory As String = "ServerSystems" Dim TempEnviroment As String = "Prod\" Dim i As Integer = 0 If MainMenu.tscombo_Enviroment.SelectedIndex = 1 Then TempEnviroment = "Prod\" If MainMenu.tscombo_Enviroment.SelectedIndex = 2 Then TempEnviroment = "Dev-UAT\" If MainMenu.tscombo_Enviroment.SelectedIndex = 3 Then TempEnviroment = "Test\" If MainMenu.tscombo_Enviroment.SelectedIndex = 4 Then TempEnviroment = "Sandbox\" If MainMenu.combo_Category.SelectedIndex = 0 Then TempCategory = "ServerSystems\" If MainMenu.combo_Category.SelectedIndex = 1 Then TempCategory = "ServerApplications\" If MainMenu.combo_Category.SelectedIndex = 2 Then TempCategory = "NetworkSystems\" If MainMenu.combo_Category.SelectedIndex = 3 Then TempCategory = "NetworkApplications\" If MainMenu.combo_Category.SelectedIndex = 4 Then TempCategory = "DesktopSystems\" If MainMenu.combo_Category.SelectedIndex = 5 Then TempCategory = "DesktopApplications\" If MainMenu.combo_Category.SelectedIndex = 6 Then TempCategory = "Databases\" Dim Dir As New IO.DirectoryInfo(MainMenu.DirRoot & TempEnviroment & TempCategory) Dim ArrayFiles As IO.FileInfo() = Dir.GetFiles("*.ini") Dim Files As IO.FileInfo ' Count Systems MsgBox(MainMenu.DirRoot & TempEnviroment & TempCategory) For Each Files In ArrayFiles MainMenu.LoadFile = Files.Name MsgBox(MainMenu.LoadFile) ReadFileForReports() MsgBox(i) MainMenu.ItemArray(i) = MainMenu.ItmOptions(i) i = i + 1 Next End Sub
I get an error at MainMenu.ItmOptions(i)
Error 1 Value of type 'String' cannot be converted to '1-dimensional array of Object'.
As seen above, MainMenu.ItmOptions is a List(of String) that is then converted to an array MainMenu.ItmOptions.ToArray
How can I achieve writing the data in MainMenu.ItmOptions() into i of MainMenu.ItemArray
It hit me as I was typing this out to try reading each item in ItmOptions and writing each into MainMenu.ItemArray(i,i2)
Dim i2 as Integer = 0 Do until i = MainMenu.ItmOptions.Count MainMenu.ItemArray(i, i2) = MainMenu.ItmOptions(i2) i2 = i2 + 1 Loop
Rather than trying than the original code. I'll test this, but didn't wanna waste this long post after typing it all out lol.
What I tried
For Each Files In ArrayFiles MainMenu.LoadFile = Files.Name MsgBox(MainMenu.LoadFile) ReadFileForReports() MsgBox(i) Dim i2 As Integer = 0 Do Until i = MainMenu.ItmOptions.Count MainMenu.ItemArray(i)(i2) = MainMenu.ItmOptions(i2) i2 = i2 + 1 Loop i = i + 1 Next
But I get a null reference exception. "Use the new keyword to create an object instance"
Being very new to VB, how can I achieve my end goal?