Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:发现一个Bug,关于With

1楼
zhuya820 发表于:2021/7/11 9:58:00
Dim Str As String = "0 0" & Chr(10) & Chr(13) & vbcrlf & "0"
Dim Int As Integer
Output.Show("【第1次输出】")
With Str
    Str = Str.Replace(vbcrlf,Chrw(12276))
    Str = Str.Replace(Chr(13),Chrw(12276))
    Str = Str.Replace(Chr(10),Chrw(12276))
    Int = Str.Length
    For I As Integer = 0 To Int - 1
        Output.Show(Ascw(Str.Chars(I)))
    Next
End With
Output.Show("【第2次输出】")
Str = "0 0" & Chr(10) & Chr(13) & vbcrlf & "0"
With Str
    Str = .Replace(vbcrlf,Chrw(12276))
    Str = .Replace(Chr(13),Chrw(12276))
    Str = .Replace(Chr(10),Chrw(12276))
    Int = Str.Length
    For I As Integer = 0 To Int - 1
        Output.Show(Ascw(.Chars(I)))
    Next
End With
【输出结果】
【第1次输出】
48
32
48
12276
12276
12276
48
【第2次输出】
48
32
48
10
13
13
10
48
【问题】
Chr(10)在第2次是多余的,这问题搞了我昨天一下午,现在汇报给组织,忘改进!
2楼
有点蓝 发表于:2021/7/19 8:59:00
这玩意不是bug,再说了这个是.net自身的语法,不是foxtable创造的。

Str = Str.Replace(vbcrlf,Chrw(12276))和Str = .Replace(vbcrlf,Chrw(12276))改变的都是外部的str变量,其实with str内部有一个独立的变量使用,一直没有变过

with 和 end with之间形成了一个独立的程序域,可以把with理解为一个sub方法。自行测试一下下面代码,原理是一样的

全局代码
Public Sub abc(str As String)
Dim s As String = str
s = s.replace("1","A")
End Sub

Public Sub abc2(str As String)
str = str.replace("1","A")
End Sub

命令窗口测试
Dim str As String = "1"
abc(str)
Output.Show(str)
abc2(str)
Output.Show(str)
共2 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .01563 s, 2 queries.