当前位置 - 股票行情交易網 - 企業服務 - Private Sub Command1_Click() A = Val(Text1.Text): B = Val(Text2.Text) For M = A To B M = M + 1 Next

Private Sub Command1_Click() A = Val(Text1.Text): B = Val(Text2.Text) For M = A To B M = M + 1 Next

下面是根據妳的程序改起來的,改動的地方就是把Form_load函數中的40個雙引號去掉

Option Explicit

Option Base 1

Const num = 10

Dim a(num) As Single, b(num) As Single, c(num) As Single

Dim x As Single, m As Single

Dim sum As Single, i As Integer

Private Sub Command1_Click()

sum = 0

For i = 1 To num

c(i) = ((a(i) - 60) / 10 + 1) * b(i)

sum = sum + c(i)

Next i

x = sum / m

Print "Text00.Text"; x

End Sub

Private Sub Form_Load()

a(1) = Val(Text1.Text) '各科成績

a(2) = Val(Text2.Text)

a(3) = Val(Text3.Text)

a(4) = Val(Text4.Text)

a(5) = Val(Text5.Text)

a(6) = Val(Text6.Text)

a(7) = Val(Text7.Text)

a(8) = Val(Text8.Text)

a(9) = Val(Text9.Text)

a(10) = Val(Text10.Text)

b(1) = Val(Text11.Text) '各科學分

b(2) = Val(Text12.Text)

b(3) = Val(Text13.Text)

b(4) = Val(Text14.Text)

b(5) = Val(Text15.Text)

b(6) = Val(Text16.Text)

b(7) = Val(Text17.Text)

b(8) = Val(Text18.Text)

b(9) = Val(Text19.Text)

b(10) = Val(Text20.Text)

m = Val(Text0.Text) '總學分

End Sub

============================================

下面是我給妳寫的程序,妳可以和妳的程序比較壹下孰優孰劣

窗體上左上角放壹個TextBox和右邊放壹個按鈕就可以了,不需要象妳那樣放21個TextBox

Option Explicit

Option Base 1

Const Total = 10

Private Sub Command1_Click()

Dim Sum As Single, Score(Total) As Single, Credit(Total) As Single

Dim i As Integer, SumCredit As Integer

For i = 1 To Total

Score(i) = (Val(Text1(i - 1).Text) - 60) / 10 + 1

Credit(i) = Val(Text1(i + Total - 1).Text)

Sum = Sum + Score(i) * Credit(i)

SumCredit = SumCredit + Credit(i)

Next i

MsgBox "平均學分:" & Format(Sum / SumCredit, "0.00")

End Sub

Private Sub Form_Load()

Dim i As Integer

Text1(0).Text = 90

For i = 0 To Total - 1

If i <> 0 Then

Load Text1(i)

Text1(i).Left = Text1(0).Left

Text1(i).Top = Text1(i - 1).Top + Text1(0).Height + 100

Text1(i).Visible = True

Text1(i).Text = Int(Rnd * 60) + 35

End If

Load Text1(i + Total)

Text1(i + Total).Left = Text1(0).Left + Text1(0).Width + 400

Text1(i + Total).Top = Text1(i).Top

Text1(i + Total).Visible = True

Text1(i + Total).Text = Int(Rnd * 5) + 1

Next

End Sub

=========================================

我覺得,妳的程序的壹個閃光點就是

c(i) = ((a(i) - 60) / 10 + 1) * b(i)

這壹句.如果這句是妳自己寫的,那證明妳還是很有想法的