18063219
級(jí)別: *
|
某程序的功能是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 我寫(xiě)的程序存在的問(wèn)題:shape1顯示正常,其余兩個(gè)顯示綠色沒(méi)問(wèn)題,但若要顯示紅色不能顯示,任然是綠色,不發(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í),無(wú)大學(xué)問(wèn)。
級(jí)別: 論壇版主
|
Select Case 結(jié)構(gòu)在滿足第一個(gè)條件后就自動(dòng)跳到End Select。 而你的幾個(gè)CASE中有重疊部分,所以只會(huì)前者有效。 你可以試一下IF …Then |
---|---|
|
ydp
級(jí)別: *
|
問(wèn)題找到了,a1 = Val(Text1.Text),這樣的寫(xiě)法,是取整數(shù),而且 你設(shè)置的是有小數(shù)點(diǎn) |
---|---|
本帖最近評(píng)分記錄: |
ydp
級(jí)別: *
|
兩種解決問(wèn)題,一就,你把所有數(shù)據(jù)都變大100倍,不要小數(shù)(好多似類的數(shù)量都是這樣數(shù)) |
---|---|
本帖最近評(píng)分記錄: |
ydp
級(jí)別: *
|
Dim a1 As Double Dim a2 As Double Dim K as double //定義水位 a2 = CDbl(Text1.Text) a2 = CDbl(Text1.Text) k = CDbl(水位的字符串) if k <= a2 then Shape1.FillColor = vbRed end if if k >= a1 then Shape1.FillColor = vbGreen end if |
---|---|
本帖最近評(píng)分記錄: |
vili
級(jí)別: *
|
就例如,C水位, 如果當(dāng)前水位在13.5-14之間,你如何顯示??顯示綠色,還是紅色,這個(gè)在你上面的程序沒(méi)有處理。 |
---|---|
|