需要使用存储在字符串 vb6 中的值引用变量

发布于 2024-07-12 10:14:36 字数 396 浏览 11 评论 0原文

我正在使用 For 循环遍历一些代码。 迭代变量是“i”。 我在 For 循环之前确定了以下变量的尺寸。 L1、L2、L3、L4 作为字符串。 我想通过某种方式引用“L”和“L”来在 For 循环内引用这些字符串。 字符(i)。 就像值“Foo”的比较一样 “灯; Char(i),当 i=1 时,结果应该是针对存储在变量 L1 中的字符串测试“Foo”。 或者当 i=2 时对抗 L2 等等。

我以前的编程经验是 Visual FoxPro,我所要做的就是在前面加上 & 。 位于字符串的前面,然后引用名称存储在字符串中的变量。

因此,如果 L1 存储“Bar”,并且我想进行比较,我可以写 &L1 ==“Bar”。 我需要能够使用 VB6 来完成此操作。 有人可以帮忙吗?

I am looping through some code using a For loop. The iterative variable is "i". I have dimensioned the following variables prior to the For Loop. L1, L2, L3, L4 as strings. I want to reference these strings inside the For loop by somehow referring to "L" & char(i). So like a comparison of a value "Foo" <> "L" & Char(i), should result is testing "Foo" against the string stored in variable L1, when i=1. Or against L2 when i=2 and so on.

My previous programming experience is Visual FoxPro and all I had to do was prefix an & on the front of the string and it then referenced the variable whose name is stored in the string.

So if L1 stored "Bar", and I wanted to compare I could write &L1 == "Bar". I need to be able to do this with VB6. Can anyone help?

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

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

发布评论

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

评论(3

两相知 2024-07-19 10:14:36

我建议您创建一个数组,而不是创建 4 个变量。 前任:

Dim L(1 To 4) As String

For i = 1 to 4
    L(i) = "Whatever"
Next

Instead of creating 4 variables, I would suggest that you create an array. Ex:

Dim L(1 To 4) As String

For i = 1 to 4
    L(i) = "Whatever"
Next
无敌元气妹 2024-07-19 10:14:36

你真正想要的是一个数组,如下所示:

Dim L(3) As String  ''// index begins at 0, 4 total elements

For Each i As String In L
    If "Foo" <> i Then
        ''// ...
    End If
Next i

What you really want is an array, like this:

Dim L(3) As String  ''// index begins at 0, 4 total elements

For Each i As String In L
    If "Foo" <> i Then
        ''// ...
    End If
Next i
半步萧音过轻尘 2024-07-19 10:14:36

这适用于类(例如 VB 表单):

Option Explicit

Public L1 As String
Public L2 As String
Public L3 As String
Public L4 As String

Sub Main()

  L1 = "Foo"
  L2 = "Bar"
  L3 = "Go"
  L4 = "Figure"

  Dim i As Long
  For i = 1 To 4
    Debug.Print CallByName(Me, "L" & CStr(i), VbGet)
  Next

End Sub

This works in a class (e.g. a VB Form):

Option Explicit

Public L1 As String
Public L2 As String
Public L3 As String
Public L4 As String

Sub Main()

  L1 = "Foo"
  L2 = "Bar"
  L3 = "Go"
  L4 = "Figure"

  Dim i As Long
  For i = 1 To 4
    Debug.Print CallByName(Me, "L" & CStr(i), VbGet)
  Next

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