VB编程常用代码大全讲解学习
- 格式:doc
- 大小:17.50 KB
- 文档页数:6
vb教程编程实例详解VB教程编程实例详解VB(Visual Basic)是一种面向对象的编程语言,它可以用于开发Windows应用程序。
在这里,我们将详细解释一些VB 编程实例,以帮助初学者更好地理解和掌握这门语言。
编程实例1:计算器首先,让我们创建一个计算器的VB程序。
我们将使用VB的窗体和按钮来实现这个功能。
首先,我们需要在窗体上添加一些按钮,如"1"、"2"、"+"、"="等。
然后,我们需要用一个文本框来显示计算结果。
在窗体上双击"+"按钮并添加以下代码:```Private Sub ButtonPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPlus.ClickDim num1 As IntegerDim num2 As IntegerDim result As Integernum1 = Integer.Parse(TextBoxNum1.Text)num2 = Integer.Parse(TextBoxNum2.Text)result = num1 + num2TextBoxResult.Text = result.ToString()End Sub```在这个代码中,我们首先定义了三个变量:num1、num2和result,用于存储计算结果。
然后,我们使用Integer.Parse方法将文本框中输入的文本转换为整数类型,并将其赋值给num1和num2。
接下来,我们将num1和num2相加,将结果赋值给result,并使用result.ToString()方法将结果转换为字符串类型并显示在结果文本框中。
编程实例2:学生成绩管理系统接下来,让我们创建一个学生成绩管理系统的VB程序。
VB总结1、阶乘和Private Function fact(n As Integer) As Long Dim i As Integerfact = 1For i = 1 To nfact = fact * iNext iEnd FunctionPrivate Sub Command1_Click()Dim a As Integer, sum As LongDim i As Integern = Val(Text1.Text)For i = 1 To nsum = sum + fact(i)Next iText2.Text = sumEnd Sub2、逆序Private Sub reverse(s As String, s1 As String) Dim i As IntegerFor i = 1 To Len(s)s1 = Mid(s, i, 1) & s1Next iEnd SubPrivate Sub Command1_Click()Dim m As String, m1 As Stringm = Text1.TextCall reverse(m, m1)Text2.Text = m1End Sub3、最小公倍数Private Sub Command1_Click()Dim s1 As Integer, s2 As Integers1 = Val(Text1.Text)s2 = Val(Text2.Text)Text3.Text = s1 * s2 / gcd(s1, s2)End SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As Integer Dim r As IntegerDor = m Mod nm = nn = rLoop Until r = 0gcd = mEnd Function4、找出100-200之间的升序数Private Function ascnum(n As Integer) As BooleanDim i As IntegerFor i = 2 To Len(CStr(n))If Mid(n, i, 1) <=Mid(n, i - 1, 1) ThenExit FunctionEnd IfNext iascnum = TrueEnd FunctionPrivate Sub Command1_Click()Dim i As IntegerFor i = 100 To 200If ascnum(i) Then List1.AddItem iNext iEnd Sub5、找出100-300素数及求各个位数之和也是素数Private Function nsum(n As Integer) As IntegerDim i As IntegerFor i = 1 To Len(CStr(n))nsum = nsum + Mid(n, i, 1)Next iEnd FunctionPrivate Function prime(n As Integer) As BooleanDim i As Integerprime = FalseFor i = 2 To Sqr(n)If n Mod i = 0 Then Exit FunctionNext iprime = TrueEnd FunctionPrivate Sub Command1_Click()Dim i As IntegerFor i = 100 To 300If prime(i) And prime(nsum(i)) ThenList1.AddItem iEnd IfNext iEnd Sub6、质因子Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)Text2.Text = n & "=" & zyz(n)End SubPrivate Function zyz(ByVal n As Integer) As String Dim k As Integerzyz = " "k = 2Do Until n = 1If n Mod k = o Thenzyz = zyz & k & "*"n = n / kElsek = k + 1End IfLoopzyz = Left(zyz, Len(zyz) - 1)End Function因子和Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)Text2.Text = yz(n)End SubPrivate Function yz(ByVal n As Integer) As Integer Dim i As IntegerFor i = 1 To nIf n Mod i = o Then yz = yz + iNext iEnd Function7、生成由个位数组成的四行五列的数组Option Base 1 Private Sub Command1_Click()Dim a(4, 5) As Integer, i As Integer, j As IntegerFor i = 1 To 4For j = 1 To 5a(i, j) = Int(Rnd * 10)Print a(i, j);Next jPrintNext iEnd Sub8、由个位数组成的五行五列的矩阵,并显示下面一个三角形Option Base 1Dim a(5, 5) As Integer Private Sub Command1_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd Sub Private Sub Command2_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To iPicture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub9、由个位数组成的五行五列的矩阵,并沿主对角线对折Option Base 1Dim a(5, 5) As Integer Private Sub Command1_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 10)Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd Sub Private Sub Command2_Click()Dim i As Integer, j As Integer, tmp As IntegerFor i = 1 To 5For j = 1 To itmp = a(i, j)a(i, j) = a(j, i)a(j, i) = tmpNext jNext iFor i = 1 To 5For j = 1 To 5Picture2.Print a(i, j);Next jPicture2.PrintNext iEnd Sub10、生成12个二位数,并打印出最小元素和最大元素Option Base 1 Private Sub Command1_Click()Dim com(12) As Integer, i As IntegerDim max As Integer, min As Integermin = 100For i = 1 To 12com(i) = 10+Int(Rnd * 90)Print com(i);If com(i) > max Then max = com(i)If com(i) < min Then min = com(i)Next iPrintPrint "最大元素:" & maxPrint "最小元素:" & minEnd Sub11、实验教程P56Option ExplicitOption Base 1Dim a(5, 5) As IntegerPrivate Sub Command1_Click()Dim i As Integer, j As IntegerFor i = 1 To 5For j = 1 To 5a(i, j) = Int(Rnd * 90) + 10Picture1.Print a(i, j);Next jPicture1.PrintNext iEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, sum As IntegerFor i = 1 To 5sum = 0For j = 1 To 5sum = sum + a(i, j)Next jText1.Text = Text1.Text & sum & vbCrLf Next iEnd SubPrivate Sub Command3_Click()Dim i As Integer, j As Integer, sum As IntegerFor j = 1 To 5sum = 0For i = 1 To 5sum = sum + a(i, j)Next iText2.Text = Text2.Text & sum & " "Next jEnd SubPrivate Sub Command4_Click()Dim i As Integer, j As Integer, sum As IntegerFor i = 1 To 5For j = 1 To 5If i = j Or i + j = 6 Then sum = sum + a(i, j) Next jNext iText3.Text = sumEnd Sub12、求任意一维数组元素之和Private Function tim(a() As Integer)Dim t As Double, i As Integert = 0For i = LBound(a) To UBound(a)t = t + a(i)Next itim = tEnd Function13、排序(升序)Option Base 1Private Sub Command1_Click()Dim i As Integer, b(10) As IntegerFor i = 1 To 10b(i) = 10 + Int(Rnd * 90)Print b(i)Next iPrintCall ascsort(b)For i = 1 To 10Print b(i)Next iEnd Sub冒泡法Private Sub ascsort(a() As Integer)Dim i As Integer, j As Integer, temp As IntegerFor i = 1 To UBound(a) - 1For j = 1 To UBound(a) - iIf a(j) > a(j + 1) Thentemp = a(j)a(j) = a(j + 1)a(j + 1) = tempEnd IfNext jNext iEnd Sub选择法Private Sub ascsort(a() As Integer)Dim i As Integer, j As Integer, temp As IntegerFor i = 1 To UBound(a)For j = i + 1 To UBound(a)If a(i) > a(j) Thentemp = a(i)a(i) = a(j)a(j) = tempEnd IfNext jNext iEnd Sub直接排序Private Sub ascsort(a() As Integer)Dim i As Integer, j As Integer, temp As Integer, pointer As Integer For i = 1 To UBound(a) - 1pointer = iFor j = i + 1 To UBound(a)If a(pointer) > a(j) Then pointer = jNext jIf i <> pointer Thentemp = a(i)a(i) = a(pointer)a(pointer) = tempEnd IfNext iEnd Sub1、I递归法阶乘:Private Function Fact(ByVal n As Integer) As LongDim i As IntegerFact = 1For i = 1 To nFact = Fact * iNext iEnd FunctionPrivate Sub Command1_Click()Dim a As Integera = Text1.TextText2.Text = Fact(a)End SubII非递归法阶乘Private Function Fact(ByVal n As Integer) As Long If n = 0 Or n = 1 ThenFact = 1ElseFact = n * Fact(n - 1)End IfEnd FunctionPrivate Sub Command1_Click()Dim a As Integera = Text1.TextText2.Text = Fact(a)End Sub2、最大公约数:Private Sub Command1_Click()Dim x As Integer, y As Integer, z As Integerx = Val(Text1.Text)y = Val(Text2.Text)z = gcd(x, y)Text3.Text = zEnd SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As IntegerDim r As IntegerDor = m Mod nm = nn = rLoop Until r = 0gcd = mEnd Function3、最小公倍数:Private Sub Command1_Click()Dim x As Integer, y As Integer, z As Integerx = Val(Text1.Text)y = Val(Text2.Text)z = gcd(x, y)Text3.Text = zEnd SubPrivate Function gcd(ByVal m As Integer, ByVal n As Integer) As IntegerDim r As Integer, s As Integers = m * nDor = m Mod nm = nn = rLoop Until r = 0gcd = s / mEnd Function4、逆序:Private Sub Command1_Click()Dim i As Integer, st As Stringi = Val(Text1.Text)Call prime(i, st)Text2.Text = stEnd SubPrivate Sub prime(ByVal n As Integer, st As String) Dim i As Integer, s As Strings = CStr(n)For i = 1 To Len(s)st = Mid(s, i, 1) & stNext iEnd Sub5、素数(判断素数):Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)If ptm(n) ThenText2.Text = "该数是素数"ElseText2.Text = "该数不是素数"End IfEnd SubPrivate Function ptm(n As Integer) As Boolean Dim i As IntegerFor i = 2 To Sqr(n)If n Mod i = 0 Then Exit ForNext iIf i > Sqr(n) Thenptm = TrueEnd IfEnd Function6、素数(求素数):Private Sub Command1_Click()Dim i As IntegerFor i = 100 To 999If Prime(i) = True Then List1.AddItem iNext iEnd SubPrivate Function Prime(n As Integer) As Boolean Dim i As IntegerFor i = 2 To n - 1If n Mod i = 0 Then Exit FunctionNext iPrime = TrueEnd Function7、数组求和Option ExplicitOption Base 1Dim a () As IntegerPrivate Sub Command1_Click()Dim i As Integer ,n As IntegerN=Val (inputBox(“请输入n的值:”))ReDim a(n)For i=1 To NA(i) =Int (Rnd*90)+10Picture 1.Print a(i)Next iEnd SubPrivate Sub total (a() As Integer,sum As Integer) Dim i As IntegerFor i =1 To UBound(a)sum=sum+a(i)Next iEnd SubPrivate Sub Command 2_Click()Dim k As Integercall total (a,k)Text1.Text=CStr(k)End Sub8、升(降)序Private Sub Command1_Click()Dim n As Integern = Val(Text1.Text)If ascnum(n) ThenText2.Text = "该数是升(降)序数"ElseText2.Text = "该数不是升(降)序数"End IfEnd SubPrivate Function ascnum(n As Integer) As Boolean Dim s As Integer, i As Integers = CStr(n)For i = 1 To Len(s) - 1If Mid(s, i, 1) >(<)= Mid(s, i + 1, 1) Then Exit For Next iIf i > Len(s) - 1 Then ascnum = TrueEnd Function9、因子和:Option ExplicitPrivate Sub Command1_Click()Dim n As Integern = Val (Text1)Text2 = cstr (yzh(n))End SubPrivate Function yzh (ByVal n As Integer) As Integer Dim i As IntegerFor i = 1 To nIf n mod i = 0 Then yzh=yzh+iNext iEnd Function。
1。
求三角形的面积代码:Option ExplicitDim a!,b!,c!r,!,s!Private Sub Command1_Click()a = InputBox(”a=”, "请输入a的数值")b = InputBox(”b=", "请输入b的数值")c = InputBox("c=”, ”请输入c的数值")If a + b 〉c And a + c 〉b And b + c > a And a 〉0 And b 〉0 And c 〉0 Thenr = 1 / 2 * (a + b + c)s = Sqr(r *(r — a) * (r — b) *(r — c))Label1。
Caption = "三角形的面积为" & sElseLabel2.Caption = ”输入的数据不能构成三角形"End IfEnd Sub2.三个数排列代码:Option ExplicitDim x!,y!,z!, t!Private Sub Command1_Click()x = InputBox("输入第一个数x")y = InputBox("输入第二个数y”)z = InputBox("输入第三个数z")Print "排序前";x &”" & y &””&zIf x < y Then t = x:x = y: y = tIf y < z Thent = y: y = z: z = tIf x 〈y Thent = x:x = y: y = tEnd IfEnd IfPrint "排序后”;z & ”" &y & ”" &xEnd Sub3。
计算一元二次方程的代码:Option ExplicitDim a!,b!,c!,d!,x1!,x2!Private Sub Command1_Click()a = InputBox(”a=”, ”请输入一元二次方程的系数a")b = InputBox("b=”,”请输入一元二次方程的系数b")c = InputBox(”c=”,"请输入一元二次方程的系数c”) If a = 0 ThenPrint ”因为a≠0,你输入的a=0,请重新输入系数a" End Ifd = b ^ 2 - 4 * a * cIf d >= 0 Thenx1 = (—b + Sqr(d))/ (2 * a)x2 = (—b - Sqr(d)) / (2 * a)Print ”系数为”&a; b; c &"的一元二次方程的根分别为”& "x1=”& x1 & ”" &"x2=" &x2ElsePrint ”此方程在实数范围内无解"End IfEnd Sub4。
vb编程代码大全Visual Basic (VB) 是一种广泛用于软件开发的高级编程语言,可以用于开发 Windows 应用程序、Web 应用程序、数据库应用程序等。
在本文中,将介绍一些常用的 VB 编程代码,帮助初学者快速入门和提高编程水平。
一、基本数据类型1. 整型数据在 VB 中,整型数据可以使用 Integer 类型表示,范围为 -32,768 到32,767。
定义整型变量的代码如下:```Dim num As Integernum = 10```2. 浮点数据浮点数据可以使用 Single 或 Double 类型表示,分别表示单精度浮点数和双精度浮点数。
定义浮点变量的代码如下:```Dim num As Singlenum = 3.143. 字符串数据字符串数据可以使用 String 类型表示,可以存储文本数据。
定义字符串变量的代码如下:```Dim str As Stringstr = "Hello, World!"```二、控制流程1. If...Then...Else 语句If...Then...Else 语句用于根据条件执行不同的代码块。
例如:```Dim num As Integernum = 10If num > 0 ThenMsgBox("Num is positive.")ElseMsgBox("Num is negative.")End If2. For 循环For 循环用于重复执行一段代码。
例如:```For i = 1 To 10MsgBox(i)Next i```3. Do While 循环Do While 循环在满足条件时执行代码块。
例如:```Dim i As Integeri = 1Do While i <= 10MsgBox(i)i = i + 1Loop```三、数组1. 一维数组一维数组在 VB 中用于存储相同类型的多个元素。
哈哈哈20道编程代码1.1000以内的全部完数Private Sub Command1_Click()Dim n As IntegerDim i As IntegerDim s As LongFor n = 1 To 1000s = 1For i = 2 To n - 1If n Mod i = 0 Then s = s + iNext iIf s = n ThenText1 = Text1 & n & " "If k Mod 5 = 0 Then Text1 = Text1 & vbCrLfEnd IfNext nEnd SubPrivate Sub Command2_Click()EndEnd Sub2.百元买百鸡Private Sub Command1_Click()Dim i As IntegerDim j As IntegerFor i = 0 To 20For j = 0 To 33If 5 * i + 3 * j + (100 - i - j) * 1 / 3 = 100 ThenText1 = Text1 & "买" & CStr(i) & "只公鸡" & CStr(j) & "只母鸡" & CStr(100 - i - j) & "只小鸡"Text1 = Text1 & Chr(13) & Chr(10)End IfNext jNext iEnd SubPrivate Sub Command2_Click()EndEnd Sub3.不靠边元素和Private Sub Command1_Click()ClsRandomizeDim a(5, 5) As Integer, s%For i = 0 To 5For j = 0 To 5a(i, j) = Int(Rnd * 9)Print a(i, j) & ",";Sum = Sum + a(i, j)Next jPrintNext ik = SumSum = 0For i = 0 To 5Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i) Next iSum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5) Text1 = k - SumEnd SubPrivate Sub Command2_Click()EndEnd Sub4.递归函数求斐波拉契数列Option ExplicitPrivate Sub Command1_Click()Dim a1, a2, b As IntegerDim i, n As Integern = InputBox("显示数列的前N项")a1 = 1For i = 1 To nb = a1 + a2Text1.SelText = b & " "a1 = a2a2 = bNext iEnd SubPrivate Sub Command2_Click() EndEnd Sub5.各位数之和Private Sub Command1_Click() Dim i As StringDim j%Dim s%i = Text1For j = 1 To Len(i)st = Mid(i, j, 1)s = s + Val(st)Next jText2 = sEnd SubPrivate Sub Command2_Click() EndEnd Sub6.回文数Private Sub Command1_Click() Dim x$, y$, c$, i%x = Text1For i = 1 To Len(x)c = Mid(x, i, 1)y = c + yNext iIf y = x ThenText2 = "x是回文数"ElseText2 = "x不是回文数"End IfEnd Sub。
vb6编程代码大全Time 返回系统时钟的当前时间。
Date 返回系统时钟的当前日期。
Now 返回代表当前日期和时间的编码值。
该函数经常用作其它系统时钟函数的参数。
Hour(Time) 返回指定时间的小时部分(0到23)。
Minute(Time) 返回指定时间的分钟部分(0到59)。
Second(Time) 返回指定时间的秒部分(0到59)。
Day(Date) 返回月份中的日期数(1到31)。
Month(Date) 返回日期中的月份(1到12)。
Year(Date) 返回日期中的年度。
Weekday(Date) 返回日期中代表一周中的星期几。
Abs(n) 返回n的绝对值。
Atn(n) 返回n的反正切值,以弧度为单位。
Cos(n) 返回n的余弦值,以弧度为单位。
Exp(n) 返回e的n次方。
Rnd(n) 产生0到1之间的一个随机数。
Sgn(n) n小于0时返回-1,n等于0时返回0,n大于0时返回1。
Sin(n) 返回n的正弦值,以弧度为单位。
Sqr(n) 返回n的平方根。
Str(n) 把数值值转换成字符串。
Tan(n) 返回n的正切值,以弧度为单位。
Val(n) 把字符串转换为数值值。
Int(n) 返回数字的整数部分。
8.4-->9Fix(n) 返回数字的整数部分。
8.4-->8以上函数在VB6和VBScript中都适用,在。
NET里面要在前面加上相应的命名空间,如System.Math.Cos(),Microsoft.VisualBasic.Hour()。
数据类型转换函数:转换函数将表达式转换成CBool BooleanCByte ByteCCur Currency '只在VB7.0以下有效CDate DateCDbl DoubleCInt IntegerCLng LongCSng SingleCStr StringCVar Variant ‘只在VB7.0以下有效CVErr Error '只在VB7.0以下有效若想了解Visual Basic正在使用哪种变量类型,可使用VarType 函数。
Vb6.0语句大全1、AppActivate 语句激活一应用程序窗口。
语法AppActivate title[, wait]AppActivate语句的语法具有以下几个命名参数:说明AppActivate语句将焦点移动到命名的应用程序或窗口,但并不影响焦点是否最大化或最小化。
当用户采取行动改变焦点或将窗口关闭时,就会将焦点从活动的应用程序窗口移动出去。
可用Shell函数启动一个应用程序并设置窗口样式。
在决定激活哪个应用程序时,请将title与每一个运行中的应用程序的标题字符串进行比较。
如果没有完全匹配,就激活任何这样的应用程序,其标题字符串以title开头。
如果以title命名的应用程序有很多实例,则激活任何一个实例。
AppActivate 语句示例本示例说明使用AppActivate语句来激活应用程序的各种用法。
示例中用到的Shell语句均假定该应用程序已经存在指定的路径中。
Dim MyAppID, ReturnValueAppActivate "Microsoft Word" ' 激活 Microsoft Word。
' AppActivate 也可利用 Shell 函数的返回值。
MyAppID = Shell("C:\WORD\WINWORD.EXE", 1) ' 运行 Microsoft Word。
AppActivate MyAppID ' 激活 Microsoft Word。
' 您也可使用 Shell 函数的返回值。
ReturnValue = Shell("c:\EXCEL\EXCEL.EXE",1) ' 运行 Microsoft Excel。
AppActivate ReturnValue ' 激活 Microsoft Excel。
2、Beep 语句通过计算机喇叭发出一个声调。
隐藏form1:form1.hide显示form1:form1.show--------------------------------------------------------------------------------------------- 退出程序时,弹出窗口提示是否要退出:Private Sub Form_Unload(Cancel As Integer)Dim iAnswer As IntegeriAnswer = MsgBox("真要退出吗?", vbYesNo)If iAnswer = vbNo ThenCancel = TrueElseEndEnd IfEnd Sub---------------------------------------------------------------------------------------------- 只能用任务管理器关闭程序的代码:Private Sub From_Unload(Cancel As Integer)Cancel = trueEnd Sub------------------------------------------------------------------------------------------------ 点击command1打开33IQ网:Dim strURLPrivate Sub Command1_Click()strURL = "错误!超链接引用无效。
Shell "explorer.exe " & strURL, 1End Sub------------------------------------------------------------------------------------------------ 运行c:\1.exeshell "c:\1.exe"执行c:\1.batshell "c:\1.bat"注:只适用于大部分exe和全部bat。
V B编程常用代码大全
VB编程常用代码大全
1.数值型函数:
abs(num): 返回绝对值
sgn(num): num>0 1; num=0 0; num<0 -1;判断数值正负
hex(num): 返回十六进制值直接表示:&Hxx 最大8位
oct(num): 返回八进制值直接表示:&Oxx 最大8位
sqr(num): 返回平方根 num>0
int(num): 取整 int(99.8)=99; int(-99.2)=100
fix(num): 取整 fix(99.8)=99; fix(-99.2)=99
round(num,n): 四舍五入取小数位 round(3.14159,3)=3.142 中点数值四舍五入为近偶取整 round(3.25,1)=3.2
log(num): 取以e为底的对数 num>0
exp(n): 取e的n次幂通常用 num^n
sin(num): 三角函数,以弧度为值计算 (角度*Pai)/180=弧度 con(num); tan(num); atn(num)
2.字符串函数:
len(str):计算字符串长度中文字符长度也计为一!
mid(str,起始字符,[读取长度]):截取字符串中间子字符串
left(str,nlen):从左边起截取nlen长度子字符串
right(str,nlen):从右边起截取nlen长度子字符串
Lcase(str):字符串转成小写
Ucase(str):字符串转成大写
trim(str):去除字符串两端空格
Ltrim(str):去除字符串左侧空格
Rtrim(str):去除字符串右侧空格
replace(str,查找字符串,替代字符串,[起始字符,替代次数,比较方法]):替换字符串
注:默认值:起始字符 1;替代次数不限;比较方法区分大小写(0)
InStr([起始字符,]str,查找字符串[,比较方法]):检测是否包含子字符串可选参数需同时选返回起始位置
InStrRev(str,查找字符串[,起始字符][,比较方法]):反向检测是否包含子字符串返回起始位置
space(n):构造n个空格的字符串
string(n,str):构造由n个str第一个字符组成的字符串
StrReverse(str):反转字符串
split(str,分割字符串[,次数][,比较方法]):以分割字符串为分割标志将字符串转为字符数组可选参数需同时选
3.数据类型转换函数:
Cint(str):转换正数 True -1;False 0;日期距离1899/12/31天数;时间上午段 0;下午段 1;
Cstr(str):日期输出格式 yyyy/mm/dd;时间输出格式 Am/Pm hh:mm:ss
Clng(str):与Cin()类似
Cbool(num):num不为零 True;反之 False
Cdate(str):转换日期格式 0:#Am 12:00:00#;正数距离1899/12/31天数的日期;浮点数日期+小数时间
Cbyte(num):num<255 转换为字节
Csng(str):转换为单精度数值
Cdbl(str):转换为双精度数值
Ccur(str):转换为现金格式
4.时间函数:
date:取系统当前日期
time:取系统当前时间
now:取系统当前时间及日期值 Datetime类型
timer:取当前时间距离零点秒值,计时器,可计算时间差
DateAdd(间隔单位,间隔值,日期):推算相邻日期
DateDiff(间隔单位,日期一,日期二):计算时间差日期二-日期一
Datepart(间隔单位,日期):计算日期的间隔单位值
Dateserial(date):输出日期值(按序列计算)
Timeserial(time):输出时间值(按序列计算)
Datevalue(datetime):取出字符串中日期值
Timevalue(datetime):取出字符串中时间值
weekday(date):计算星期几
MonthName(date):输出月分名
year(datetime):截取年份
month(datetime):截取月份
day(datetime):截取日
hour(datetime):截取小时
minute(datetime):截取分钟
second(datetime):截取秒
5.其它函数:
Array(unit,..):动态生成数组
Asc(str):输出字符串第一个字符的ASCII码
Chr(asc):转换ASCII为字符 Enter:Chr(13)&Chr(10)
Filter(数组名称,关键字符串,[,包含][,比较方法]):
将字符串数组中含有关键字符串的元素存成新的数组(默认) [包含]为false则取不包含的元素
oin(ArrayName):将数组中元素连成字符串
Ubound(ArrayName[,维数]):取得数组相应维数的上界
Lbound(ArrayName[,维数]):取得数组相应维数的下界一般为0
Randmize n:启动随机数种子
Rnd(n):取得随机数,n>0或为空,取序列下一随机值,n<0,随机值相同,n=0,生产与上一随机值相同的数
取介于A和B之间的随机正数C,公式:C=Int((B-A+1)*Rnd+A) 条件(B>A)
子程序和自定义函数
Sub StrSubName Function StrFunName(arg[1],..)
子程序体函数体
Exit Sub 中途跳出 Exit Function 中途跳出
End Sub StrFunName=value 返回值
End Function
[call] StrSubName 引用子程序 Var=StrFunName(arg[1],..) 引用函数。