Q: control reference in hashtable, how to get control.text?

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

confused_newbie

I have a variety of comboboxes on a form. I created a hashtable where the
key is the combobox number ("01", "02", "03"..."12") and the value is the
corresponding combobox (cmb01, cmb02, etc)

now I want to allow the user to click a button (cmbSubmit) and have the
program cycle through the comboboxes, grab the text of each, and appended it
to a text file. I've figured out the appending part, but I can't figure out
how to get the text for each box. For example:
=====================
Dim myEnumerator as IDictionaryEnumerator = myHT2.getEnumerator
Dim tempControl as ComboBox

While myEnumerator.MoveNext
tempControl = myEnumerator.value '<-- option strict on disallows
conversion from system.object to system.windows.forms.combobox
MyTextString = MyTextString & ", " & tempControl.text
Next
'then I append the line to my text file
=====================
My alternative is to use:
-------------------------------
for each tempControl in me.controls
MyTextString = MyTextString & ", " & tempControl.text
Next
-------------------------------
but with the first solution, I can add some code that will make sure the
text is collected from the comboboxes in order (rather than the default
order in the hashtable). In this second solution, I don't think (?) I have
any control over the order, although I'd presume that it would grab the
comboboxes/text in the same order each time?

Any help or suggestions appreciated!!
Keith
 
Have you tried shortening to:

Dim cbox As New ComboBox

For Each cbox In myHT2.Values

' Use cbox.Text here

Next
 
That sounds great to access the objects, and I've learned something new
today :-)
but what I really want is control over the order in which the text is
appended to my resulting text file.
The HT keys and values are added "randomly" (not in an order I select)
based on a "for each text file in directory" logic, so the actual order
might be 12,04,11,10,01,02,03,05 etc.
When I grab the cbox.text from each combobox, I want to append the text to
my resulting string in numeric order:
01,02,03,04...012

I can potentially do this by cycling through the HT multiple times
(hardcoded) by looking for key 01, then key 02, etc- or I could grab the
key along with each cbox, and create a new HT with the same key but the
text value of the cbox, then cycle through the new HT to put them all in
order ....not sure of the syntax, but something like:
---------------------------------------
Dim cbox as new combobox
Dim tempitem as string

For Each cbox in myHT2.values
myHT3.add = (myHT2.key, cbox.text)
Next

For i = 1 to 12
tempitem =text(i,"00") 'not at my PC at the moment so I can't look up
the syntax, this is from old VBA syntax
tempstring = MyHT3.key(tempitem).value 'I know this is totally wrong
syntax, but again, no helpfile in front of me
finalstring= finalstring & ", " & tempstring
Next
------------------------------------

....not very eloquent programming.... can anyone think of an easier way for
me to get the text of each combobox "in order" regardless of the order they
were appended to myHT2?

Many thanks!
keith
 
Back
Top