[Visual Basic] 纯文本查看 复制代码
Option Explicit
Private Sub Command1_Click()
Print Exp(5) 'E指数
End Sub
Private Sub Command10_Click()
Print Sin(45 * 3.14 / 180) '正弦
End Sub
Private Sub Command11_Click()
Print Tan(45 * 3.14 / 180) '正切
End Sub
Private Sub Command12_Click()
Print Log(2.732) '自然对数
End Sub
Private Sub Command13_Click()
Print Sgn(5) '返回一个正负号或0
End Sub
Private Sub Command14_Click()
Print LCase("ABcdE") '将字母转换为小写
End Sub
Private Sub Command15_Click()
Print Left("ABCDE", 3) '取左边3个字符
End Sub
Private Sub Command16_Click()
Print LTrim(" AAA" + " BBB ") '删除左边的空格
End Sub
Private Sub Command17_Click()
Print Right("ABCDE", 3) '取C右边3个字符
End Sub
Private Sub Command18_Click()
Print RTrim("AA" + "BB") '删除C右边的空格
End Sub
Private Sub Command19_Click()
Print Space(5) '产生5个数的空格字符
End Sub
Private Sub Command2_Click()
Dim x As Integer
Dim y As Integer
x = 12
y = 8
Print Sqr(x * x + y * y) '平方根
End Sub
Private Sub Command20_Click()
Print Trim("AA" + "BB") '删除C首尾两端的空格
End Sub
Private Sub Command21_Click()
Print UCase("abcde") '将C中的字母转换为大写
End Sub
Private Sub Command22_Click()
Print Asc("A") '返回第一个字符的ASCII码 65
End Sub
Private Sub Command23_Click()
Print Chr(97) '返回ASCII码对应的字符 a
End Sub
Private Sub Command24_Click()
Print Str(100010) '将N转换成Str类型
End Sub
Private Sub Command25_Click()
Print Val("123.567") '将括号内容转换成数字
End Sub
Private Sub Command26_Click()
Print Date ' 返回当前系统日期(含年月日)
End Sub
Private Sub Command27_Click()
Print DateAdd("M", 1, Date); DateAdd("ww", 1, Date); DateAdd("D", 1, Date); '输出当前时间一月后、一周后、一天后的日期
End Sub
Private Sub Command28_Click()
Print DateDiff("D", #2/25/2024#, #7/30/2024#) '输出两个日期之间相隔的天数
End Sub
Private Sub Command29_Click()
Print Day(Date)
End Sub
Private Sub Command3_Click()
Dim x As Single
Dim y As Single
x = 56.8
y = 78.9
Print Int(x * y) '返回参数的整数部分
End Sub
Private Sub Command30_Click()
Print Hour(Time) '返回当前小时
End Sub
Private Sub Command31_Click()
Print Minute(Time) '返回当前分钟
End Sub
Private Sub Command32_Click()
Print Month(Date) '返回当前月份
End Sub
Private Sub Command33_Click()
Print Now() '返回当前日期和时间(含年月日时分秒)
End Sub
Private Sub Command34_Click()
Print Second(Time) '返回当前秒
End Sub
Private Sub Command35_Click()
Print Time() '返回当前时间(含时分秒)
End Sub
Private Sub Command36_Click()
Print Weekday(Date, vbMonday) '返回当前星期
End Sub
Private Sub Command37_Click()
Print Year(Date) '返回当前年份
End Sub
Private Sub Command38_Click()
Dim MyArray(1 To 5) As Integer
Print IsArray(MyArray)
End Sub
Private Sub Command39_Click()
Dim Mydate
Mydate = "04/28/2014" ' Assign valid date value.
Print IsDate(Mydate) ' Returns True.
End Sub
Private Sub Command4_Click()
Print Mid("ABCDE", 3, 1) ' 从第1个字符起,取C中第3个字符
End Sub
Private Sub Command40_Click()
Dim MyVar
MyVar = "53" ' Assign value.
Print IsNumeric(MyVar) ' Returns True.
End Sub
Private Sub Command41_Click()
Dim MyVar
MyVar = Null
Print IsNull(MyVar) ' Returns True
End Sub
Private Sub Command42_Click()
Dim varTest
varTest = 123
If IsError(varTest) Then
MsgBox "varTest 包含错误值"
Else
MsgBox "varTest 不包含错误值"
End If
End Sub
Private Sub Command43_Click()
'新建文件,并写入数据,关闭
Open "a.txt" For Output As #1
Print #1, "ABCDEFG"; vbCrLf; "HIJK"
Close #1
Dim textLine As String
' 打开文件
Open "a.txt" For Input As #2
Open "b.txt" For Output As #3
' 循环直到文件末尾
While Not EOF(2)
' 读取一行
Line Input #2, textLine
Print #3, textLine
Wend
' 关闭文件
Close
'''-------------强大的分隔符-----------------''''
Dim st As Struct
'新建文件,并写入记录,关闭
Open "a.dat" For Random As #1 Len = Len(st)
Put #1, , st
Close #1
'打开文件,并写入新文件,关闭
Open "a.dat" For Random As #2 Len = Len(st)
Open "b.dat" For Random As #3 Len = Len(st)
Dim st2 As Struct
Get #2, , st2
Put #3, , st2
Close
End Sub
Private Sub Command44_Click()
Label1.ForeColor = QBColor(Int(Rnd * 15)) '标签闪烁
End Sub
Private Sub Command45_Click()
Label2.BackColor = RGB(255, 0, 0) '背景色为红色
Label3.BackColor = RGB(0, 0, 255) '背景色为蓝色
Label4.BackColor = RGB(100, 100, 100) '背景色为深灰色
End Sub
Private Sub Command46_Click()
Print Format(Time, "h:mm:ss") & " " & "时/分/秒格式"
Print Format(#6/4/2024#, "yyyy-m-d") & " " & "年/月/日格式"
Print Format(#6/4/2024#, "m-d-yy") & " " & "月/日/年格式"
Print Format(123.45, "0000.00") & " " & "显示一个数字,位数不足自动补0"
Print Format(123.45, "####.##") & " " & "显示一个数字"
Print Format(0.45, "#%") & " " & "显示百分比"
Print Format(1.4567, "#.##") & " " & "固定小数点位置"
Print Format(1234567, "#,###,###") & " " & "千位分隔符"
Print Format(12345, "$#,###,###") & " " & "原样输出"
Print Format("Hello", "<") & " " & "将字符转换成小写"
Print Format("Hello", ">") & " " & "将字符转换成大写"
Print Format("Hello", "&&&&&&&") & " " & "显示一串字符"
Print Format("Hello", "@@@@@@@") & " " & "显示一串字符,位数不足前面补空格"
End Sub
Private Sub Command47_Click() '返回变量是否已经初始化
Dim MyVar, MyCheck
If MyCheck Then IsEmpty (MyVar) ' 返回 True。
Print IsEmpty(MyVar)
If MyVar = Null Then IsEmpty (MyVar)
Print MyCheck = IsEmpty(MyVar) ' 返回 False。
If MyVar = Empty Then IsEmpty (MyVar)
Print IsEmpty(MyVar) ' 返回 True。
End Sub
Private Sub Command48_Click() '返回参数是否已经传递给过程.net中用Isnothing代替
' 调用函数,不传递可选参数
MyFunction
' 调用函数,传递可选参数
MyFunction "Hello, World!"
End Sub
Private Sub Command49_Click()
Dim testVar As Variant
Set testVar = CreateObject("Scripting.Dictionary")
If IsObject(testVar) Then
MsgBox "testVar 是一个对象" '检查变量是否是对象的引用
Else
MsgBox "testVar 不是一个对象"
End If
End Sub
Private Sub Command5_Click()
Print Len("ABCDE") '测试C的长度
End Sub
Private Sub Command6_Click()
Print InStr("ABCDE", "DE") '在C1中查找C2的位置
End Sub
Private Sub Command7_Click()
Print Rnd() * 100 '生成0-100之间的随机数
End Sub
Private Sub Command8_Click()
Print Abs(-7) '绝对值
End Sub
Private Sub Command9_Click()
Print Cos(45 * 3.14 / 180) '余弦
End Sub