传递部分名称作为参数 [英] pass part of name as argument

查看:59
本文介绍了传递部分名称作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据传递的名称访问多个参数。


例如我有以下asp:textboxes:


BillingAddress1

BillingAddress2

BillingCity

ShippingAddress1

ShippingAddress2

ShippingCity


我有2个子程序。 Sub A呼叫Sub B并且通过Billing和Billing。或

运费。我希望能够通过连接名称访问对象

(BillingAddress1.Text,ShippingAddress1.Text等)。我

不想说


如果name =" Billing"然后

BillingAddress1.Text =" something

else

ShippingAddress2.Text =" something

end if


我想做类似的事情:


Sub A()

致电B(结算) ,somevalue1,somevalue2,somevalue3)

致电B(运费,somevalue4,somevalue5,somevalue6)

End Sub


Sub B(名称,值1,值2,值3)

名称+地址1 =值1''我知道我不能这样做

方式 - 我想要替换名称+地址1用其他东西。

姓名+地址2 =价值2

姓名+地址3 =价值3

结束子


谢谢,


Tom

I want to access multiple arguments based on name passed.

For example I have the following asp:textboxes:

BillingAddress1
BillingAddress2
BillingCity
ShippingAddress1
ShippingAddress2
ShippingCity

I have 2 subroutines. Sub A call Sub B and passess either "Billing" or
"Shipping". I wanted to be able to access the objects
(BillingAddress1.Text, ShippingAddress1.Text etc) by a concatenated name. I
don''t want to say

If name = "Billing" then
BillingAddress1.Text = "something
else
ShippingAddress2.Text = "something
end if

I want to do something like:

Sub A ()
Call B ("Billing",somevalue1, somevalue2,somevalue3)
Call B ("Shipping",somevalue4,somevalue5,somevalue6)
End Sub

Sub B (Name,value1,value2,value3)
Name + Address1 = value1 '' I know I can''t do it this
way - I want to replace "Name + Address1" with something else.
Name + Address2 = value2
Name + Address3 = value3
End Sub

Thanks,

Tom

推荐答案

tshad,


为什么不想使用普通代码。如果你想使自己的定义成为
,编程就结束了。你展示的代码在我的想法中是完美的。


然而,也许是一个更好的替代选择案例,甚至有点

对此更好。<

http://msdn2.microsoft .com / zh-CN / library / cy37t14y.aspx


顺便说一句,使用+ for string连接可以在Visual Basic中给出

具有选项严格的不可预测的结果,因此ASPNET可能因此更加美元b $ b。正确的字符是&。


" 1" +1给出2

" 1" &安培; " 1 QUOT;给出11


我希望这会有所帮助,


Cor

" tshad" < ts ********** @ ftsolutions.comschreef在bericht

新闻:Ov ************** @ TK2MSFTNGP03.phx.gbl ...
tshad,

Why don''t you want to use normal code. Programming ends if you want to make
your own definitions. The code you show is in my idea perfect.

However maybe is a nicer alternative the Select Case which is even a little
bit nicer for this.

http://msdn2.microsoft.com/en-us/library/cy37t14y.aspx

By the way using the + for string concatination can be in Visual Basic give
unpredictable result with option strict of, probably therefore even more
with ASPNET. The correct character for that is "&".

"1" + "1" gives "2"
"1" & "1" gives "11"

I hope this helps,

Cor
"tshad" <ts**********@ftsolutions.comschreef in bericht
news:Ov**************@TK2MSFTNGP03.phx.gbl...

>我想根据传递的名称访问多个参数。


例如我有以下内容asp:文本框:


BillingAddress1

BillingAddress2

BillingCity

ShippingAddress1

ShippingAddress2

ShippingCity


我有2个子程序。 Sub A呼叫Sub B并且通过Billing和Billing。或

运费。我希望能够通过连接的名称访问对象

(BillingAddress1.Text,ShippingAddress1.Text等)。

我不想说


如果name =" Billing"然后

BillingAddress1.Text =" something

else

ShippingAddress2.Text =" something

end if


我想做类似的事情:


Sub A()

致电B(结算) ,somevalue1,somevalue2,somevalue3)

致电B(运费,somevalue4,somevalue5,somevalue6)

End Sub


Sub B(名称,值1,值2,值3)

名称+地址1 =值1''我知道我不能这样做

方式 - 我想要替换名称+地址1用其他东西。

姓名+地址2 =价值2

姓名+地址3 =价值3

结束子


谢谢,


Tom
>I want to access multiple arguments based on name passed.

For example I have the following asp:textboxes:

BillingAddress1
BillingAddress2
BillingCity
ShippingAddress1
ShippingAddress2
ShippingCity

I have 2 subroutines. Sub A call Sub B and passess either "Billing" or
"Shipping". I wanted to be able to access the objects
(BillingAddress1.Text, ShippingAddress1.Text etc) by a concatenated name.
I don''t want to say

If name = "Billing" then
BillingAddress1.Text = "something
else
ShippingAddress2.Text = "something
end if

I want to do something like:

Sub A ()
Call B ("Billing",somevalue1, somevalue2,somevalue3)
Call B ("Shipping",somevalue4,somevalue5,somevalue6)
End Sub

Sub B (Name,value1,value2,value3)
Name + Address1 = value1 '' I know I can''t do it this
way - I want to replace "Name + Address1" with something else.
Name + Address2 = value2
Name + Address3 = value3
End Sub

Thanks,

Tom



Cor,


" Cor Ligthert [MVP]" < no ************ @ planet.nlschrieb:
Cor,

"Cor Ligthert [MVP]" <no************@planet.nlschrieb:

顺便说一句,使用+ for string连接可以在Visual Basic中

给出了不可预测的结果,选项严格,因此甚至可以用ASPNET获得
。正确的字符是&。


" 1" +1给出2
By the way using the + for string concatination can be in Visual Basic
give unpredictable result with option strict of, probably therefore even
more with ASPNET. The correct character for that is "&".

"1" + "1" gives "2"



不,它不是。 " 1 QUOT; + 1''给出2而''1 +'1'''给出2,但是''1 +" 1"''

总是给''" 11"''。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org / dotnet / faqs />

No, it doesn''t. ''"1" + 1'' gives 2 and ''1 + "1"'' gives 2, but ''"1" + "1"''
always gives ''"11"''.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


感谢您的快速反应,快速撰写。


Cor


" Herfried K. Wagner [MVP]" < hi *************** @gmx.atschreef in bericht

新闻:O3 ************** @ TK2MSFTNGP03.phx.gbl ...
Thank you for your quick reaction, to quick written.

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.atschreef in bericht
news:O3**************@TK2MSFTNGP03.phx.gbl...

Cor,


" Cor Ligthert [MVP]" < no ************ @ planet.nlschrieb:
Cor,

"Cor Ligthert [MVP]" <no************@planet.nlschrieb:

>顺便使用+ for string concatination可以在Visual Basic
给出了不可预测的结果和严格的选项,因此甚至可能更多地使用ASPNET。正确的字符是&。

1和1。 +1给出2
>By the way using the + for string concatination can be in Visual Basic
give unpredictable result with option strict of, probably therefore even
more with ASPNET. The correct character for that is "&".

"1" + "1" gives "2"



不,它不是。 " 1 QUOT; + 1''给出2而''1 +'1'''给出2,但是''1 +" 1"''

总是给''" 11"''。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org / DOTNET /常见问题/>


No, it doesn''t. ''"1" + 1'' gives 2 and ''1 + "1"'' gives 2, but ''"1" + "1"''
always gives ''"11"''.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



这篇关于传递部分名称作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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