以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=151663)

--  作者:薛翁
--  发布时间:2020/6/30 14:39:00
--  [求助]
Dim a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22 As Double
Dim a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a34,a35,a36,a37,a38 As Double
Dim a39,a40,a41,a42,a43,a44,a45,a46,a47,a48,a49,a50,a51,a52,a53,a54,a55 As Double
Dim a56,a57,a58,a59,a60,a61,a62,a63 As Double

For Each r1 As Row In Tables("工作表").Rows
    If r1.checked Then
       For js As Integer = 1 To 63        
           a & js = 0.00
        Next
......
next

在每次循环中,这63个变量都应先清0,编译提示 a & js = 0.00出错。
运行过程中也要给变量动态赋值。
请老师告诉我该如何处理,非常感谢!



--  作者:有点蓝
--  发布时间:2020/6/30 14:51:00
--  

变量名称是无法动态取值的,只能a1=0,a2=0这样,没有这种用法:a&"1" = 0

考虑使用字典

Dim zd As New Dictionary(Of Stringdouble)
zd.add("a1",0) 
zd.add("a2",0) 
……
For Each r1 As Row In Tables("工作表").Rows
    If r1.checked Then
       For js As Integer = 1 To 63        
           zd("a" & js) = 0
        Next
......
next
[此贴子已经被作者于2020/6/30 14:52:12编辑过]