VB程式設計問題請教

2022-06-20 14:15:06 字數 3066 閱讀 5330

1樓:匿名使用者

if then語句有行語句和塊語句.

你這樣寫,第2個if a1 <= 375 then a2 = 0.571 是行語句

你看給你整理下.

private sub command5_click()

if a1 >= 0 and a1 <= 1000 then

if a1 <= 375 then a2 = 0.571

elseif a1 <= 425 then a2 = 0.525

elseif a1 <= 475 then a2 = 0.491

elseif a1 <= 525 then a2 = 0.457

elseif a1 <= 575 then a2 = 0.431

elseif a1 <= 625 then a2 = 0.405

elseif a1 <= 675 then a2 = 0.384

elseif a1 <= 725 then a2 = 0.363

elseif a1 <= 775 then a2 = 0.3465

elseif a1 <= 850 then a2 = 0.33

elseif a1 <= 950 then a2 = 0.301

else

msgbox "輸入溫度有誤,請重新輸入!"

end if

text14.text = a2

'輸出結果

end sub

當第一個條件成立後進入第2個行語句的判斷.

你的省下的elseif語句是和第一句並列的...如果第一個執行了後面的就不執行了.

改的話是這樣的;

private sub command5_click()

if a1 >= 0 and a1 <= 1000 then

if a1 <= 375 then

a2 = 0.571

elseif a1 <= 425 then a2 = 0.525

elseif a1 <= 475 then a2 = 0.491

elseif a1 <= 525 then a2 = 0.457

elseif a1 <= 575 then a2 = 0.431

elseif a1 <= 625 then a2 = 0.405

elseif a1 <= 675 then a2 = 0.384

elseif a1 <= 725 then a2 = 0.363

elseif a1 <= 775 then a2 = 0.3465

elseif a1 <= 850 then a2 = 0.33

elseif a1 <= 950 then a2 = 0.301

else

msgbox "你的a1是大於950的."

'你對大於950的在這裡給a2賦值吧。

end if

else

msgbox "輸入溫度有誤,請重新輸入!"

end if

text14.text = a2

'輸出結果

end sub

提個建議,你的a2是是要返回給text14的,所以建議把a2寫成字串"0.xx"

否則text14得到的數值沒有0

或者 text14.text =0 & a2 (因為你的a2全部都是小於0的可以這樣寫)

2樓:匿名使用者

你這樣的語法只會執行第一個if語句:

if a1 >= 0 and a1 <= 1000 then等於不執行命令....

後面的都不會執行了

可以用case語句,簡單點

3樓:在世貿天階灌籃的高飛燕草

private sub command5_click()if a1 >= 0 and a1 <= 1000 thenif a1 <= 375 then

a2 = 0.571

elseif a1 <= 425 thena2 = 0.525

elseif a1 <= 475 thena2 = 0.491

elseif a1 <= 525 thena2 = 0.457

elseif a1 <= 575 thena2 = 0.431

elseif a1 <= 625 thena2 = 0.405

elseif a1 <= 675 thena2 = 0.384

elseif a1 <= 725 thena2 = 0.363

elseif a1 <= 775 thena2 = 0.3465

elseif a1 <= 850 thena2 = 0.33

elseif a1 <= 950 thena2 = 0.301

else

msgbox "輸入溫度有誤,請重新輸入!"

end if

end if

text14.text = a2

end sub

4樓:匿名使用者

應該在最後一個else語句前插一行**:end if**將變為:

private sub command5_click()if a1 >= 0 and a1 <= 1000 thenif a1 <= 375 then a2 = 0.571elseif a1 <= 425 then a2 = 0.525elseif a1 <= 475 then a2 = 0.

491elseif a1 <= 525 then a2 = 0.457elseif a1 <= 575 then a2 = 0.431elseif a1 <= 625 then a2 = 0.

405elseif a1 <= 675 then a2 = 0.384elseif a1 <= 725 then a2 = 0.363elseif a1 <= 775 then a2 = 0.

3465elseif a1 <= 850 then a2 = 0.33elseif a1 <= 950 then a2 = 0.301end if

else

msgbox "輸入溫度有誤,請重新輸入!"

end if

text14.text = a2

'輸出結果

end sub

vb程式設計問題

private sub command1 click dim i,j as integer,s as double,n as double for i 1 to 100 n 1 for j 1 to i n n j next j s s n next i print 1 2 100 send sub...

vb程式設計問題

此方法是用隨機數產生20個不重複的數,顯示20個數,再挑出奇數,再排列,再顯示。數字之間用空格隔開。private sub command1 click text1 text2 dim a 1 to 20 b 1 to 20 as integer dim i,i1,i2,j,j1,j2,j3,j4,...

請教VB問題

新增一個command1按鈕控制元件 private sub command1 click dim i as integer,s as stringme.autoredraw true for i 1 to 9 s s cstr i me.print s next i end sub 很簡單 pri...