Hi guys,
I have a question here confused me for a long time.
say, if I declare and instantiate a hashtable in Class1, and I wanna use it in Class 2. what should I do? I understand that in Class2 I need to declare the hashtable and get the hashtabel instantiated in Class1. But how can I do it?
following is part of my code.
Class1:
Class2:
In Class2, I wanna use a Console.WriteLine method to output hence test the items in the hashtable. I Dim ht As Hashtable, but how can I use the items stored in ht in Class1?
Thanks very much for any help!
I have a question here confused me for a long time.
say, if I declare and instantiate a hashtable in Class1, and I wanna use it in Class 2. what should I do? I understand that in Class2 I need to declare the hashtable and get the hashtabel instantiated in Class1. But how can I do it?
following is part of my code.
Class1:
VB.NET:
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.Collections
Public Class ButtonTable
Inherits System.Collections.CollectionBase
Private ReadOnly HostForm As System.Windows.Forms.Form
Dim Z1 As String
Dim Z2 As String
Public ht As Hashtable
Public aButton As New System.Windows.Forms.Button()
Public Sub AddNewButton()
' Create a new instance of the Button class.
Dim i As Integer
Dim oXLApp As Excel.Application 'Declare the object variables
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
oXLApp = New Excel.Application 'Create a new instance of Excel
oXLBook = oXLApp.Workbooks.Open("C:\Documents and Settings\intern\My Documents\yoyoyo.xls")
'Open an existing workbook
oXLSheet = oXLBook.Worksheets(1) 'Work with the first worksheet
For i = 1 To 100
Z1 = oXLSheet.Cells.Item(i, 5).Value
Z2 = oXLSheet.Cells.Item(i, 6).Value
Dim aButton As New System.Windows.Forms.Button()
' Set intial properties for the button object.
aButton.Text = Z1
aButton.Name = Z2
Dim ht As New Hashtable()
ht.Add(aButton.Name, aButton)
Next i
oXLApp.Visible = False 'Don't show it to the user
oXLBook.Save()
' Ensure that the save command is fully completed
Do While Not oXLBook.Saved
Application.DoEvents()
Loop
' Then close the Workbook
oXLBook.Close()
End Sub
End Class
Class2:
VB.NET:
Imports Microsoft.Office.Interop
Imports System.Collections
Public Class ButtonShow
Inherits System.Windows.Forms.Form
Dim datafrm As Form2
' Declare a new ButtonTable object.
Dim MyControlTable As ButtonTable
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ht As Hashtable
Dim Item As DictionaryEntry
For Each Item In ht
Console.WriteLine(Item.Key)
Next Item
End Sub
End Class
In Class2, I wanna use a Console.WriteLine method to output hence test the items in the hashtable. I Dim ht As Hashtable, but how can I use the items stored in ht in Class1?

Thanks very much for any help!