vbs基本编程

【常量变量的定义】

'常量变量的定义
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

【时间日期 函数】


                
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值