Embedded Hashtables

  • Thread starter Thread starter Curtis
  • Start date Start date
C

Curtis

Does anyone know the proper method to save information to embedded
hashtables.

I am trying to save parent/child information to hashtables but I am not
getting the correct results I have made a very simplified example of
problem with the following code:

Dim cust As New Hashtable
Dim invoice As New Hashtable
Dim invoiceLines As New Hashtable
invoiceLines.Add(1, "500")
invoiceLines.Add(2, "1000")
invoice.Add("Inv123", invoiceLines)
cust.Add("ABC", invoice)
invoiceLines.Clear()
invoice.Clear()
invoiceLines.Add(1, "123")
invoiceLines.Add(2, "10")
invoice.Add("Inv222", invoiceLines)
cust.Add("BBB", invoice)

Is there a way to correctly save this information so that it doesn't delete
the values of the first hashtables that I want saved into the cust hashtable
when I do a clear?

Thanks,
Curtis
 
I solved my problem by using the .clone method of the hashtables like so:

Dim cust As New Hashtable
Dim invoice As New Hashtable
Dim invoiceLines As New Hashtable
invoiceLines.Add(1, "500")
invoiceLines.Add(2, "1000")
invoice.Add("Inv123", invoiceLines.Clone)
cust.Add("ABC", invoice.Clone)
invoiceLines.Clear()
invoice.Clear()
invoiceLines.Add(1, "123")
invoiceLines.Add(2, "10")
invoice.Add("Inv222", invoiceLines.Clone)
cust.Add("BBB", invoice.Clone)

Curtis
 

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

Back
Top