VB:根据其他变量的值为变量命名 [英] VB:Giving variables a name from values of other variables

查看:40
本文介绍了VB:根据其他变量的值为变量命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个人的值之后创建一个变量名.

I'd like to make a variable with it's name after anotherone's value.

这是一个例子:

    While loopBool
        loopTimes = 0
        FolderBrowserDialog1.ShowDialog()
        If DialogResult.OK Then
            Dim [loopTimes] As String = FolderBrowserDialog1.SelectedPath() 
        End If
        'Some more stuff
    End While

我希望 [loopTimes] 是变量 loopTimes 的值,但我无法弄清楚.提前致谢

I'd like the [loopTimes] be the value of the variable loopTimes but I can't figure it out. Thanks in advance

推荐答案

最好的方法是使用字典:

The best way to accomplish this is to use a dictionary:

Dim myDict As New Dictionary(Of Integer, String)()

然后,您可以将字符串添加到字典中:

Then, you can add your strings to the dictionary:

While loopBool
    loopTimes = 0 'I'm assuming this is already declared somewhere?

    FolderBrowserDialog1.ShowDialog()
    If DialogResult.OK Then
        myDict(loopTimes) = FolderBrowserDialog1.SelectedPath() 
    End If
    'Some more stuff
End While

这篇关于VB:根据其他变量的值为变量命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆