0

enter image description hereI have been stuck trying everything I can think of and I can not get this to work. I am trying to create a list from a 2D array. The reason behind this is so that I can create a XY graph and use the grid lines to indicate where a select item is within my graph. I have attached a hand drawing o my idea if that helps anyone as well. In simple every time within my 2D array a file comes across that reads testtesttest.D000 I need that to be stored into a separate list so I can use that for my x axis. I am using List(Of String) in order to create what I currently have. Everything I have tried I cannot seem to get those select files by their self in a new list. The code below currently reads all files and puts them in to the correct place. would it be more simple to also use the .AxisX. Command to get this to work?

 '2D ARRAY
  

   reader = New streamReader("R:PathTooriginalFile.csv")
     Dim stAll as String = reader.ReadToEnd
     reader.Close()
     MonitorIDTextFile = New StreamWrite("R:PathToWhereICoppiedTheFile", False)
     MonitorIDTextFiles.WriteLine(stALL) MonitorIDTextFile.close()

 
 'X-Axis Define 
     **strong text**Dim LinesForDateOfTheFile =
     File.ReadAllLines("R:PathToWhereICoppiedTheFile") For x_DOF = 1 to
     LineCount
     Dim data = LinesForDateOfTheFile(x_DOF)
     Dim splits = data.Split(","c)
     For y_DOF = 0 To myarray.GetUpperBound(1)
         myarray(x_DOF, y_DOF) = splits(y_DOF)
         DateOfFile = myarray(x_DOF, 3)
     Next 
     DateOfTheFileValues.Add(DateOfFile) 
Next 
    CountsOfTheDateOfFile = DateOfTheFileValues.Count -1
 
 'Y-AXIS Define 

 Dim LinesForCR1 =
 File.ReadAllLines("R:PathToWhereICoppiedTheFile") For x_CR1 = 1 to
 LineCount
     Dim data = LinesForCR1(x_CR1)
     Dim splits = data.Split(","c)
     Dim StringConversion As Single
     For y_CR1 = 0 To myarray.GetUpperBound(1)
         myarray(x_CR1, y_CR1) = splits(y_CR1)
         GrossCR1 = myarray(x_CR1, 44)
     Next 
     StringConversion = CSng(GrossCR1)
     GrossCR1 = StringConversion
     GrossCR1Values.Add(GrossCR1) Next CountsOfCR1 = GRossCR1Values.Count -1 

 'Plot Graph 

 ChartName.Titles.Add("Name Of
 Chart") ChartName.ChartAreas.Clear()
 ChartName.ChartAreas.Add("Default") With
 ChartName.ChartAreas("Dedault")
     Dim i As Integer
     For i = 0 to CountsOfDateOfFile
     Next
     .AxisX.Title = "Date"
     .AxisY.Title = "Counts"
     .Axisx.MajorGrid.LineColor = Color.Red
     .Axisx.Maximum = CountsOfDateOfFile
     .AxisY.MajorGrid.LineColor = Color.Orange
     ChartName.ChartAreas(0).AxisY.IsLogarithmic = True
     ChartName.Series.Clear() End With
     ChartName.Add("CR1")
     ChartName.Series("CR1").Color = Color.DarkTurquoise
     ChartName.Series("CR1").BorderDashStyle = 
     DataVisualization.Charting.ChartDashStyle.Dot
     ChartName.Series("CR1").BorderWidth = 4
     ChartName.Series("CR1").ChartType = 
     DataVisualization.Charting.SeriesChartType.Point
 
     For i1 As Integer = 0 To CountsOfCR1
         Dim y1 As Single
         Dim x1 AS Single
     x1 = DateOfFileValues(i1)
     y1 = GrossCR1Values(i1)
         If y1 = 0 Then y1 = 1 
     ChartName.Series("CR1").Points.AddXY(x1, y1)
     Next
  • Not an answer but may help. Seems to be a whole heap of redundancy in this code that really doesn't appear to have any point. Why read the original file just to write it out again, then read that file twice more? What's even the point of converting to lists when you can bind your chart direct to the array? – Hursey Aug 08 '23 at 00:13
  • It's a little hard to see where you are going wrong based on the code shown, because things don't seem to be broken down into subroutines. Might you please indicate where you are stuck? Better yet, can you [edit] your question to share 1) a sample of a CSV file you want to read (as text, not as a screen shot) and 2) the type you want to read it in as, which is presumably something like `List(Of T)` where `T` might be `List(Of String)`? – dbc Aug 08 '23 at 03:13
  • But perhaps [How to convert a 2D array to a 2D list in C#](https://stackoverflow.com/q/37458052) could help. Take [this answer](https://stackoverflow.com/a/37459282/3744182) by Ivan Stoev and translate it to vb.net with some online tool such as https://converter.telerik.com/ or https://icsharpcode.github.io/CodeConverter/. – dbc Aug 09 '23 at 18:35

1 Answers1

0

To create a new List from an ArrayList using vb.net, Enumerate the items in the ArrayList and add each item to a List.

        Dim anArrayList As New ArrayList()
        anArrayList.Add("sampleData3")
        anArrayList.Add("sampleData4")

        Dim lstString As New List(Of String)

        For Each item As String In anArrayList
            lstString.Add(item)
        Next

        For Each item In lstString
            Diagnostics.Debug.WriteLine(item)
        Next

        ''expected output:
        ''sampleData3
        ''sampleData4

To start with an Array instead of ArrayList, use:

Dim lstString As List(Of String) = arrString.ToList()

I am trying to create a list from a 2D array.

        Dim arrString(2) As String
        arrString(1) = "sampleData1"
        arrString(2) = "sampleData2"

        Dim lstString As List(Of String) = arrString.ToList()

        For Each item as String In lstString
            Diagnostics.Debug.WriteLine(item)
        Next
        'expected output:
        'sampleData1
        'sampleData2
Gary S
  • 46
  • 6