动态设置varibable值? [英] Dynamically set varibable value?

查看:68
本文介绍了动态设置varibable值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨:


我无法动态设置变量。以下

代码不起作用。非常感谢任何想法。

谢谢,

吉姆


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

推荐答案

* ra **** @ fauske.com (jcr)scripsit:
* ra****@fauske.com (jcr) scripsit:
我无法动态设置变量。以下
代码不起作用。任何想法都将不胜感激。
谢谢,
吉姆

昏暗的astr作为弦
昏暗的bstr作为弦
昏暗的myval作为双
Dim te As Double
昏暗的AAA作为对象
astr =" test"
bstr =" test"

如果astr = bstr那么
' '想要设置变量te(这是双倍)= 333.3
''AAA = CType(astr,ValueType)

AAA = Mid(bstr,1,2)
' '中(bstr,1,2)= 333.3
AAA = 333.3
结束如果

te = te + 1
''变量te现在应该设置为334.3
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>


嗨感谢您的回复。


每次输入

这部分代码时,变量bstr的文本都会有所不同。 bstr的文本值是我要设置的

变量。例如,如果bstr =MO,我想

将变量MO设置为唯一值。我现在通过IF条件获得很多

来实现这一目标。我想动态地做。


感谢您的帮助,

Jim

hi *************** @ gmx.at (Herfried K. Wagner [MVP])在留言新闻中写道:< c0 ************* @ ID-208219.news.uni-berlin.de> ...
Hi Thanks for the reply.

The text for variable bstr will be different for each time I enter
this portion of the code. The value of the text for bstr is the
variable that I want to set. For example, if bstr = "MO" I want to
set the variable MO to a unique value. I do this now by having alot
of "IF conditions". I would like to do it dynamically.

Thanks for your help,
Jim

hi***************@gmx.at (Herfried K. Wagner [MVP]) wrote in message news:<c0*************@ID-208219.news.uni-berlin.de>...
* ra****@fauske.com (jcr)scripsit:
* ra****@fauske.com (jcr) scripsit:
我无法动态设置一个变量。以下
代码不起作用。任何想法都将不胜感激。
谢谢,
吉姆

昏暗的astr作为弦
昏暗的bstr作为弦
昏暗的myval作为双
Dim te As Double
昏暗的AAA作为对象
astr =" test"
bstr =" test"

如果astr = bstr那么
' '想要设置变量te(这是双倍)= 333.3
''AAA = CType(astr,ValueType)

AAA = Mid(bstr,1,2)
' '中(bstr,1,2)= 333.3
AAA = 333.3
结束如果

te = te + 1
''变量te现在应该设置为334.3
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())
///



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())
///



* ra **** @ fauske.com (jcr)scripsit:
* ra****@fauske.com (jcr) scripsit:
每次输入这部分代码时,变量bstr的文本都会有所不同。 bstr的文本值是我想要设置的
变量。例如,如果bstr =MO,我想将变量MO设置为唯一值。我现在通过大量的IF条件来做到这一点。我想动态地做。
The text for variable bstr will be different for each time I enter
this portion of the code. The value of the text for bstr is the
variable that I want to set. For example, if bstr = "MO" I want to
set the variable MO to a unique value. I do this now by having alot
of "IF conditions". I would like to do it dynamically.




我会做设计。您可以使用''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值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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