dpflagg
07-18-2003, 07:46 PM
I have a structure type defined in a class, and I want to retrieve an instance of that structure outside the class. How do I declare an object and use an object of that type, or retrieve an element of the structure. Here's what I have:
Public Class myClass
Public Structure commandStruct
Dim commandCode As String
Dim text As String
Public Sub New(ByVal commandCode As String, ByVal text As String)
Me.commandCode = commandCode
Me.text = text
End Sub
End Structure
Dim commandHT As HashTable
Public resetCommand As New commandStruct("0x01","Reset")
Public Sub New()
commandHT.Add(resetCommand.text,resetCommand)
End Sub
End Class
Now, I want to retrieve the command code based on a combo box on my form:
Public Class myForm
device = New myClass
Public Sub SomeFunctionInForm()
cmdCode = (device.commandHT.Item(comboBox1.Text)).commandCode
End Sub
End Class
The line:
cmdCode = (device.commandHT.Item(comboBox1.Text)).commandCode
is functionally what I want, but it doesn't work. I.e., I want to retrieve the commandCode element of the commandStruct structure, as keyed into using the text of the combobox.
I also tried:
Dim command As commandStruct = device.commandHT.Item(...)
but the form class doesn't know about the commandStruct class.
Any suggestions on how I can do this?
Thanks.
Public Class myClass
Public Structure commandStruct
Dim commandCode As String
Dim text As String
Public Sub New(ByVal commandCode As String, ByVal text As String)
Me.commandCode = commandCode
Me.text = text
End Sub
End Structure
Dim commandHT As HashTable
Public resetCommand As New commandStruct("0x01","Reset")
Public Sub New()
commandHT.Add(resetCommand.text,resetCommand)
End Sub
End Class
Now, I want to retrieve the command code based on a combo box on my form:
Public Class myForm
device = New myClass
Public Sub SomeFunctionInForm()
cmdCode = (device.commandHT.Item(comboBox1.Text)).commandCode
End Sub
End Class
The line:
cmdCode = (device.commandHT.Item(comboBox1.Text)).commandCode
is functionally what I want, but it doesn't work. I.e., I want to retrieve the commandCode element of the commandStruct structure, as keyed into using the text of the combobox.
I also tried:
Dim command As commandStruct = device.commandHT.Item(...)
but the form class doesn't know about the commandStruct class.
Any suggestions on how I can do this?
Thanks.