vb程式設計if語句的使用,VB程式設計IF語句的使用

時間 2021-12-19 15:19:31

1樓:匿名使用者

if《條件》then

《語句》

《語句》

...end if

與c語言不同,(vb)的條件語句更符合英語的語法,如果then後面所跟的語句只有一條,可以寫成:

if 《條件》 then

不用end if

有時還用到:

if《條件》then

《語句》

else

《語句》

end if

還可以在else裡再巢狀if語句,如

if 《條件》 then

《語句》

else if

《語句》

else

《語句》

end if

2樓:匿名使用者

真的太多了 我

if dir("d:\2.exe")<>"" then msgbox "有檔案"

if dir("d:\2.exe")<>"" then else msgbox "沒檔案"

if dir("d:\2.exe")<>"" and dir("d:\3.exe")<>"" then

msgbox "都有"

elseif dir("d:\2.exe")<>"" then

msgbox "有2檔案"

elseif dir("d:\3.exe")<>"" then

msgbox "有3檔案"

else

msgbox "都沒有"

end if

if dir("d:\1.exe")<>"" or dir("d:\2.exe") <>"" then

msgbox "有檔案不知道是哪個"

end if

3樓:匿名使用者

vb的這個if其實可以用意思來配上去的.. if在這裡就是"如果/判斷". then在這裡就是"接著".

else在這裡就是"相反"..end if在這裡就是"結束判斷" ..

這些只是我的翻譯..但是理解這些就比較好用了..

比如例子:

if text1.text = "ok" then ' 如果text1.text裡面的內容是"ok" 那麼就執行下列**

msgbox "文字框裡的內容是ok"

else '相反,如果text1.text裡面的內容不是"ok", 那麼就執行下列**

msgbox "文字框裡的內容不是ok"

end if

這裡只是一個簡單的判斷.. 判斷text1.text裡面的內容是不是"ok"

例子2:

if dir("c:\1.exe") <> "" then

msgbox "c盤有1.exe"

else

msgbox "c盤沒有1.exe"

end if

總之,有if就必須要end if

後面有end if 前面也必須要 if

認真學喔..! 加油..

vb中的if語句

4樓:荀曾顏念雁

檢測事件是在文字框中的change事件中判斷,也就是說只要文字框有改變就檢測!

如果把其中的

and改寫成

or就可以判斷其中一個文字是否為空!

private

subtext1_change()

'判斷文字框最快的速度還是判斷它的長度是否為0iflen(text1.text)=0

andlen(text2.text)=0

then

image5.visible

=false

else

image5.visible

=true

endif

endsub

private

subtext2_change()

iflen(text1.text)=0

andlen(text2.text)=0

then

image5.visible

=false

else

image5.visible

=true

endif

endsub

完美財經網

5樓:檢霽杜鵾

if《條件》then

《語句》

《語句》

...end

if與c語言不同,(vb)的條件語句更符合英語的語法,如果then後面所跟的語句只有一條,可以寫成:

if《條件》

then

不用end

if有時還用到:

if《條件》then

《語句》

else

《語句》

endif

還可以在else裡再巢狀if語句,如

if《條件》

then

《語句》

else

if《語句》

else

《語句》

endif

6樓:樂觀的召喚師

每一層要用end if來結束本層判斷。

7樓:取名字嚴重難

private sub text1_keypress(keyascii as integer)

select case len(text1.text)case 0

if keyascii < 49 or keyascii > 57 then keyascii = 0

case 1

if keyascii < 48 or keyascii > 57 then

if keyascii <> 8 thenkeyascii = 0

end if

end if

case else

if keyascii = 8 then

else

keyascii = 0

end if

end select

end sub

我這個測試了效果很好 在顯示前做判斷

8樓:錯覺

dim a

a=int(a)

a=inputbox("輸入數值")

if a <100

moveto 文字的座標

else

moveto 非文字的座標

endif

9樓:

input "n"

if n<100

list n

else

wait

10樓:匿名使用者

private sub text1_lostfocus()

if text1.text = "" or isnumeric(text1.text) = false or val(text1.

text) >= 100 then text1.setfocus

end sub

vb裡 if語句什麼情況下不用加end if ?

11樓:她是我的小太陽

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

if a=3 then b=2

下面的要加end if,多行

if a=3 then

b=2end if

**有換行就要用end if

不換行就不用end if

例如:例一:

if ***x then yyyy '這時就不用也不可以用end if

例二:if ***x then

yyyy

end if '這時就必須要用end if

12樓:

嚴格的程式語言和良好的程式設計習慣都要求成對編寫**,所以,最好有if的地方,後面有end if。

13樓:匿名使用者

不換行的不需要endif。

但是好的程式設計習慣是哪怕只有一行,也要換行並加上endif。一方面可讀性好,另一方面便於跟蹤除錯和設定斷點。

14樓:匿名使用者

**有換行就要用end if

不換行就不用end if

例如:例一:

if ***x then yyyy '這時就不用也不可以用end if

例二:if ***x then

yyyy

end if '這時就必須要用end if

vb中if巢狀語句

15樓:baby_原來

if 條件為真 then

執行語句

end if(判斷結束)

if a=3 then

if b=2 then

if c=7 then

if d=8 then

以上條件都成立的時候執行下邊一段話

.....執行**並結束這個判斷

(假如d=5,則執行下邊的**)

else

...........執行**

end if (這裡是結束d=8 這個條件的)end if(這裡是結束c=7這個條件的)end if(這裡是結束b=2這個條件的)end if(這裡是結束a=3這個條件)

16樓:

vb6中 if then 可以允許寫在一行中,如果一行中的then後需要跟不止一個語句,可以在語句間加冒號,如:

if 2 = 2 then text1.text = 2: text2.text = 2

要理解這一點,你只需要記住 vb語句與語句之間可以通過換行符來識別...

17樓:匿名使用者

if語句可以像下面這樣子寫

第一種if ... then ...

第二種if ... then

......

end if

第三種if ... then

......

else

......

end if

第四種if ... then ... else ...

總的來說,如果是分開兩行寫的話,就要end if,一行的就不用了

18樓:谷歌vip使用者

不需要了

假如判斷條件a=b為真,執行suba,否則執行subb,用下面的**格式可以省略end if,else不用也可以。

if a=b then suba else subb寫在一行可以省略end if。

如果a=b你要同時執行suba和subb的話,語句間用半形的:隔開就可以了

if a=b then suba:subb else subb用:符號可以在一行**中寫n行**。

例如 a=b:a=c:a=d

等價於a=b

a=ca=d

這樣也是不會出錯的。

你上面所提到的

if keyascii=13 then text2.setfocus等價於if keyascii=13 thentext2.setfocus

end if

如果分開兩行寫必須有end if

因為編譯器需要知道你在什麼時候結束if判斷,判斷條件和處理結果寫在一行編譯器可以知道你什麼時候結束if語句,如果寫在兩行,編譯器就無法識別了,所以必須新增end if。

19樓:荔菲彭澤

if keyascii=13 then text2.setfocus

這一句不需要end if

vb程式設計,VB程式設計

大哥你這個問題很簡單,只不過在這裡不能把 全給你,你的問題描述的不清楚,我吧幾個關鍵的技術點告訴你 字型變化有font屬性來實現 按鈕始終在窗體又下放可以再窗體的form resize中設定 按鈕的top和left屬性讓他們分別 me.whith 50,me.heght 50 4 4個按鈕每單擊一次...

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

dim a,b 定義兩個變體型變數a,b,在該模組範圍內有效 private sub form load 窗體載入事件觸發的函式 a picture1.width 記錄 框控制元件picture1的寬度到a變數 b picture1.height 記錄 框控制元件picture1的高度到b變數 hs...

VB程式設計題(簡單),VB 程式設計題(簡單)

做個標記,等會發你郵箱 private sub form load timer1.interval 1000timer1.enabled trueend sub private sub timer1 timer if option1.value true then text1.text format...