注册 登录
编程论坛 VB6论坛

各位高手,请帮忙持下这代码那里有问题,谢谢!

wyq7826275 发布于 2013-01-15 16:22, 291 次点击

Private Sub Command1_Click()
Dim q As Double
Dim k As Double
Dim λ As Double
Dim date_q(10000) As Double
Dim b As Double
Dim i As Double
q = Text1
k = Text2
For i = 0 To 10000
    λ = i / 10000
    b = ((k + 1) / 2) ^ (1 / (k - 1)) * λ * (1 - (k - 1) / (k + 1) * λ * λ) ^ (1 / (k - 1))
    date_q(i) = b
Next i
For i = 0 To 10000
     If q > date_q(i) Then Next i
     If q = date_q(i) Then Exit For
     If q < date_q(i) Then Exit For
λ = (i - (date_q(i) - q) / (date_q(i) - date_q(i - 1))) / 10000
Text3.Text = λ
End Sub
2 回复
#2
lowxiong2013-01-15 18:06
for next是唯一对应的语句对,不能单独作为条件语句执行,你的If q > date_q(i) Then Next i是不符合语法规范的,应改为
For i = 0 To 10000
'这一句去掉,既然小于或等于都跳出循环,那么进入循环的必然是大于     If q > date_q(i) Then Next i
'这一句也可去掉,因为VB有<=的关系符     If q = date_q(i) Then Exit For
     If q <= date_q(i) Then Exit For
next
#3
yz10252013-01-15 21:55
以下是引用wyq7826275在2013-1-15 16:22:00的发言:


Private Sub Command1_Click()
Dim q As Double
Dim k As Double
Dim λ As Double
Dim date_q(10000) As Double
Dim b As Double
Dim i As Double
q = Text1
k = Text2
For i = 0 To 10000
    λ = i / 10000
    b = ((k + 1) / 2) ^ (1 / (k - 1)) * λ * (1 - (k - 1) / (k + 1) * λ * λ) ^ (1 / (k - 1))
    date_q(i) = b
Next i
For i = 0 To 10000
     If q > date_q(i) Then Next i
     If q = date_q(i) Then Exit For
     If q < date_q(i) Then Exit For
λ = (i - (date_q(i) - q) / (date_q(i) - date_q(i - 1))) / 10000
Text3.Text = λ
End Sub


图解~Win7的装这软件显示不正常~将就点吧~
只有本站会员才能查看附件,请 登录
1