使用变量设置变量的值 [英] Set the value of a variable using a variable

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

问题描述

可能有一种非常简单的方法可以做到这一点,所以请原谅我,但我想从变量中设置变量的值,例如......


函数Calculate_Something(ByVal乘数为整数,ByVal变量为___?)

变量= 5 *乘数

结束函数


我希望这个函数要做的是获取传入变量的名称并为其分配计算值。


任何帮助都将非常感谢,TIA !!

There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be...

function Calculate_Something(ByVal multiplyer as integer, ByVal variable as ___?)
variable = 5 * multiplyer
end function

What I would like this function to do is take the name of the incoming variable and assign a calculated value to it.

Any help would be greatly appreciated, TIA!!

推荐答案

我的第一篇文章可能还不清楚,这里有一点说明......


函数Calculate_Something (ByVal乘数为整数,ByVal name_of_variable为___?)

name_of_variable = name_of_variable * multiplyer

结束函数


假设变量我插入到name_of_variable是一个整数变量,我应该可以使用这个函数来改变一个变量的值我想要的变量。或者至少这是我想要做的事情。

" Blaxer"写道:
My first post may not have been clear, here it is clarified a bit...

function Calculate_Something(ByVal multiplyer as integer, ByVal name_of_variable as ___?)
name_of_variable = name_of_variable * multiplyer
end function

Assuming that the variable I plug in to name_of_variable is an integer variable, I should be able to use this function to change the value of any variable I want. Or at least that is what I want to be able to do.
"Blaxer" wrote:
这可能是一个非常简单的方法,所以请原谅我,但我想从变量设置一个变量的值,一个例子是.. 。

函数Calculate_Something(ByVal乘数为整数,ByVal变量为___?)
变量= 5 *乘数
结束函数

我想要什么这个功能是取传入变量的名称并为其分配一个计算值。

任何帮助将不胜感激,TIA !!
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be...

function Calculate_Something(ByVal multiplyer as integer, ByVal variable as ___?)
variable = 5 * multiplyer
end function

What I would like this function to do is take the name of the incoming variable and assign a calculated value to it.

Any help would be greatly appreciated, TIA!!



假设这是在一个类中完成的,你可以使用反射,

看一下FieldInfo.SetValue方法


hth


家伙


" Blaxer"写道:
Assuming this is done within a class you could use reflection,
have a look at FieldInfo.SetValue method

hth

guy

"Blaxer" wrote:
我的第一篇文章可能还不清楚,这里有一点澄清...

函数Calculate_Something(ByVal multiplyer as integer,ByVal name_of_variable as ___?)
name_of_variable = name_of_variable * multiplyer
结束函数

假设我插入到name_of_variable的变量是一个整数变量,我应该可以使用这个函数来改变我想要的任何变量的值。或者至少这是我想要做的事情。

" Blaxer"写道:
My first post may not have been clear, here it is clarified a bit...

function Calculate_Something(ByVal multiplyer as integer, ByVal name_of_variable as ___?)
name_of_variable = name_of_variable * multiplyer
end function

Assuming that the variable I plug in to name_of_variable is an integer variable, I should be able to use this function to change the value of any variable I want. Or at least that is what I want to be able to do.
"Blaxer" wrote:
这可能是一个非常简单的方法,所以请原谅我,但我想从变量设置一个变量的值,一个例子是.. 。

函数Calculate_Something(ByVal乘数为整数,ByVal变量为___?)
变量= 5 *乘数
结束函数

我想要什么这个函数要做的是传入变量的名称,并为其分配一个计算值。

任何帮助将不胜感激,TIA !!
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be...

function Calculate_Something(ByVal multiplyer as integer, ByVal variable as ___?)
variable = 5 * multiplyer
end function

What I would like this function to do is take the name of the incoming variable and assign a calculated value to it.

Any help would be greatly appreciated, TIA!!



你好Blaxer,


这是一个典型的超载样本


\\\\ \\ b
公共函数计算(ByVal变量为Double)As Double

返回变量* 5

结束函数

公共函数计算(ByVal变量为整数)为整数

返回变量* 5

结束函数

///


我想通过发送和返回变量作为

对象,你也可以做到这一点,但这不会给你更少的代码行,而且非常多。 br />

我希望这有帮助吗?


Cor
Hi Blaxer,

This is a typical sample of overloading

\\\
Public Function calculate(ByVal variable As Double) As Double
Return variable * 5
End Function
Public Function calculate(ByVal variable As Integer) As Integer
Return variable * 5
End Function
///

I think that you can do it as well by sending and returning the variable as
object, however that will not give you less lines of code and is very much
less clean.

I hope this helps?

Cor


这篇关于使用变量设置变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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