TextChanged 和 switch 语句来判断更改的文本框并重建图表数据并更新(索引超出范围)VB.Net



我正在努力使用 switch 语句和 textchanged 来更新表单面板中的图表,以便在更改文本时图表将与新值重新绑定,从而在某种意义上创建一个动态图表。

我下面的代码不断返回超出Case T8K.Name : Me.yvals(7) = Convert.ToInt32(T8K.Text)范围的索引。(见下文(

还必须指出,所有文本框和图表都位于面板内

任何人都可以协助我可能做错了什么。

Public Class Dashboard
    Private xvals As New List(Of Integer)
    Private yvals As New List(Of Integer)
Private Sub Dashboard_Load(Sender As Dashboard, e As EventArgs) Handles MyBase.Load
        'loads data into the 'TCClientDBDataSet.Client_DB' table.
        Me.Client_DBTableAdapter.Fill(Me.TCClientDBDataSet.Client_DB)
        'Chart Setup
        'Dim A5K1 As Integer = T5K1.Text
        'Dim A5K2 As Integer = T5K2.Text
        'Dim A5K3 As Integer = T5K3.Text
        'Dim average = (A5K1 + A5K2 + A5K3) / 3
        Me.xvals = New List(Of Integer) From {1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000}
        Me.yvals = New List(Of Integer) From {T1K.Text, T2K.Text, T3K.Text, T4K.Text, T5K1.Text, T6K.Text, T7K.Text, T8K.Text, T9K.Text, T10K.Text}
        Dim xmaxvals() As Integer = ({1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000})
        Dim ymaxvals() As String = {tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text, tst_MaxOutput.Text}
        Testpoint_Chart.Series.Clear()
        Testpoint_Chart.Series.Add("Test Data")
        Testpoint_Chart.Series.Add("Max Torque")
        With Testpoint_Chart.ChartAreas(0)
            .AxisX.Title = "Pressure (Psi)"
            .AxisX.Minimum = 1000
            .AxisX.Maximum = 10000
            .AxisX.Interval = 1000
            .AxisY.Interval = 1000
            .AxisY.Title = "Test Points (ft.lb)"
            'If T10K.Text > Math.Ceiling(tst_MaxOutput.Text / 1000) * 1000 Then
            .AxisY.Maximum = Math.Ceiling(T10K.Text / 1000) * 1000
            'Else
            '.AxisY.Maximum = Math.Ceiling(tst_MaxOutput.Text / 1000) * 1000
            'End If
        End With
        'Test Points
        With Testpoint_Chart.Series("Test Data")
            .IsVisibleInLegend = True
            .ChartType = SeriesChartType.Line
            .IsValueShownAsLabel = True
            .Points.DataBindXY(Me.xvals, Me.yvals)
        End With
        'Max Torque
        With Testpoint_Chart.Series("Max Torque")
            .IsVisibleInLegend = True
            .ChartType = SeriesChartType.Line
            .IsValueShownAsLabel = False
            .Color = Color.Red
            .Points.DataBindXY(xmaxvals, ymaxvals)
        End With
    End Sub
    Private Sub TextBox_TextChanged(Sender As TextBox, e As EventArgs) Handles T1K.TextChanged, T2K.TextChanged, T3K.TextChanged, T4K.TextChanged, T5K1.TextChanged, T6K.TextChanged, T7K.TextChanged, T8K.TextChanged, T9K.TextChanged, T10K.TextChanged
        Select Case Sender.Name
            Case T1K.Name : Me.yvals(0) = Convert.ToInt32(T1K.Text)
            Case T2K.Name : Me.yvals(1) = Convert.ToInt32(T2K.Text)
            Case T3K.Name : Me.yvals(2) = Convert.ToInt32(T3K.Text)
            Case T4K.Name : Me.yvals(3) = Convert.ToInt32(T4K.Text)
            Case T5K1.Name : Me.yvals(4) = Convert.ToInt32(T5K1.Text)
            Case T6K.Name : Me.yvals(5) = Convert.ToInt32(T6K.Text)
            Case T7K.Name : Me.yvals(6) = Convert.ToInt32(T7K.Text)
            Case T8K.Name : Me.yvals(7) = Convert.ToInt32(T8K.Text)
            Case T9K.Name : Me.yvals(8) = Convert.ToInt32(T9K.Text)
            Case T10K.Name : Me.yvals(9) = Convert.ToInt32(T10K.Text)
        End Select
        Me.Testpoint_Chart.Series("Test Data").Points.DataBindXY(Me.xvals, Me.yvals)
        Me.Testpoint_Chart.Update()
    End Sub

非常感谢@jmcilhinney 事实证明,这是 String 的转换问题,这意味着我的索引是空的,因此在对代码进行了一些修改并将 NumericUpDown 控件与数组一起使用后,我设法让它工作。

相关内容

  • 没有找到相关文章

最新更新