VB6 到 VB.NET Visual Studio 升级向导讨厌我的一些变量名

发布于 2024-08-02 01:16:34 字数 1042 浏览 4 评论 0原文

我正在使用升级向导将 VB6 升级到 VB.NET 项目。 我知道这会给我带来很大的悲伤,但我正在努力使旧的应用程序可用。 如果我有时间,我会重写它,但目前我正在完成暑期实习,并且希望能有所作为。

向导正在做的一件事我找不到理由,那就是重命名随机变量。 例如:

Structure ctrObj
    Dim Name As String
    Dim Index As Integer
    Dim Top As Integer
    'UPGRADE_NOTE: Left was upgraded to Left_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Dim Left_Renamed As Integer
    Dim Height As Integer
    Dim width As Integer
    Dim ScaleHeight As Integer
    Dim ScaleWidth As Integer
End Structure

对于我的一生,我不明白为什么这会向左改变。 据我所知,它不是一个保留名称,我在范围内找不到其他名为 left 的变量,并且重命名它不会产生编译器错误。

'UPGRADE_NOTE: Left was upgraded to Left_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Dim Left_Renamed As Integer

更改为

Dim Left As Integer

不会给出编译器错误。

它对整个项目中看似随机的变量执行此操作。 有人知道为什么它不喜欢我的一些变量名吗?

I am upgrading a VB6 to VB.NET project using the upgrade wizard. I know this is going to give me a lot of grief, but I am trying to make the old application useable. I'd rewrite it if I had time but am currently finishing up a summer internship and would like to get something working.

One thing the wizard is doing that I can find no justification for is renaming of random variables. For example:

Structure ctrObj
    Dim Name As String
    Dim Index As Integer
    Dim Top As Integer
    'UPGRADE_NOTE: Left was upgraded to Left_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Dim Left_Renamed As Integer
    Dim Height As Integer
    Dim width As Integer
    Dim ScaleHeight As Integer
    Dim ScaleWidth As Integer
End Structure

For the life of me I don't understand why this is changing left. It isn't a reserved name as far as I can tell, there is no other variable named left that I can find in scope, and renaming it does not create a compiler error.

'UPGRADE_NOTE: Left was upgraded to Left_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Dim Left_Renamed As Integer

changed to

Dim Left As Integer

does not give a compiler error.

It does this to seemingly random variables throughout my project. Anyone have ideas as to why it doesn't like some of my variable names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

⒈起吃苦の倖褔 2024-08-09 01:16:34

我最好的猜测是,它重命名为 Left 以避免与 VB Function Left 混淆。 这是命名空间中模块的方法,默认导入到每个 VB.Net 项目中。 因此它是全球可用的。

例如: This 编译得很好

Dim x = Left("here", 1)

它可能担心如果不带参数使用该函数可能会出现歧义错误。 例如

Public Structure S1
  Public Left As Integer
  Public Sub Method1()
    Dim x = Left
  End Sub
End Structure

,但是由于几个原因,这不可能发生。 主要是 VB 的名称绑定规则将优先使用成员变量 Left 而不是模块函数 Left。

因此,不完全确定原因,但这可能是为了避免潜在的歧义而过于谨慎。

My best guess is that it's renaming Left to avoid confusion with the VB Function Left. This is a method on a module in a namespace which is default imported into every VB.Net project. As such it is globally available.

For example: This compiles just fine

Dim x = Left("here", 1)

It is probably worried that there could be an ambiguity error if the function was used without arguments. For example

Public Structure S1
  Public Left As Integer
  Public Sub Method1()
    Dim x = Left
  End Sub
End Structure

However this can't happen though for a couple of reasons. Primarily VB's name binding rules will prefer the member variable Left over the Module Function Left.

So, not entirely sure why but it's probably an over caution to avoid potential ambiguity.

影子是时光的心 2024-08-09 01:16:34

Left 是 Visual Basic 中的字符串函数。 它从字符串左侧获取指定数量的字符,并返回包含这些字符的新字符串。

Left is a string function in Visual Basic. It takes the specified number of characters from the left side of a string and returns a new string containing those characters.

守护在此方 2024-08-09 01:16:34

VB6 x$ = left$("你好世界",5)
print x$ hello

VB2005,8,9 vs VB6

 left = left$
 right = right$
 mid   = mid$
 trim  = trim$
 chr(13)+chr(10) = Chr$(32)+ Chr$(10) (line feed + carriage return)

left 是保留字,会生成错误,因此转换程序会以您知道它已被更改的方式更改它。

VB6 x$ = left$("hello world",5)
print x$ hello

VB2005,8,9 vs VB6

 left = left$
 right = right$
 mid   = mid$
 trim  = trim$
 chr(13)+chr(10) = Chr$(32)+ Chr$(10) (line feed + carriage return)

left is a reserve word and will generate errors so the conversion program changes it in a way that you know it's been changed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文