比如在全局代码里定义了3个全局变量 : _todo :"TODO",
_finished:"FINISHED"
_lost:"LOST"
怎样写代码遍历这些全局变量的值呢?我用下面的方式写,只是得到变量字符串本身,不能得到变量对应的值。
Dim sts() As String = {"_todo","_finished","_lost"}
For Each st As String In sts
output.show(st)
Next
Dim sts() As String = {"_todo","_finished","_lost"}
For Each st As String In sts
output.show(vars(st))
Next
Dim sts() As String = {"_todo", "_finished", "_lost"}
For Each st As String In sts
output.show("Vars(" & """" & (st) & """" & ")")
Next
我做了个示例,全局变量已赋值,用2楼代码显示不了值
此主题相关图片如下:pixpin_2024-05-27_10-24-21.png
如果使用的的是public变量,不是vars变量。没有办法遍历处理,只能逐个变量使用