dpflagg Posted July 12, 2003 Posted July 12, 2003 I have a data structure that is known at compile time, so I thought I would put it in a structure. However, it seems like I am late binding, but I have no intention to (I didn't even know what it was before I got an error, because the Compact Framework doesn't support it). Here is a snippet: Enum commandEnum ReadCommand WriteCommand OtherCommand End Enum Public Structure commandStruct Dim commandType As commandEnum Dim commandCode As String Dim numBytes As Integer Dim text As String Public Sub New(ByVal commandType As commandEnum, _ ByVal commandCode As String, _ ByVal numBytes As Integer, _ ByVal text As String) Me.commandType = commandType Me.commandCode = commandCode Me.numBytes = numBytes Me.text = text End Sub End Structure Public resetCommand = New commandStruct(commandEnum.OtherCommand, "0x01", 0, "Reset MPU") Now, when I try to access the data, like txtBox.Text = resetCommand.text, it says I'm late binding. How should I be doing this differently? Thanks! Quote
srinivasulu Posted July 13, 2003 Posted July 13, 2003 Hi Its late binding coz you havent given the type while declaring the object. try this Public resetCommand As commandStruct resetCommand = New commandStruct(commandEnum.OtherCommand, "0x01", 0, "Reset MPU") Then try to access the structure! Quote
dpflagg Posted July 14, 2003 Author Posted July 14, 2003 But this declares the structure twice, which is not allowed ... Quote
*Experts* Volte Posted July 14, 2003 *Experts* Posted July 14, 2003 No, you are declaring it once, and then setting that variable to a new instance. When you declare a structure or class without setting it to New, you are creating a null reference to a commandStruct, meaning that it points nowhere, and you can't use any non-static class members. Once you use New, it creates a new instance and assigns it to the reference variable, rendering it usable. 'This creates an empty (null) reference to a commandStruct Public resetCommand As commandStruct 'This creates an instance of a commandStruct and makes resetCommand reference it resetCommand = New commandStruct(commandEnum.OtherCommand, "0x01", 0, "Reset MPU") Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.