标题:Function 为什么不能这样调用?
只看楼主
kira007
Rank: 2
等 级:论坛游民
帖 子:294
专家分:27
注 册:2007-6-28
结帖率:50%
已结贴  问题点数:20 回复次数:3 
Function 为什么不能这样调用?
oldstr="1|2"
newstr="1"



addstr = CompareString(oldstr,newstr,"add")


'=================================================
'这个位置 输出 oldstr 或者 newstr 或 下面的调用 都会报错
'delstr = CompareString(oldstr,newstr,"del")
'只能单个调用
'除非加上 oldstr2=oldstr,  newstr2= newstr
'把以上调用改为 delstr = CompareString(oldstr2,newstr2,"del")
'这样就可以 同时存在 addstr , delstr
'这是什么原因??
'=================================================




Function CompareString(str1,str2,action)
dim restring,sum
    restring=""
    sum=0
    
    if action ="add" then
    
                if Int(len(str1))=0  then
                    restring = str2
                else
                '=========================================================
                    str1=split(str1,"|")
                    str2=split(str2,"|")
                    
                    for i=0 to ubound(str2)
                    
                            for j=0 to ubound(str1)
                                if str2(i) = str1(j) then
                                    exit for
                                else
                                    sum = sum+1
                                end if
                            next
                        
                        if(sum = ubound(str1)+1) then
                            restring = restring & str2(i) &"|"
                        end if
                        sum=0
                    next
                '======================================================
                
                    if len(restring)>0 then
                        restring=left(restring,len(restring)-1)
                    end if                
                    
                end if
                
    
    else
    
            if Int(len(str2))=0 then'新字符串为空
                
                restring = str1 ' 返回原字符串 作为 删除字符
            else

                    str1=split(str1,"|")
                    str2=split(str2,"|")
                    
                    for i=0 to ubound(str1)
                    
                            for j=0 to ubound(str2)
                                if str2(j) = str1(i) then
                                    exit for
                                else
                                    sum = sum+1
                                end if
                            next
                        
                        if(sum = ubound(str2)+1) then
                            restring = restring & str1(i) &"|"
                        end if
                        sum=0
                    next
                '======================================================
                
                    if len(restring)>0 then
                        restring=left(restring,len(restring)-1)
                    end if                

            
            end if
    
    
    end if



    '得出需要 增添的字符            
    CompareString = restring

End Function
搜索更多相关主题的帖子: Function 
2009-07-20 10:20
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:20 
不明白楼主写这个函数做什么用?想调用什么?
2009-07-20 14:33
kira007
Rank: 2
等 级:论坛游民
帖 子:294
专家分:27
注 册:2007-6-28
得分:0 
字符串比较啊
比较 字符串1 和 字符串2
根据参数
得到比较结果
如:A=1,3,4
    B= 1,5,6
ADD-> 得到字符串A 比 字符串B 不同的新 字符串3,4
DEL-> 得到字符串B 比 字符串A 不同的新 字符串5,6

生活的理想,就是为了理想的生活。
2009-07-20 18:05
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
这两个字符串允许长度不一样?
2009-07-20 18:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-279868-1-1.html




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

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