Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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!

  • *Experts*
Posted

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")

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...