実行時バインディングでこの問題が発生します。食料品リストアプリケーションを作成しています。食料品リストのアイテムの、、、、およびを格納Itemするという名前のクラスがあります。namepricequantitydescription
ListCollectionオブジェクトのを定義するという名前のモジュールがCollectionありItemます。Edit現在選択されているアイテムのプロパティを自動的に表示するフォームを作成しましたListCollectionが、テキストボックスに入力しようとするとOption Strict、遅延バインディングが許可されないというメッセージが表示されます。
私は簡単なルートをとって無効Option Strictにすることができますが、問題が何であるかを理解したいので、将来の参考のために知っています。
ここに適切なコードを貼り付けます。(遅延バインディングエラーはにありEditItem.vbます。)
Item.vbコード:
' Member variables:
Private strName As String
' Constructor
Public Sub New()
strName = ""
' Name property procedure
Public Property Name() As String
Get
Return strName
End Get
Set(ByVal value As String)
strName = value
End Set
End Property
ListCollection.vbコード:
' Create public variables.
Public g_selectedItem As Integer ' Stores the currently selected collection item.
' Create a collection to hold the information for each entry.
Public listCollection As New Collection
' Create a function to simplify adding an item to the collection.
Public Sub AddName(ByVal name As Item)
Try
listCollection.Add(name, name.Name)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
EditItem.vbコード:
Private Sub EditItem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Set the fields to the values of the currently selected ListCollection item.
txtName.Text = ListCollection.listCollection(g_selectedItem).Name.Get ' THIS LINE HAS THE ERROR!
String変数を宣言してそれにプロパティを割り当てようとしました。また、アイテムItemから直接値を取得しようとしましたが(関数を使用せずに)、どちらも違いはありませんでした。 ListGet
この問題を解決するにはどうすればよいですか?