VB的基本语法

Option Explicit '强制声明变量

'变量的定义

'Dim Opera,Operb,result

'常量的定义

'Const vbPI=3.14

'Opera=InputBox("please input a's value")

'Operb=InputBox("please input b's value")

'result=Opera+Operb

'MsgBox Opera&"+"&Operb&"="&result

'MsgBox vbPI

'内置换行

'MsgBox "hello"&vbCrLf&"world"

'字符串,大小写转换

'Dim x

'x=LCase("aBc") '小写

'MsgBox x

'x=UCase("Abcc") '大写

'MsgBox x

'StrComp 比较字符 如果字符相同则返回结果为0,否则为非0

'Dim username,inun

'username="zhangsan"

'inun=InputBox("请输入用户名")

' If StrComp(username,inun) Then

' MsgBox "用户名不相同"

' Else

' MsgBox "相同"

' End If

'字符长度

' Dim a

' a="maiziedu"

' MsgBox Len(a)

'字符串替换

'Dim astr

'astr=Replace("hello,xiaoyu","hello","hi")

'MsgBox astr

'字符串分割

'Dim teststr,teststrs

'teststr="2.1.3"

'teststrs=Split(teststr,".")

' MsgBox teststrs(0)

' MsgBox teststrs(1)

' MsgBox teststrs(2)

猜你喜欢

转载自www.cnblogs.com/fjy49/p/9150930.html
VB