感觉好玩但不一定好用的代码

类CLink代码如下:
Private  mI  As   Integer

Public   Function  Append(i  As   Integer As  CLink
    mI 
=  mI  +  i
    
Set  Append  =  Me
End Function

Public   Function  GetValue()  As   Integer
    GetValue 
=  mI
End Function
用法如下:
     Dim  c  As  CLink
    
Set  c  =   New  CLink
    
MsgBox  c.Append( 1 ).Append( 2 ).Append( 3 ).GetValue
    
Set  c  =   Nothing
好玩的就是Append函数的用法,《Programming Ruby》里边有一段这么的用法,只是感觉有趣。

判断是否包含字符串的一个用法,下边只是一个范例:
Private   Function  IncludeNumber(s  As   String As   Boolean
    Static c 
As  Collection
    
Dim  i  As   Integer
    
Dim  v  As   String
    
If  c  Is   Nothing   Then
        
Set  c  =   New  Collection
        
For  i  =   0   To   9
            c.Add i, 
" c "   &  i
        
Next
    
End   If
    
On   Error   GoTo  e:
    c.Item 
" c "   &  s
    IncludeNumber 
=   True
    
Exit   Function
e:
End Function
说白了,很多时候适当利用错误处理进行一些逻辑判断也是好的。 719489.html

Duiker 2007-04-19 12:50 发表评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值