VB编程问题,求指教
用户从键盘上输入股票30天的收盘价,程序计算并显示滑动平均价(每行显示五天滑动平均价)。说明:当天的滑动平均价为前五天收盘价的平均值,前四天的滑动平均价按当天收盘价计算...
用户从键盘上输入股票30天的收盘价,程序计算并显示滑动平均价(每行显示五天滑动平均价)。说明:当天的滑动平均价为前五天收盘价的平均值,前四天的滑动平均价按当天收盘价计算
展开
1个回答
展开全部
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim x(30) As Single, y(30) As Single
For i = 1 To 30
x(i) = InputBox("请输入第" & i & "天的收盘价:", 0)
Next
For i = 1 To 26
x(0) = 0
For j = 1 To 5
x(0) = x(0) + x(i + j - 1)
Next
y(i + 5 - 1) = x(0) / 5
Next
For i = 1 To 4
x(0) = 0
For j = 1 To i
x(0) = x(0) + x(j)
Next
y(i) = x(0) / (j - 1)
Next
For i = 1 To 30
Circle (50 + i * 100, 1500 - x(i) * 10), 10
Circle (50 + i * 100, 1500 - y(i) * 10), 10
Circle (50 + i * 100, 1500), 10
Next
For i = 1 To 30
Print y(i);
If i Mod 5 = 0 Then Print
Next
End Sub
下面是随机生成收盘价
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim x(30) As Single, y(30) As Single
Dim x0 As Integer, y0 As Integer
Dim x1 As Integer, y1 As Integer
For i = 1 To 30
'x(i) = InputBox("请输入第" & i & "天的收盘价:", 0)
x(i) = Round(Rnd * 10 + 15, 2)
Next
x0 = 50 + 100
y0 = 1500 - x(1) * 40
For i = 1 To 26
x(0) = 0
For j = 1 To 5
x(0) = x(0) + x(i + j - 1)
Next
y(i + 5 - 1) = x(0) / 5
Next
For i = 1 To 4
x(0) = 0
For j = 1 To i
x(0) = x(0) + x(j)
Next
y(i) = x(0) / (j - 1)
Next
x1 = 50 + 100
y1 = 1500 - y(1) * 40
For i = 1 To 30
'Circle (50 + i * 100, 1500 - x(i) * 40), 20, RGB(0, 255, 0)
'Circle (50 + i * 100, 1500 - y(i) * 40), 20, RGB(255, 0, 0)
Line (x0, y0)-(50 + i * 100, 1500 - x(i) * 40), RGB(0, 255, 0)
x0 = 50 + i * 100
y0 = 1500 - x(i) * 40
Line (x1, y1)-(50 + i * 100, 1500 - y(i) * 40), RGB(255, 0, 0)
x1 = 50 + i * 100
y1 = 1500 - y(i) * 40
Circle (50 + i * 100, 1500), 10
Next
For i = 1 To 30
Print y(i);
If i Mod 5 = 0 Then Print
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询