问题描述
嗨:
我无法动态设置变量。以下
代码不起作用。非常感谢任何想法。
谢谢,
吉姆
Dim astr As String
Dim bstr As String
Dim myval As Double
Dim te As Double
Dim AAA As Object
astr = 测试
bstr =" test"
如果astr = bstr那么
''想要设置变量te(这是双倍的) )= 333.3
''AAA = CType(astr,ValueType)
AAA =中(bstr,1,2)
''中(bstr,1,2)= 333.3
AAA = 333.3
结束如果
te = te + 1
''变量te现在应该设置为334.3
Hi:
I am having trouble dynamically setting a variable. The following
code does not work. Any ideas would greatly be appreciated.
Thanks,
Jim
Dim astr As String
Dim bstr As String
Dim myval As Double
Dim te As Double
Dim AAA As Object
astr = "test"
bstr = "test"
If astr = bstr Then
''want to set variable te (which is double) = 333.3
'' AAA = CType(astr, ValueType)
AAA = Mid(bstr, 1, 2)
'' Mid(bstr, 1, 2) = 333.3
AAA = 333.3
End If
te = te + 1
''variable te should now be set to 334.3
推荐答案
你永远不会给te赋值。为什么使用实用程序变量
''AAA''?
\\\
Dim astr, bstr As String
Dim te As Double
astr =" test"
bstr =" test"
如果astr = bstr
如果是IsNumeric(astr)那么
te = Double.Parse(astr)
否则
...
结束如果
否则
te = 333.3
结束如果
te = te + 1
MsgBox(te.ToString())
///
-
Herfried K. Wagner [MVP]
< http://www.mvps.org/dotnet>
You never assign a value to ''te''. Why do you use the utility variable
''AAA''?
\\\
Dim astr, bstr As String
Dim te As Double
astr = "test"
bstr = "test"
If astr = bstr
If IsNumeric(astr) Then
te = Double.Parse(astr)
Else
...
End If
Else
te = 333.3
End If
te = te + 1
MsgBox(te.ToString())
///
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
你永远不会为''te''赋值。为什么你使用实用程序变量
''AAA''?
\\\
Dim astr,bstr As String
Dim te As Double
astr =" test"
bstr =" test"
如果astr = bstr
如果是IsNumeric(astr)那么
te = Double.Parse(astr)
其他
...
结束如果
等等te = 333.3
结束如果
te = te + 1
MsgBox( te.ToString())
///
You never assign a value to ''te''. Why do you use the utility variable
''AAA''?
\\\
Dim astr, bstr As String
Dim te As Double
astr = "test"
bstr = "test"
If astr = bstr
If IsNumeric(astr) Then
te = Double.Parse(astr)
Else
...
End If
Else
te = 333.3
End If
te = te + 1
MsgBox(te.ToString())
///
我会做设计。您可以使用''Hashtable''来存储(key,
值)对。也许这符合你的需求。
-
Herfried K. Wagner [MVP]
< http:// www.mvps.org/dotnet>
I would rething the design. You can use a ''Hashtable'' to store (key,
value) pairs. Maybe this will fit your needs.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
这篇关于动态设置varibable值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!