vb课程设计报告(直线拟合) 下载本文

Private Sub Option1_Click() Form2.Label6.Enabled = False Form2.Label7.Enabled = False Form2.Label8.Enabled = False Form2.Label9.Enabled = False Form2.Label10.Enabled = False For n = 6 To 10

Form2.Text1(n).Enabled = False

Form2.Text1(n).BackColor = &H8000000F Form2.Text2(n).Enabled = False

Form2.Text2(n).BackColor = &H8000000F Next End Sub

Private Sub Option2_Click() Form2.Label6.Enabled = True Form2.Label7.Enabled = False Form2.Label8.Enabled = False Form2.Label9.Enabled = False Form2.Label10.Enabled = False Form2.Text1(6).Enabled = True

Form2.Text1(6).BackColor = &HFFFFFF Form2.Text2(6).Enabled = True

Form2.Text2(6).BackColor = &HFFFFFF For n = 7 To 10

Form2.Text1(n).Enabled = False

Form2.Text1(n).BackColor = &H8000000F Form2.Text2(n).Enabled = False

Form2.Text2(n).BackColor = &H8000000F Next End Sub

Private Sub Option3_Click() Form2.Label6.Enabled = True Form2.Label7.Enabled = True Form2.Label8.Enabled = False Form2.Label9.Enabled = False Form2.Label10.Enabled = False For n = 6 To 7

Form2.Text1(n).Enabled = True

Form2.Text1(n).BackColor = &HFFFFFF Form2.Text2(n).Enabled = True

Form2.Text2(n).BackColor = &HFFFFFF Next

For n = 8 To 10

Form2.Text1(n).Enabled = False

Form2.Text1(n).BackColor = &H8000000F Form2.Text2(n).Enabled = False

Form2.Text2(n).BackColor = &H8000000F Next End Sub

Private Sub Option4_Click() Form2.Label6.Enabled = True Form2.Label7.Enabled = True Form2.Label8.Enabled = True Form2.Label9.Enabled = False Form2.Label10.Enabled = False For n = 6 To 8

Form2.Text1(n).Enabled = True

Form2.Text1(n).BackColor = &HFFFFFF Form2.Text2(n).Enabled = True

Form2.Text2(n).BackColor = &HFFFFFF Next

For n = 9 To 10

Form2.Text1(n).Enabled = False

Form2.Text1(n).BackColor = &H8000000F Form2.Text2(n).Enabled = False

Form2.Text2(n).BackColor = &H8000000F Next End Sub

Private Sub Option5_Click() Form2.Label6.Enabled = True Form2.Label7.Enabled = True Form2.Label8.Enabled = True Form2.Label9.Enabled = True Form2.Label10.Enabled = False Form2.Text1(10).Enabled = False

Form2.Text1(10).BackColor = &H8000000F Form2.Text2(10).Enabled = False

Form2.Text2(10).BackColor = &H8000000F For n = 6 To 9

Form2.Text1(n).Enabled = True

Form2.Text1(n).BackColor = &HFFFFFF Form2.Text2(n).Enabled = True

Form2.Text2(n).BackColor = &HFFFFFF Next

End Sub

Private Sub Option6_Click() Form2.Label6.Enabled = True Form2.Label7.Enabled = True Form2.Label8.Enabled = True Form2.Label9.Enabled = True Form2.Label10.Enabled = True For n = 6 To 10

Form2.Text1(n).Enabled = True

Form2.Text1(n).BackColor = &HFFFFFF Form2.Text2(n).Enabled = True

Form2.Text2(n).BackColor = &HFFFFFF Next End Sub

Form2:

Option Base 1 Dim m As Integer Dim X(10) As Single Dim Y(10) As Single

Private Sub Command1_Click() '进入第三个绘图窗体 Form1.Hide Form2.Hide Form3.Show

Dim A As Single '截距 Dim B As Single '斜率 Dim c As Single Dim d As Single Dim e As Single Dim f As Single Dim W As Single Dim R As Single Dim T As Single '讨论点的个数

If Form2.Text1(5).Enabled = True Then m = 5 If Form2.Text1(6).Enabled = True Then m = 6 If Form2.Text1(7).Enabled = True Then m = 7 If Form2.Text1(8).Enabled = True Then m = 8

If Form2.Text1(9).Enabled = True Then m = 9 If Form2.Text1(10).Enabled = True Then m = 10

'对点的x.y坐标进行赋值 If m = 5 Then

For n = 1 To 5

X(n) = Text1(n).Text Y(n) = Text2(n).Text Next End If

If m = 6 Then For n = 1 To 6

X(n) = Text1(n).Text Y(n) = Text2(n).Text Next End If

If m = 7 Then For n = 1 To 7

X(n) = Text1(n).Text Y(n) = Text2(n).Text Next End If

If m = 8 Then For n = 1 To 8

X(n) = Text1(n).Text Y(n) = Text2(n).Text Next End If

If m = 9 Then For n = 1 To 9

X(n) = Text1(n).Text Y(n) = Text2(n).Text Next End If

If m = 10 Then For n = 1 To 10

X(n) = Text1(n).Text Y(n) = Text2(n).Text Next End If

For n = 1 To m c = X(n) + c

d = X(n) * X(n) + d

e = X(n) * Y(n) + e f = Y(n) + f Next

A = (e * c - f * d) / (c * c - m * d) '计算直线的截距 B = (c * f - m * e) / (c * c - m * d) '计算直线的斜率

'打印数据方程的位置 Form3.CurrentX = 200 Form3.CurrentY = 350

Form3.Print \直线斜率(B)=\Form3.CurrentX = 200 Form3.CurrentY = 580

Form3.Print \直线截距(A)=\Form3.CurrentX = 200 Form3.CurrentY = 810

Form3.Print \直线方程为:\'在坐标图上打印出点来 For n = 1 To m

Form3.PSet (360 + 37 * X(n), 5400 - 37 * Y(n)), RGB(0, 0, 0) Next

W = 5400 - 3700 * B - 37 * A R = 360 + (3700 - 37 * A) / B T = 360 - 37 * A / B

'将超出坐标轴的线去掉 If A >= 0 Then

Form3.Line (360, 5400 - 37 * A)-(4060, W)

If W < 1700 Then Form3.Line (R, 1700)-(4060, W), &H8000000F

If W > 5400 And B < 0 Then Form3.Line (T, 5400)-(4060, W), &H8000000F Else

Form3.Line (360 + (5400 - 37 * A) / B, 5400)-(4060, W)

If W < 1700 Then Form3.Line (R, 1700)-(4060, W), &H8000000F

If W > 5400 And B < 0 Then Form3.Line (T, 5400)-(4060, W), &H8000000F End If End Sub

'返回第一个窗体

Private Sub Command2_Click() Form1.Show Form2.Hide Form3.Hide For n = 1 To m

Text1(n).Text = \ Text2(n).Text = \Next End Sub