| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1842 人关注过本帖
标题:求一个RFIND函数的每句什么意思
只看楼主 加入收藏
natesc
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2013-9-15
结帖率:37.5%
收藏
已结贴  问题点数:20 回复次数:5 
求一个RFIND函数的每句什么意思
程序代码:
Public Function rFind(ByVal txt As String, ByVal code1 As String, Optional ByVal code2 As String = """", Optional ByVal rev As Boolean = False)
    On Error Resume Next
    Dim tmp As String, i1 As Long, i2 As Long
    tmp = txt
    If InStr(tmp, code1) = 0 Then rFind = "": Exit Function
    i1 = InStr(tmp, code1) + Len(code1)
    tmp = Mid(tmp, i1)
    If InStr(tmp, code2) = 0 Then rFind = "": Exit Function
    If rev Then
       i2 = InStrRev(tmp, code2)
    Else
       i2 = InStr(tmp, code2)
    End If
    rFind = Mid(tmp, 1, i2 - 1)
End Function

特别是其中I1,I2,TMP,COD1,COD2,及最后的RFIND都是什么意思[color=#0000FF][/color]

[此贴子已经被作者于2017-2-3 17:18编辑过]

搜索更多相关主题的帖子: color 
2017-02-03 17:06
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4938
专家分:30047
注 册:2008-10-15
收藏
得分:10 
Public Function rFind(ByVal txt As String, ByVal code1 As String, Optional ByVal code2 As String = """", Optional ByVal rev As Boolean = False)
    On Error Resume Next
    Dim tmp As String, i1 As Long, i2 As Long
    tmp = txt           '取传入的字串
    If InStr(tmp, code1) = 0 Then rFind = "": Exit Function     '如果转入的字串不包含第一个字串,返回空,结束函数
    i1 = InStr(tmp, code1) + Len(code1)           '计算第一个字串在目标字串结束的位置
    tmp = Mid(tmp, i1)           '取第一个字串在目标字串之后的字符
    If InStr(tmp, code2) = 0 Then rFind = "": Exit Function       '如果不包含第二个字串,返回空,结束函数
    If rev Then                 '传入第二个字串查找方向
       i2 = InStrRev(tmp, code2)       '从右向左查找
    Else
       i2 = InStr(tmp, code2)         '从左到右查找
    End If
    rFind = Mid(tmp, 1, i2 - 1)       '得到从第一字串结束到 第二个字串开始之间的字符,并返回结果
                                      'rFind 是函数名,可以理解为一个变量,该变量用于返回函数结果,只能写在 等号的左边
                                      '如果写在右边就是递归调用
End Function

授人于鱼,不如授人于渔
早已停用QQ了
2017-02-03 17:53
natesc
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2013-9-15
收藏
得分:0 
谢谢指教
2017-02-03 18:44
natesc
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2013-9-15
收藏
得分:0 
回复 3楼 natesc
那么在下面这代码中引用,又怎么理解
程序代码:
Public Function RichStr(TMRichText As String, xxRichText As String) As String
    
    If TMRichText = "" Then
        RichStr = ""
        Exit Function
    End If
    
    If xxRichText = "" Then
        RichStr = ""
        Exit Function
    End If
    
    
    Dim TMlen As Long
    Dim XXlen As Long
    
    Dim TMStra As String
    Dim XXStr As String
    
    TMlen = Val(rFind(TMRichText, "lang2052\f0\fs", " "))
    XXlen = Val(rFind(xxRichText, "lang2052\f0\fs", " "))
    
    TMStra = rFind(TMRichText, "lang2052\f0\fs" & TMlen, "\par")
    XXStr = rFind(xxRichText, "lang2052\f0\fs" & XXlen, "\par")
    
    
    '开始拼接编码
    
    Dim RichStr1 As String
    
    RichStr1 = TMStra & "\par  \par" & XXStr
    
    Dim Str1 As String
    
    Str1 = "{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052{\fonttbl{\f0\fnil\fcharset134 \'cb\'ce\'cc\'e5;}}" & vbCrLf & "\viewkind4\uc1\pard\lang2052\f0\fs" & TMlen + XXSStr & RichStr1 & "\par }"
    
    RichStr = Str1
    
    
End Function


[此贴子已经被作者于2017-2-3 18:47编辑过]

2017-02-03 18:46
natesc
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2013-9-15
收藏
得分:0 
回复 2楼 风吹过b
Public Function rFind(ByVal txt As String, ByVal code1 As String, Optional ByVal code2 As String = """", Optional ByVal rev As Boolean = False)
    On Error Resume Next
    Dim tmp As String, i1 As Long, i2 As Long
    tmp = txt                                         'tmp赋值txt
    If InStr(tmp, code1) = 0 Then rFind = "": Exit Function    '如果tmp为零长度或者txt中没有子串code1,rFind = ""同时退出函数
    i1 = InStr(tmp, code1) + Len(code1)               '定位txt中包含的第一个子串code1之后
    tmp = Mid(tmp, i1)                                '从上述位置截取tmp重新赋值个tmp
    If InStr(tmp, code2) = 0 Then rFind = "": Exit Function    '如果tmp为零长度或者txt中没有子串code2,rFind = ""同时退出函数
    If rev Then
        i2 = InStrRev(tmp, code2)                     '如果反序,则用InStrRev求子串code2在tmp的位置
    Else
        i2 = InStr(tmp, code2)                        '如果不是反序,则用InStr求子串code2在tmp的位置
    End If
    rFind = Mid(tmp, 1, i2 - 1)                       '从上述位置截取tmp重新赋值个tmp,只有tmp中有2个或2个以上的子串code2时,反序和正序才有差别,当只有一个时,逆序正序结果相同
End Function
这是另一个网友给的解释,不知道有什么不同
2017-02-03 21:14
xiangyue0510
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:86
帖 子:938
专家分:5244
注 册:2015-8-10
收藏
得分:10 
风版真的很热心,也有耐心。
学编程就是读代码到写代码的过程,像这种自己不去读代码,所有的语句都要别人替他标注的,我说实话不爱搭理。
2017-02-04 08:41
快速回复:求一个RFIND函数的每句什么意思
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016825 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved