以下是小弟我淺學寫出的曲線表繪圖, 但是其中有不解的地方是 下方都會有警告訊息
''變數'xxx'已在指派值之前使用.可能會在執行階段產生null參考例外狀況''
雖然是可以使用, 但是一但套用在別的程式當副程式, 就會有錯誤狀況發生, 請問我該如何解決 ?
Dim A() As Integer = {152, 100, 142, 110, 180}
Dim B() As Integer = {98, 63, 64, 88, 79}
Dim C() As Integer = {76, 65, 64, 67, 75}
Dim D() As String = {"09:19", "11:30", "12:08", "12:59", "14:40"}
Dim COUNT As Integer = A.GetLength(0)
Dim G As Graphics = Me.CreateGraphics
Dim LBLACK2 As New System.Drawing.Pen(Color.Black, 2)
Dim LBLACK1 As New System.Drawing.Pen(Color.Black, 1)
Dim LRED1 As New System.Drawing.Pen(Color.Red, 1)
Dim LRED2 As New System.Drawing.Pen(Color.Red, 2)
Dim LRED5 As New System.Drawing.Pen(Color.Red, 5)
Dim LGREEN1 As New System.Drawing.Pen(Color.Green, 1)
Dim LGREEN2 As New System.Drawing.Pen(Color.Green, 2)
Dim LBLUE1 As New System.Drawing.Pen(Color.Blue, 1)
Dim SRED As New System.Drawing.SolidBrush(Color.Red)
Dim SGREEN As New System.Drawing.SolidBrush(Color.Green)
Dim SBLUE As New System.Drawing.SolidBrush(Color.Blue)
Dim font As New Font("新細明體", 8, FontStyle.Regular)
G.DrawRectangle(LBLACK2, 10, 5, Me.Width - 20, Me.Height - 100)
G.DrawLine(LBLACK1, 10, ((Me.Height - 100) / 3) + 5, Me.Width - 10, ((Me.Height - 100) / 3) + 5)
G.DrawLine(LBLACK1, 10, (((Me.Height - 100) / 3) * 2) + 5, Me.Width - 10, (((Me.Height - 100) / 3) * 2) + 5)
Dim X1 As Integer
X1 = (Mid(D(COUNT - 1), 1, 2) - Mid(D(0), 1, 2)) + 1
G.DrawLine(LGREEN2, 10 + 5, ((((Me.Height - 100 - 5) / 3) * 3) + 5 + 5) - 2, 10 + 5, ((((Me.Height - 100 - 5) / 3) * 3) + 5 + 5) + 2)
G.DrawString(Mid(D(0), 1, 2).ToString, font, SBLUE, 10 + 1, ((((Me.Height - 100 - 5) / 3) * 3) + 5 + 5) + 4)
Dim Z As Integer
For Z = 1 To X1
G.DrawLine(LGREEN2, (((Me.Width - (15 * 2)) / X1) * Z) + 15, (Me.Height - 100) + 5 - 2, (((Me.Width - (15 * 2)) / X1) * Z) + 15, (Me.Height - 100) + 5 + 2)
G.DrawString(Mid(D(0), 1, 2) + Z, font, SBLUE, (((Me.Width - (15 * 2)) / X1) * Z) + 8, ((Me.Height - 100) + 5 + 4))
Next
Dim CON, TIMEPOINT, SYS, DAI, PUL, POINTX, LINEX(), SYSY(), DAIY(), PULY(), L As Integer
L = 0
For CON = 0 To (COUNT - 1)
TIMEPOINT = ((Mid(D(CON), 1, 2) - Mid(D(0), 1, 2)) * 60) + Mid(D(CON), 4, 2)
POINTX = (((Me.Width - (15 * 2)) / (60 * X1)) * TIMEPOINT) + 15
SYS = CLng((((Me.Height - 5 - 100) / 3) * 2) + ((Me.Height - 5 - 100) / 3) - ((((Me.Height - 5 - 100) / 3) / 250) * A(CON)) + 12)
DAI = CLng((((Me.Height - 5 - 100) / 3)) + ((Me.Height - 5 - 100) / 3) - ((((Me.Height - 5 - 100) / 3) / 150) * B(CON)) + 12)
PUL = CLng((((Me.Height - 5 - 100) / 3) - ((((Me.Height - 5 - 100) / 3) / 150) * C(CON)) + 12))
POINTX = POINTX - 4
SYS = SYS - 4
DAI = DAI - 4
PUL = PUL - 4
L += 1
ReDim Preserve LINEX(L), SYSY(L), DAIY(L), PULY(L)
LINEX(L) = (((Me.Width - (15 * 2)) / (60 * X1)) * TIMEPOINT) + 12
SYSY(L) = CLng(SYS + 2)
DAIY(L) = CLng(DAI + 2)
PULY(L) = CLng(PUL + 2)
G.FillEllipse(SRED, POINTX, SYS, 4, 4)
G.FillEllipse(SGREEN, POINTX, DAI, 4, 4)
G.FillEllipse(SBLUE, POINTX, PUL, 4, 4)
Next
Dim LINK As Integer
For LINK = 1 To L - 1
G.DrawLine(LRED1, LINEX(LINK), SYSY(LINK), LINEX(LINK + 1), SYSY(LINK + 1))
G.DrawLine(LGREEN1, LINEX(LINK), DAIY(LINK), LINEX(LINK + 1), DAIY(LINK + 1))
G.DrawLine(LBLUE1, LINEX(LINK), PULY(LINK), LINEX(LINK + 1), PULY(LINK + 1))
Next
End Sub