VBA 2015使用他的名字部分找到变量

时间:2016-04-18 07:56:42

标签: vba variables search find

我有:

Dim some340id, some341id, someCDFid, someARCid, some8FGid etc... as String

需要找到:

Dim idtofind as String = "ARC"

类似的东西:

Dim Found As String = some{idtofind}id

如何为此编写代码?

2 个答案:

答案 0 :(得分:0)

虽然VB是翻译,但我不知道你是否可以这样做。但是你可以做的是使用一个具有有意义的Const名称的数组和索引,例如:

Private Const i340id As Integer = 0
Private Const i341id As Integer = 1
...
Private Const iMAXid As Integer = 99

Dim some(iMAXid) As String

MsgBox "String is " & some(i341id)

答案 1 :(得分:0)

@Paul,不工作(“String is”为空),但我尝试修改你的解决方案,现在它正在工作。非常感谢你。

Public Const incoming340id As Integer = 0
    Public Const incoming341id As Integer = 1
    Public Const incomingMAXid As Integer = 99

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim some As String = 341

    MsgBox("String is " & "incoming" & some.ToString & "id")
End Sub

现在如何改变工作变量?

Dim somethingNew as String = "incoming" & some.ToString & "id"

我有新东西,想要像变量incoming341id一样工作

incoming341id = otherResult.Text

但现在我有了“新东西”......