VB.NET puzzle

  • Thread starter Thread starter bill salkin
  • Start date Start date
B

bill salkin

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]
 
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
 
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]
 
I agree, the logic behind this is far from clear. I think Bill, needs to
tell us specifically what the objective of his code is rather than talking
about how to jury rig a solution for this dubious looking requirement. ( No
offense Bill, I just tell it like I see it ! ).

Regards - OHM
 
Ken Tucker said:
Hi,


Hashtables allow you store data based on a key. Would that work
for you?

Dim htData As New Hashtable

htData.Add("Cat", 3)

htData.Add("Dog", 4)

Debug.WriteLine(htData("Cat").ToString)
http://msdn.microsoft.com/library/d...frlrfsystemcollectionshashtableclasstopic.asp

This sounds helpful...(I'm not the OP)...

I want to provide a single property on a user control that contains a number
of named images. A hashtable sounds perfect to hold this data.
Unfortunately, when define a property as a hashtable it only adds
"systemobject" type objects.

How can I have it add images? Do I need to specify some kind of default so
that when a user opens the collection in the IDE that it already knows that
this should be adding images?

I know I'm going at this the wrong way, but I just can't nail it down. Any
kind of advice is appreciated!

My current code for the property:
dim iHash as Hashtable
...
Public Property IMA() As Hashtable
Get
Return iHash
End Get
Set(ByVal Value As Hashtable)
iHash = Value
End Set
End Property
 
Hi OHM,

I thought this was typical for you or the ones who like it.

I thought you did give it almost as example yesterday do you know, "ByRef"
(was just for fun, normaly that does not interest me at all, 4 bytes)

I think the answer is a collection of objects from which each object has a
"name" (CAT or DOG etc) and an index and an Item(1, 3)

Cor
 
Hello All,

The actual application I'm working on is database driven,
with the field names being Lender specific. The field
names, as well as associated data (from a weekly import),
are stored in a Sql table.

As new Lenders are supported by the app, we update the
field names and LenderID in the Sql table. Typically,
each Lender uses about 30 fields related to
customer/property/loan info.

For example, let's suppose Lender1 uses the
field "BorrowerName". In my VB code I refer to this field
as "strBorrowerName" (naming conventions, please) and
assign it a value based upon the data in a weekly import
file. A typical code example would be

strBorrowerName = "Bill"

The "str" part is the VB naming convention;
the "BorrowerName" field name comes from our Sql table;
the "Bill" part is initially gotten at run time when we
import the file.

This is the actual problem I'm trying to address.


TIA,

Bill

P.S. Yes, I could

a) rename the field in the database table
to "strBorrowerName" (I won't do that - VB naming
conventions in a Sql table? Forget it.)

or

b)change my VB code naming conventions. Possible, but then
the company naming standard is ignored.

I was hoping there was a relatively easy way to do what I
needed programatically but I don't see it.
 
OK, well if I understand your correctly. I make the following assumptions

1.) You are getting data from your database. Presumably into a DataTable
probably inside a DataSet yes ?
2.) The Lenders Field contains a list of Lender Names ( Must be unique )
3.) For some reason, for each Lender Name you wish to create a string based
on the following.
str + :LenderName and assign it a value from another field ?, this is
presumably the Primary Key ?
4.) It sounds like you are trying to make a lookup table to give you the PK
of the Lender ?


If these assumptions are correct, then you can create a DataView of the
DataTable and
use the RowFilter or Find Methods.

If you are getting the DataIn some other way directly into an array. Why not
use Kens
suggestion to use a HashTable. ( Slightly modified to demonstrate )

Dim htData As New Hashtable

Dim inp() As String = {"Cat"}

htData.Add("str" & inp(0), 3)

MsgBox(htData("strCat")) ' Displays Three

Regards - OHM
 
Back
Top