Problem with Structures

G

Guest

Hi everyone,

I have a structure with this format:
Public Structure Forms
Public _01234 as string
Public _04321 as string
Public _03456 as integer
End Structure

As you can see, the variable names are all numeric. What I want to do is
that given a numeric string, I have to determine if that string is a valid
variable of the Forms structure and if it is, then output the value.
For example, the Forms structure has these values:

_01234 = "Test1"
_04321 = "Test2"
_03456 = 100

Lets say I have a function GetStructureValue(varName as string)...
If the varName passed is "01234" then the output of the function should be
"Test1", if 03456, the output is 100, if 98765, which is not defined in the
structure, an error or -1 should be passed.

Is there a way to achieve this in vb.net?

Anyone's help will be much appreciated.

Thanks in advance!

Simang
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

Generally, it should be possible through the Reflection API. I cannot
currently think of any problems related to structures, but you should
definitely check the System.Reflection namespace docs on any particulars.
 
J

Jeff Gaines

Hi everyone,

I have a structure with this format:
Public Structure Forms
Public _01234 as string
Public _04321 as string
Public _03456 as integer
End Structure

As you can see, the variable names are all numeric. What I want to do
is that given a numeric string, I have to determine if that string is
a valid variable of the Forms structure and if it is, then output the
value. For example, the Forms structure has these values:

_01234 = "Test1"
_04321 = "Test2"
_03456 = 100

Lets say I have a function GetStructureValue(varName as string)...
If the varName passed is "01234" then the output of the function
should be "Test1", if 03456, the output is 100, if 98765, which is
not defined in the structure, an error or -1 should be passed.

Is there a way to achieve this in vb.net?

Anyone's help will be much appreciated.

Thanks in advance!

Simang

In C# you could do something like:

string GetStructureValue(varName as string)
{
string strResult = "-1";
switch(varName)
{
case "01234"
strResult = "Test1";
break;
case "03456"
strResult = "100"
break;
default
strResult = "-1"
break;
}
return strResult;
}

You would need to convert it to VB. Only problem is it's hard coded of
course so not very flexible.

I would also be wary of calling your structure 'Forms' - it's a bit
close to 'Form' and with VB's lack of case sensitivity a typo could
cause come interesting problems :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top