【常量变量的定义】
'常量变量的定义
Option Explicit '强制变量声明,有了此语句必须申明变量再使用
Dim opera,operb,result '一般,也可以不声明直接使用变量
Const vbPI=3.14 '常量 前面加vb或者con一般表示是常数
opera=InputBox("please input a's value")
operb=InputBox("please input b's value")
result=opera+operb
MsgBox opera&"+"&operb&"="&result
MsgBox vbPI
【字符串】
'大小写转换
Dim x
x=LCase("aBc")'abc ,转小写
MsgBox x
x=UCase("aBc")'ABC ,转大写
MsgBox x
'比较字符串StrComp
Dim name,user
name="lisi"
user=InputBox("please input your name")
If StrComp(name,user) Then
MsgBox "输入的名字不同"
Else '两个字符串相同,StrComp返回0,否则返回非0
MsgBox "名字相同"
End If
'字符串长度
Dim a
a="abcdef" '6
MsgBox Len(a)
'替换字符串
Dim astr
astr=Replace("hello,lisi","lisi","zhang")
MsgBox astr 'hello,zhang
'切割
Dim teststr
teststr="2.1.3"
teststrs=Split(teststr,".")
MsgBox teststrs(0) '2
MsgBox teststrs(1) '1
MsgBox teststrs(2) '3
【转换函数】
'转换函数
MsgBox CBool(0) '0转成false,非0转成true
MsgBox CBool(34) 'true
MsgBox CInt(4.5) '转成整数,4.5是4,4.6是5
MsgBox CDate("12/12/2012") '2012-12-12
MsgBox Asc("a") '97
MsgBox Chr(65) 'A
【时间日期 函数】