Home All Groups Group Topic Archive Search About

How can I display hashtable key values in a web page?

Author
25 Mar 2005 1:39 PM
Chuck Insight
Here is my first attempt at populating the hashtable.

dim t as hashtable = new hashtable()
dim k as integer = t.key
dim v as integer = t.value
v = 0
  for k = 1 to 200
    on error goto bottom
      if t.count = 50 then
        goto exit
      end if
    k = int(rnd * 50) +1
    v += 1
    t.add(k)
:bottom
  next k
Show quoteHide quote
:exit

Author
25 Mar 2005 2:42 PM
Jason Bentley
Chuck, looking at your code, I am not sure what you are trying to
accomplish but the Hashtable.Keys is an ICollection container. Then you
can loop through the collection and display the keys.

Jason Bentley
http://geekswithblogs.net/jbentley
Author
25 Mar 2005 10:37 PM
Chuck Bauer
Thank you very much for that information.

Next, would you please be more specific about exactly how to actually
accomplish displaying the values of the keys in the sequence they were
produced.

I tried <#= %> and <%= %> both throw an error.

Thanks for your continued assistance,
Chuck

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Author
28 Mar 2005 3:29 AM
Jason Bentley
Chuck, first, when you loop through the collection, the contents will
not necessarily be in the order they were created. Can you give a
thorough expanation of what you are doing? As far as displaying inline
code, <%= %> should work but can you post your full code now.

Jason Bentley
http://geekswithblogs.net/jbentley
Author
28 Mar 2005 11:58 AM
Chuck Insight
Thanks for the reply Jason.

To answer your question, I am trying to create a collection of 50 unique
random numbers.
Recording them as the key value assures this.
If the random number generated already exists, I direct it to :Bottom, which
simply requests another random number.
On the other hand, if the newly generated number is unique, I increment a
counter.
The counter number is the value half of the table.

I know hashtables don't provide output in a predefined sequence without
help.
So, my plan to display the key-value pair sequenced according the value.
This leads me to my initial question, which is "How can I display hashtable
key values in a web page?"

Thanks again,
Chuck


Show quoteHide quote
"Jason Bentley" <ims***@gmail.com> wrote in message
news:1111980583.433257.282270@f14g2000cwb.googlegroups.com...
> Chuck, first, when you loop through the collection, the contents will
> not necessarily be in the order they were created. Can you give a
> thorough expanation of what you are doing? As far as displaying inline
> code, <%= %> should work but can you post your full code now.
>
> Jason Bentley
> http://geekswithblogs.net/jbentley
>
Author
28 Mar 2005 1:55 PM
Jason Bentley
Chuck, this code will print out a list of integers from 200 to 1 from
the Hashtable.

Dim t As Hashtable = New Hashtable
For I As Integer = 1 To 200
     t.Add(I, I)
Next
Dim keyCollection As ICollection = t.Keys
Dim looper As IEnumerator = keyCollection.GetEnumerator()

Do While looper.MoveNext()
     Response.Write(Convert.ToString(looper.Current) & "<BR>")
Loop

Is this what you are looking for?

Jason Bentley
http://geekswithblogs.net/jbentley