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

C

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
:exit
 
C

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
 
J

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
 
C

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
 
J

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
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top