[英]Why won't my variable set to an instance of an object?
The program is a booking system (amongst other things) for a holiday letting company. 该程序是度假租赁公司的预订系统(除其他外)。 I am working on the screen where you can see properties and ammend them or add more (etc)
我正在屏幕上工作,您可以在其中查看属性并对其进行修改或添加更多(等)
Okay so It works fine in my other cases, but this one it just doesn't want to accept...I expect it's something stupid. 好的,所以在其他情况下也能正常工作,但是这只是不想接受...我希望这有点愚蠢。 Basically In the initial loading of the entire program I filled the Data Tables with the relevant info and then accessed them when needs be, in this case I am in the Form Properties and want to access Bookings (Which were made in FrmBookings) to see when the property is next booked to have guests in.
基本上,在整个程序的初始加载中,我用相关信息填充了数据表,然后在需要时访问它们,在这种情况下,我在表单属性中,想要访问预订(在FrmBookings中进行),以查看何时该酒店接下来被预订以接待客人。
Dim Intcounter As Integer = 0
Dim NumberBookingRecords As Integer = BookingsNumRecs
Dim PropertyName As String
Dim PropertyFromBookings As String
Do
PropertyName = DTProperties(Intcounter)("Property Name").ToString
PropertyFromBookings = (DTBookings(NumberBookingRecords)("Property").ToString)
If PropertyName = PropertyFromBookings Then
lblDateOfArrival.Text = (DTBookings(NumberBookingRecords)("Arrival").ToString)
Intcounter = Intcounter + 1
Else
If Not NumberBookingRecords = 0 Then
NumberBookingRecords = NumberBookingRecords - 1
Else
End If
End If
Loop Until Intcounter >= intNumPropertyRecs
However when I get to PropertyFromBookings = (DTBookings(NumberBookingRecords)("Property").ToString)
it tells me that it could not be set to an instance of an object...no matter what I try an access from DTBookings I get the same response. 但是,当我进入
PropertyFromBookings = (DTBookings(NumberBookingRecords)("Property").ToString)
它告诉我无法将其设置为对象的实例...无论我尝试从DTBookings访问什么,我都会得到同样的反应。
This is in the initial load form at the opening of the program 这是程序打开时的初始加载形式
Dim FSBookings As New FileStream(strFileNameBookings, FileMode.OpenOrCreate, FileAccess.Read)
Application.DoEvents()
If FileLen(strFileNameBookings) > 0 Then
DTBookings.ReadXmlSchema(strFileNameBookings)
DTBookings.ReadXml(strFileNameBookings)
BookingsNumRecs = DTBookings.Rows.Count
intCurrRec = 1
Else
End If
FSBookings.Close()
blnStopAuto = True
blnStopAuto = False
Based on your code sample, DTBookings()
is a function call. 根据您的代码示例,
DTBookings()
是一个函数调用。 There are two possibilties here. 这里有两个可能性。 Either:
要么:
Nothing
, and when you try to use a Nothing as if there were an actual object there, (in this case, when trying to look up the ("Property")
indexer) you'll get that exception, or ... Nothing
,并且当您尝试使用Nothing好像那里有一个实际对象时(在这种情况下,当您尝试查找("Property")
索引器时),您将得到该异常,要么 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.