* if 語句
*ng未必是指結果集中的所有數據,也許只是一行中所有的,或是一列中所有的
保險起見,可以一格格枚舉
dim a as boolean=true
Dim row As DataRow
For Each row In *
Dim column As DataColumn
For Each column In *s
if row(column).contains("Agree") then a=false
Next column
Next row
if a then
*(0).Enabled = False
else
*(0).Enabled = True
end if
*中的if else問題
Private Sub Button1_Click(ByVal sender As *, ByVal e As *rgs) Handles *
If * Then : * = Val(*) * 10 + 1 : Else : * = Val(*) * 10 + 1 : End If
End Sub
或
Private Sub Button1_Click(ByVal sender As *, ByVal e As *rgs) Handles *
If * Then
* = Val(*) * 10 + 1
Else
* = Val(*) * 10 + 1
End If
End Sub
樓主只是單純的格式錯誤而已。
If。Then。 是可以
If。Then。Else 是不存在的
需要一行內用到的話,必須還要跟個End If,也就是
If。Then。Else。End If
當然最好還是分行寫,自己以后修改也容易看
If 條件1 Then
' 代碼
ElseIf 條件2 Then
' 代碼
ElseIf 條件2 Then
' 代碼
Else
' 代碼
End If
其中ElseIf行與Else行,在不需要時都可以不寫。
* 中,#if 是什么語法
#If。Then。#Else 指令
根據條件編譯選定的 Visual Basic 代碼塊,需要有#Const 配對,一般要先用#Const 定義條件編譯器常量
'以下是例子
Module Module1
#Const i = 60
Sub Main()
#If i > 30 Then
*ine("???") '如果用#Const定義了i,該句語句才會執行,假如用的是private i as integer=60定義,該語句不會被執行
#End If
End Sub
End Module
vb單擊if語句的語法格式
if payment="Cash" then
msgbox "You are going to pay cash!"
elseif payment="Visa" then
msgbox "You are going to pay with visa."
elseif payment="AmEx" then
msgbox "You are going to pay with American Express."
else
msgbox "Unknown method of payment."
end If
轉載請注明出處華閱文章網 » vb.netif語句