VB6.0第六课

一、递归
1、递归:在过程中直接或间接地调用过程本身,即自己调用自己的过程。
如:

function F(n as integer) as single
    if n>1 and n<=30  then
        F=n*F(n-1)
    else
        F=1
     end if 
end function

Private sub command1_click()
    text2.text=F(val(text1.text)
end sub

递归的执行过程如下流程图:
在这里插入图片描述
说明:递归过程可以转化为循环结构。但是通常递归过程更快一些。建议通过F8键,通过单步调试,弄清整个递归过程的执行过程。

二、属性过程(property)
1、用于创建和操作类模块的属性。包括:一个Property Let、Property Get 或Property Set语句开头,以一个end Property语句结束。

2、Property Let语句、Property Get语句
如:

Private i as integer

Public  Property Let mark(Byval newvalue as integer)
   i=newvalue
end property

Public Property Get mark()  as integer
    mark=i
end property

三、数学函数
1、abs( n )
2、Exp( n ):以e(自然对数的底)的 n 次方
3、sgn(n):指出参数n的正负号,大于0返回值为1,等于0返回值为0,小于0返回值为-1。
4、sqr(n):n的平方根

四、字符串函数
1、len( n)
2、left、right:从左、右开始取指定数量的字符
print left(“hellotheworld”,2)
3、mid: print mid(“hellotheworld”,2,3)
4、trim、rtrim、Ltrim
(1)trim:去头尾的空格
(2)rtrim:去尾空格
(3) ltrim:去头空格

五、类型转换函数
1、asc:转换为ascii,返回一个integer值
如:print asc(“A”) '返回值为65

2、chr:转换为字符,返回 string值
如:print chr(65) '返回值为A

3、val:转换为数值型
如:print val(“1234”) '返回值为1234
print val(" 1 2 3 4") '返回值为1234

4、str:转换为字符型
如:print str(234) '回返值为"234"

六、判断函数
1、isnull:检测变量的值是否为null
如:

dim num
print isnull(num)    '输出值为false
num=""
print isnull(num)    '输出值为false
num="abc"
print isnull(num)    '输出值为false
num=null
print isnull(num)    '输出值为true

2、isnumeric:指出表达式的运算结果是否为数值。

print  isnumeric(44)    '输出值为true
print  isnumeric("hello")    '输出值为false
print  isnumeric(#4/1/2019#)    '输出值为false
print  isnumeric(null)    '输出值为false

3、isarray:指出变量是否为一个数组。

dim bb as string
dim  aa(1 to 5)  as integer
print  isarray(aa)     '输出值为true
print  isarray(bb)     '输出值为false

七、日期和时间函数
1、date、now、time

print "系统日期:" &  date    '输出系统日期
print "系统日期和时间:" &  now    '输出系统日期
print "系统时间:" &  time    '输出系统日期

2、timer函数:从午夜到现在经过的秒数,返回值为single

3、weekday函数:返回某个日期是星期几,返回variant(integer)类型的值。

dim day as string
dim n as integer
n=weekday(date)
if n=1  then day="sunday"
if n=2  then day="monday"
if n=3  then day="tuesday"
if n=4  then day="wednesday"
if n=5  then day="thursday"
if n=6  then day="friday"
if n=7  then day="saturday"

在这里插入图片描述

4、year、month、day
如:

print year(now)& "年"  & month(now) & "" & day(now) & "日"   '输出当前的日期

5、hour、minute、second

八、随机函数
1、randomize:初始化随机数生成器,无须任何参数

2、Rnd:返回一个single值。

九、格式化函数:format

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值