1.If
Private Sub Command1_Click()
Dim a As String "声明a是字符串形式的变量"
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
a = 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
a = Rnd
b = 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
a = Text1.Text
Select Case a
Case "红色"
Label1.BackColor = RGB(255, 0, 0)
Case "绿色"
Label1.BackColor = RGB(0, 255, 0)
Case "蓝色"
Label1.BackColor = RGB(0, 0, 255)
Case Else
Label1.BackColor = RGB(255, 255, 0)
End Select
End Sub
5.do .....loop
Private Sub Command1_Click()
Dim a, b, s, i As Integer "整型"
a = Val(text1.Text)
b = Val(text2.Text)
s = 0
i = a
Do While i <= b
s = s + i
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
a = Val(Text1.Text)
b = Val(Text2.Text)
s = 0
i = a
While i <= b
s = s + i
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
a = Val(Text1.Text)
b = Val(Text2.Text)
s = 0
i = a
For i = a To b Step 2
s = s + i
Next
MsgBox "计算结果为:" & s
End Sub
1.
Dim a As Double
Private Sub Command1_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Fix(a) "取整"
End Sub
Private Sub Command2_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Int(a) "不大于数值(456.123)的整数部分"
End Sub
Private Sub Command3_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Abs(a) "绝对值"
End Sub
Private Sub Command4_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Sgn(a) "判断数值为正数(1)负数(-1)0(0)"
End Sub
Private Sub Command5_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Sqr(a) "平方根"
End Sub
2.不知道是高中还是初中的东西,现在都记不起来了,百度了一下,还是一头雾水,
Dim a As Integer
Private Sub Command1_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Log(a) "对数"
End Sub
Private Sub Command2_Click()
a = Val(Text1.Text) "将字符串转为数值"
MsgBox "函数值为:" & Sin(a) "正弦"
End Sub
Private Sub Command3_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Cos(a) "余弦"
End Sub
Private Sub Command4_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Tan(a) "正切"
End Sub
Private Sub Command5_Click()
a = Val(Text1.Text)
MsgBox "函数值为:" & Atn(a) "余切"
End Sub
3. Els val
Trim 删除空格
Ltrim 删除左空格
Rtrim 删除右空格
Left(s,6) 选取左六
Mid (s,2,6) 取指定位置的字符串
Right(s,6) 从右选6字符串
4.Dim a as
Variant
len(a) 长度
Space (a) 空格为
UCase(a) 大写
LCase(a) 小写 a=Val(Text1.text) 数字
Str(a) 数字转字符
5.Dim a,b As
String
Instr(a,b) 若字符串B是A的子串,结果为1,反之则为0
6.
Val 将字符串转为数字
Str 将数字转为字符串
Asc(a) 字符串首字的Ascii 码
Chr(a)得到以数字为Ascii码的字符
7.随机函数
Rnd(a) a不变则随机值不变 CInt 将数字小数第一们4舍5入 CCur (a) 将小数后第五位4舍5入