18063219
級(jí)別: *
精華主題: * 篇
發(fā)帖數(shù)量: * 個(gè)
工控威望: * 點(diǎn)
下載積分: * 分
在線時(shí)間: (小時(shí))
注冊(cè)時(shí)間: *
最后登錄: *
查看18063219的 主題 / 回貼
樓主  發(fā)表于: 2010-04-29 13:45
某程序的功能是a1<=q<a2,Shape1.FillColor = vbGreen;q<a4,Shape1.FillColor = vbRed
a2<=q<a3,Shape2.FillColor = vbGreen,Shape2.FillColor = vbGreen  ;q<a5,Shape2.FillColor = vbRed
a3<=q<15,Shape3.FillColor = vbGreen,Shape2.FillColor = vbGreen,Shape1.FillColor = vbGreen;q<a6,Shape3.FillColor = vbRed
我寫的程序存在的問題:shape1顯示正常,其余兩個(gè)顯示綠色沒問題,但若要顯示紅色不能顯示,任然是綠色,不發(fā)生變化。
Private Sub Command2_Click()
Const pi = 3.14159
Dim t As Single, y As Single, p As Single
Dim a1 As Single, a2 As Single, a3 As Single, a4 As Single, a5 As Single, a6 As Single, q As Single



a1 = Val(Text1.Text)
a2 = Val(Text2.Text)
a3 = Val(Text3.Text)
a4 = Val(Text4.Text)
a5 = Val(Text5.Text)
a6 = Val(Text6.Text)
For t = 0 To 24 Step 0.0003
y = -2 * Sin(t * pi / 1.5) + 3

p = y / 5
Text8.Height = Text7.Height * (1 - p)
q = p * 15
Text9.Text = q
Shape1.Refresh
DoEvents
Select Case q


Case 0 To a4
Shape1.FillColor = vbRed
Case a1 To a2
Shape1.FillColor = vbGreen


Case a4 To a5
Shape2.FillColor = vbRed
Case a2 To a3
Shape2.FillColor = vbGreen
Shape1.FillColor = vbGreen


Case a5 To a6
Shape3.FillColor = vbRed
Case a3 To 15
Shape3.FillColor = vbGreen
Shape2.FillColor = vbGreen
Shape1.FillColor = vbGreen


End Select
Next t
End Sub
[ 此帖被18063219在2010-04-29 20:41重新編輯 ]
sjm213
有小知識(shí),無大學(xué)問。
級(jí)別: 論壇版主

精華主題: 7 篇
發(fā)帖數(shù)量: 5196 個(gè)
工控威望: 7419 點(diǎn)
下載積分: 158630 分
在線時(shí)間: 3154(小時(shí))
注冊(cè)時(shí)間: 2007-11-21
最后登錄: 2024-11-13
查看sjm213的 主題 / 回貼
1樓  發(fā)表于: 2010-04-29 23:16
Select Case 結(jié)構(gòu)在滿足第一個(gè)條件后就自動(dòng)跳到End Select。
而你的幾個(gè)CASE中有重疊部分,所以只會(huì)前者有效。
你可以試一下IF …Then