Issue Converting DataType (VSE 2010, .NET 4.0)

VSE 2010 , .NET 4.0 , datatype , cdbl Independence, United States
  • 10 years ago

    I am attempting to fill a DataTable with columns of numbers from a CSV to create lines on a third party chart control called Zedgraph. The problem is, the control keeps plotting one-to-one lines of point counts (in other words, if the column has 400 points, it plots a straight line from 0,0 to 400,400). I believe it is doing this because the data in my table is still being input as type String, which it shouldn't given the Cdbl(Var(x)) function I have written in. Why do you think my table values are still of type String?

    Imports ZedGraph

    Public Class Form1

    Private Sub CreateDataset(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim DataSet As New DataSet If OpenFileDialog1.ShowDialog() = DialogResult.OK Then DataSet = getCsvToDataset(OpenFileDialog1.FileName) End If

    Call ChartFill(DataSet)

    End Sub

    Private Sub ChartFill(ByVal DS As DataSet) Dim ChartPane As GraphPane = ZG1.GraphPane Dim dspl As New DataSourcePointList With dspl .DataSource = DS.Tables(0) .XDataMember = "Time Slot" .YDataMember = "X1 1000 Air" End With

    Dim line1 As CurveItem line1 = ChartPane.AddCurve("X1 1000 Air", dspl, Color.Aquamarine)

    ChartPane.AxisChange()

    End Sub

    Private Shared Function getCsvToDataset(ByVal strPath As String) As DataSet Dim strLine As String Dim strArray As String() Dim charArray As Char() = New Char() {","c} Dim ds As New DataSet() Dim dt As DataTable = ds.Tables.Add("TheData") Dim aFile As New IO.FileStream(strPath, IO.FileMode.Open) Dim sr As New IO.StreamReader(aFile)

    strLine = sr.ReadLine() strArray = strLine.Split(charArray)

    For x As Integer = 0 To strArray.GetUpperBound(0) dt.Columns.Add(strArray(x).Trim()) Next

    strLine = sr.ReadLine() While strLine IsNot Nothing strArray = strLine.Split(charArray) Dim dr As DataRow = dt.NewRow() For i As Integer = 0 To strArray.GetUpperBound(0) dr(i) = strArray(i).Trim() If dr(i) <> "" Then dr(i) = CDbl(Val(dr(i))) End If Next dt.Rows.Add(dr) strLine = sr.ReadLine() End While sr.Close()

    Dim ds2 As New DataSet Dim dt2 As DataTable = ds2.Tables.Add("MoreData")

    Return (ds) End Function

    End Class

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Better train people and risk they leave – than do nothing and risk they stay.” - Anonymous