VB.NET难题 [英] VB.NET puzzle

查看:76
本文介绍了VB.NET难题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数组,比如


inp1(0)=" Cat" inp2(0)= 3

inp1(1)=" Dog" inp2(1)= 4

我想用它们来创建一个新的变量,其中一部分是来自inp1的字符串名称和相应的值。例如,这里是我想从上面的数组创建的VB.NET

字符串变量:

strCat = 3(注意Cat是inp1(0) )价值3

是inp2(0))


strDog = 4

任何想法怎么做?


TIA,


比尔

解决方案

会不会使用枚举更谨慎?

您试图将运行时值与编译时文字和

符号混合使用。


-Rob Teixeira [MVP]

" bill salkin" <一个******* @ discussions.microsoft.com>在留言中写道

news:07 **************************** @ phx.gbl ... < blockquote class =post_quotes>我有两个数组,比如

inp1(0)=" Cat" inp2(0)= 3
inp1(1)=" Dog" inp2(1)= 4

我想用它们来创建一个新变量,其中部分字符串名称来自inp1,而相应的
值来自inp2。例如,以下是我想从上面的数组创建的VB.NET
字符串变量:

strCat = 3(注意Cat是inp1(0)的值3
是inp2(0))

strDog = 4

任何想法如何做到这一点?

TIA,



也许我的inp2示例是一个糟糕的选择。我没有/ b $ b意味着暗示这些值必须是连续的

整数。例如,Inp2可以包含其他字符串

值。


在这种情况下,如何使用Enum'并不明显


Bill

-----原始消息-----
使用枚举会更谨慎吗?
你正在尝试将运行时值与compile-
时间文字和符号混合使用。

-Rob Teixeira [MVP]

" bill salkin" <一个******* @ discussions.microsoft.com>在messagenews中写了
:07 **************************** @ phx.gbl ...

我有两个阵列,说

inp1(0)=" Cat" inp2(0)= 3
inp1(1)=" Dog" inp2(1)= 4

我想用它们来创建一个新变量,其中
的字符串名称来自inp1,而相应的
值来自inp2。例如,以下是我想从上面的数组创建的VB.NET
字符串变量:

strCat = 3(注意Cat是inp1(0)的值
of 3 isp2(0))

strDog = 4

任何想法如何做到这一点?

TIA,





不幸的是,VB没有有了集合的概念(比如Pascal),所以你要

必须手动和单独定义值(不像枚举的

分组值),但是我仍然很好奇为什么你这样做。如果你要
将使用代码中的值(否则为什么要使用变量

命名?),你就会知道在程序出现之前它们应该是什么/>
汇编了吧?


-Rob Teixeira [MVP]


" bill salkin" <一个******* @ discussions.microsoft.com>在消息中写道

news:06 **************************** @ phx.gbl ... < blockquote class =post_quotes>也许我的inp2示例是一个糟糕的选择。我并不意味着暗示这些值必须是连续的整数。例如,Inp2可能包含其他字符串
值。

在这种情况下,如何使用Enum的

Bill

-----原始消息-----
使用枚举会更加谨慎吗?
您正在尝试将运行时值与编译混合 -


时间文字和

符号。

-Rob Teixeira [MVP]

" bill salkin" <一个******* @ discussions.microsoft.com>在消息

新闻中写道


:07 **************************** @phx.gbl ...

我有两个数组,比如说

inp1(0)=" Cat" inp2(0)= 3
inp1(1)=" Dog" inp2(1)= 4

我想用它们来创建一个新变量,其中部分字符串名称来自inp1,而相应的
值来自inp2。例如,以下是我想从上面的数组创建的VB.NET
字符串变量:

strCat = 3(注意Cat是inp1(0)的值3是inp2(0))

strDog = 4

任何想法怎么做?

TIA,





I have two arrays, say

inp1(0) = "Cat" inp2(0) = 3
inp1(1) = "Dog" inp2(1) = 4

I want to use them to create a new variable with part of
the string name coming from inp1 and the corresponding
value coming from inp2. For example, here are the VB.NET
string variables I want to create from the above arrays:
strCat = 3 (note that "Cat" is inp1(0) the the value of 3
is inp2(0))

strDog = 4
Any ideas how to do this?

TIA,

Bill

解决方案

Would it be more prudent to use an Enum?
You are attempting to mix runtime values with compile-time literals and
symbols.

-Rob Teixeira [MVP]
"bill salkin" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...

I have two arrays, say

inp1(0) = "Cat" inp2(0) = 3
inp1(1) = "Dog" inp2(1) = 4

I want to use them to create a new variable with part of
the string name coming from inp1 and the corresponding
value coming from inp2. For example, here are the VB.NET
string variables I want to create from the above arrays:
strCat = 3 (note that "Cat" is inp1(0) the the value of 3
is inp2(0))

strDog = 4
Any ideas how to do this?

TIA,

Bill



Perhaps my example for inp2 was a bad choice. I didn''t
mean to imply that those values must be consecutive
integers. Inp2 could, for example contain other string
values.

Under that context it''s not obvious how to use Enum''s

Bill

-----Original Message-----
Would it be more prudent to use an Enum?
You are attempting to mix runtime values with compile- time literals andsymbols.

-Rob Teixeira [MVP]
"bill salkin" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...

I have two arrays, say

inp1(0) = "Cat" inp2(0) = 3
inp1(1) = "Dog" inp2(1) = 4

I want to use them to create a new variable with part of the string name coming from inp1 and the corresponding
value coming from inp2. For example, here are the VB.NET
string variables I want to create from the above arrays:
strCat = 3 (note that "Cat" is inp1(0) the the value of 3 is inp2(0))

strDog = 4
Any ideas how to do this?

TIA,

Bill


.



Unfortunately, VB doesn''t have the concept of Sets (like Pascal), so you''ll
have to define the values manually and seperately (unlike an enum with its
grouped values), but I''m still curious as to why you''re doing this. If you
are going to use the values in code (otherwise why have the variable
names?), you would already know what they should be before the program is
compiled, right?

-Rob Teixeira [MVP]

"bill salkin" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...

Perhaps my example for inp2 was a bad choice. I didn''t
mean to imply that those values must be consecutive
integers. Inp2 could, for example contain other string
values.

Under that context it''s not obvious how to use Enum''s

Bill

-----Original Message-----
Would it be more prudent to use an Enum?
You are attempting to mix runtime values with compile-


time literals and

symbols.

-Rob Teixeira [MVP]
"bill salkin" <an*******@discussions.microsoft.com> wrote


in message

news:07****************************@phx.gbl...

I have two arrays, say

inp1(0) = "Cat" inp2(0) = 3
inp1(1) = "Dog" inp2(1) = 4

I want to use them to create a new variable with part of the string name coming from inp1 and the corresponding
value coming from inp2. For example, here are the VB.NET
string variables I want to create from the above arrays:
strCat = 3 (note that "Cat" is inp1(0) the the value of 3 is inp2(0))

strDog = 4
Any ideas how to do this?

TIA,

Bill


.



这篇关于VB.NET难题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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