一、Msgbox使用
①若参数列表不用“小括号”括起来,则是没有返回值的
'第一个数要要输出的内容,第三个是标题,
Msgbox "hello,marry",,"问候"
Msgbox "Something is wrong",16,"error"
②若将参数用小括号括起来,则是有返回值的,可以用一个变量接收;当然,不接收也可以
'第二是是按钮button
'
Dim i
i=Msgbox("Are you new comer?",vbOKCancel,"Question")
'输出值到log文件中
Print i
If i=1 Then
Msgbox "欢迎新成员加入"
Else
Msgbox"继续努力"
End If
二、Inputbox的使用
Inputbox(“对话框内容”,“对话框标题”)返回值为输入的内容
与Msgbox相同,若要用返回值,则用“小括号”
Dim name
name=Inputbox("what's your name" )
Msgbox "My name is"&name
三、练习
用Inputbox输入两个值,完成加法和乘法运算,然后用Msgbox输出该值
Dim add1,add2,result1
'Inputbox的返回值是string类型,在vbs中,“+”也是字符串的连接符
'要用Cint函数转化类型为int类型
add1=Cint(Inputbox("请输入第一个加数"))
Msgbox VarType(add1) 'vbString类型
add2=Cint(Inputbox("请输入第二个加数"))
result1=add1+add2
Msgbox VarType(result1) 'vbInteger类型
Msgbox add1 & "+" & add2 & "=" &result1
result2=add1*add2
Msgbox add1 & "*" & add2 & "=" &result2
额外:Cint(expression)
Returns an expression that has been converted to a Variant of subtype Integer.
注意:
Note CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
注意CInt与Fix和Int函数不同,Fix和Int截断小数部分,而不是四舍五入。当小数部分恰好为0.5时,CInt函数总是将其四舍五入到最接近的偶数。
例如,Cint(0.5)=0,Cint(1.5)=2。