类CLink代码如下:
Private mI As Integer

Public Function Append(i As IntegerAs 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 StringAs 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
说白了,很多时候适当利用错误处理进行一些逻辑判断也是好的。

相关文章:

  • 2021-06-05
  • 2022-01-24
  • 2021-10-19
  • 2021-06-30
  • 2022-02-12
  • 2021-07-30
  • 2022-03-06
  • 2022-12-23
猜你喜欢
  • 2021-11-19
  • 2022-02-13
  • 2022-12-23
  • 2021-10-09
  • 2022-12-23
相关资源
相似解决方案