The funeral of Azeroth

Herose

 

Vb11.12 VB 中基本语句

1.If
Private Sub Command1_Click()
Dim a As String      "声明a是字符串形式的变量"
= Text1.Text
If a = "你好" Then
MsgBox "你输入的是你好"
ElseIf a <> "你好" Then           或       Else
MsgBox "你输入的并非是你好"
End If

End Sub
2.if
Private Sub Command1_Click()
Dim a As String
= Text1.Text
If a = "邱吉尔" Then
MsgBox "恭喜你,回答正确"
ElseIf a = "罗斯福" Then
MsgBox "恭喜你,回答正确"
ElseIf a = "斯大林" Then
MsgBox "恭喜你,回答正确"
Else
MsgBox "对不起,你真笨"
End If


End Sub
3.
Private Sub Command1_Click()
Dim a, b As Double
= Rnd
= Rnd
If a > b Then
MsgBox "本轮小张胜"
ElseIf a < b Then
MsgBox "本轮小王胜"
Else
MsgBox "本轮作费"
End If

End Sub
4.Select case
Private Sub Command1_Click()
Dim a As String
= Text1.Text
Select Case a
Case "红色"
Label1.BackColor 
= RGB(25500)
Case "绿色"
Label1.BackColor 
= RGB(02550)
Case "蓝色"
Label1.BackColor 
= RGB(00255)
Case Else
Label1.BackColor 
= RGB(2552550)
End Select

End Sub
5.do .....loop
Private Sub Command1_Click()
Dim a, b, s, i As Integer  "整型"
= Val(text1.Text)
= Val(text2.Text)
= 0
= a
Do While i <= b    
= s + i
=  i  + 1
Loop
MsgBox "计算结果为" & s
Do loop 的另一种形式
Do
s=s+i
i=i+1
Loop while i<=b

End Sub
"计算两个整数之间所有整数之和(包括这两个整数)"
6.  do while 当条件满足时候执行
     do until   当条件不满足时候执行
Do
s=s+i
i=i+1
Loop until i>b
7.While...(条件满足时) Wend(执行)
Private Sub Command1_Click()
Dim a, b, s, i As Integer
= Val(Text1.Text)
= Val(Text2.Text)
= 0
= a
While i <= b
= s + i
= i + 1
Wend
MsgBox "计算结果为:" & s

End Sub
8.For  a to b  Step  2     计算a到b之间间隔为2的所有数之和
Private Sub Command1_Click()
Dim a, b, s, i As Integer
= Val(Text1.Text)
= Val(Text2.Text)
= 0
= a
For i = a To b Step 2
= s + i
Next
MsgBox "计算结果为:" & s

End Sub



posted on 2010-11-12 16:30 Herose 阅读(97) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(3)

随笔档案

文章档案

相册

http://www.enet.com.cn/eschool/video/vb/

搜索

最新评论

阅读排行榜

评论排行榜