Still having trouble: new to hashtable syntax

  • Thread starter Thread starter confused_newbie
  • Start date Start date
C

confused_newbie

I believe that I have successfully added my keys and objects (comboboxes) to
my hashtable. I adjusted my previous code to make sure that each
object/combobox was only present once in my hashtable, so I should have a
1:1 relationship (vs 1-to-many, which I had before).

The keys are not in any order going into the hashtable, which I presume is
FIFO. They are appended based on whatever random order the program opens my
text files during startup.

I need to consistently get the _text_ of the comboboxes out in a specific
order, based on the keys ("00a", "00b", "00c", "01", "02","03",..."12"), as
I need to append the text in that order to an output text file on
cmbSubmit_Click

Option 1: gives me the .text properties of each combobox, but I can't figure
out how to also return the key for the selected object so I can use that to
order my text snippets:

Dim CmbTemp as combobox
For each CmbTemp in myHT.values
'use CmbTemp.text here
tempKey = myHT.keys 'is the whole key list?- how do I limit it to just
the key of the currently selected HT value?
Next

Option 2: I could try to go through each key, and then pull each Combobox,
something like the code below, but it is very worky and I'm sure there is a
simpler way to get this data, not that either of these are working anyway.

Dim TempKey as String
Dim CmbTemp as combobox

For each TempKey in myHT.keys
CmbTemp = myHT(TempKey) 'not allowed because expression is
'system.object', not a collection type
Next

'or

For each CmbTemp in myHT(TempKey) 'not allowed because expression is
'system.object', not a collection type
Next

Next

With the idea that if I could navigate through these one at a time, I could
build a new hashtable with all strings (e.g. it would use the same keys, but
I would have the combobox.text as the value instead of the combobox itself)
such as:
myHT myHT2 (the new one)
"00a" cmb00a "00a" "Apple"
"00b" cmb00b "00b" "Green"
"00c" cmb00c "00c" "Tree"
"01" cmb01 "01" "Car"
"02" (etc)

then, even though they are out of order, at least I could grab the values
and put them in the order I need...

any syntax help appreciated greatly!
Keith
 
Why do you need to use a Hashtable? Would it be easier to accomplish your
task with a simple ArrayList? That way you'll be able to iterate through the
items in the order you add them in.
 
Back
Top