Vb程式設計 if 不判斷 end if放在哪裡

2025-07-17 11:55:29 字數 2846 閱讀 2802

vb裡面,什麼時候if then的語句不用加end if 在後面?要說明情況,可以舉例說明

1樓:天涯路易

if a then b 行語句不需要else或end ifif a then 塊語句沒用else必須要end ifbend if

if a then 塊語句用了else必須要end ifbelse

c 不滿足條件a時就執行cend if

要不要else就取決於你要不要執行或有沒有必要執行條件c

2樓:網友

單句if語句不用加,即if語句只有一行,例如:

if a=3 then b=2

下面的要加end if,多行。

if a=3 then

b=2end if

3樓:

在一句裡寫完的就不用end if

例如if a=b then c=1:d=2:e=3否則就要。

if a=b then

c=1:d=2:e=3

end if

(vb程式設計)end if沒有塊if

4樓:

把你的end if 去掉就行了。

vb程式內顯示塊if 沒有end if……

5樓:帳號已登出

if val(<500 then

猜的太小"elseif val( then

猜對"猜的太大"

end if

end if

例如:private sub command1_click()dim x as integer

if x >=90 then

a等"elseif x >=80 then

b等"elseif x >=60 then

c等"elseif x < 60 then

e等"end if

end if ' 這裡漏了個end if

end if

end if

end sub

請留意**裡,變數x未賦值,請補上賦值**,否則變數x將恆為0。

6樓:遠巨集

書寫不規範,不容易看出缺少end if,應該這樣寫:

if val(<500 then

你猜的太小了"

elseif val( then

你猜對了"你猜的太大了"

end if

end if

乙個if對應乙個end if,在寫程式時,寫好if後立即換行寫好end if,這樣不容易出錯。

7樓:網友

嗯 1樓說的對你 確實少了乙個 end if 因為乙個if語句只能有乙個else如果想判斷多個用select case比較好,如果你想用if的話 多次判斷就用elseif就可以了 例如:

if...then

elseif ..then

elseend if

就可以了。

8樓:網友

sheets("商品入庫已及查詢").select '-啟用工作表"商品入庫已及查詢"

msgbox "品名請勿空白!",vbokonly

之間缺少:if trim(cells(7, 1).value) =then

9樓:kiss泰坦

你確實少加了乙個end if,你加在end sub之前就行了。

10樓:網友

private sub command1_click()

label1=iif(val(text1) <500, "你猜的太小了", iif(val(text1) =500, "你猜對了", 你猜的太大了"))

end sub

11樓:網友

不是說的很清楚嘛,你有兩個if語句,而只有乙個endif

12樓:海子

在 end sub 前面加個 end if 就ok啦 那麼簡單。

13樓:網友

改用select case吧。

你這確實少了乙個end if

vb語言if一定要有end if結尾嗎

14樓:網友

then 後面語句寫於if同一行 則不需要end if

多語句寫同行可用冒號連線。

15樓:網友

不是一定。例如。

private sub command1_click()a = 5

if a > 0 then msgbox "hello" '關鍵是看這裡then後面語句,如果僅有一句,不轉行。不用endif

if a>0 then '這種情形就一定要!

msgbox "yes"

elsemsgbox "no"

endifend sub

這樣就不用。

16樓:我叫明輝

不一定,這個分兩種形式.

一、if ..then ..這種不用.二、if ..then ..else

end if

這個要.

vb中什麼時候用if語句後面用end if 結束?什麼時候不用?

17樓:網友

如果執行語句比較簡單。

可以和if書寫在同一行。

那麼就可以不寫。

例如 if 。。then 。。

如果有多條執行語句。

就必須多行書寫,結尾必須有endif

VB程式設計,vb程式設計是什麼?

51 len函式,檢測字元成的長度。right函式,從右邊在指定的字串中擷取一定數量的字元組成新的字串。52 dim a 9 as nteger 惠用紅色標註這一行,不能執行。以下省略。vb程式設計是什麼?1 vb程式設計以visual basic 6.0簡體中文版為語言背景,深入淺出的介紹visu...

vb程式設計問題,VB程式設計問題

設 text1 text2 text3 text4 command1 label1 4個test輸入資料 command1是按鈕 label1顯示內容 我給你寫一個子程式 其它你在工具欄向視窗託就行了,然後把這個子程式複製到 做就ok了 private command1 click dim maxa...

EXCEL中VB程式設計關於模糊判斷單元文字的問題(程式設計高手進)

t range a1 value if instr 1,t,糖 0 and instr 1,t,連 0 and instr 1,t,指 0 then range a2 range a1 else range a2 end if 子易空間站 excel培訓專家 呵呵,vba做這個還是夠簡單的!sub ...