2010-07-09 67 views
0

我是VB.net的新手,面臨一種奇怪的情況。我有一個包含另一個結構的結構。內部結構是可空的。現在我要做的就像下面這樣。我創建了一個新的內部結構實例,設置了成員變量並將整個結構分配給父級的內部結構。但它給出了一個錯誤。分配不成功。如果我試圖窺視觀察窗口中的結構,則說明「property evaluation failed」爲HasValueValue屬性。在vb.net中分配可空類型對象的錯誤

Dim testData As List(Of TestData) = Nothing 

    Dim testData_List1 As New TestData 
     With testData_List1.commonTestParam 
      .AccuchekActiveEnergy = 2.56 
      .AccuchekActiveEnergyUnit = ActiveEnergyUnit.KiloWattHour 
      .AccuchekApparentEnergy = 34.56 
      .AccuchekApparentEnergyUnit = ApparentEnergyUnit.VoltAmpereHour 
      .AccuchekFrequency = 1 
      .AccuchekRange = "20474 ewr 34324" 
      .AccuchekType = AccuchekType.AccuchekOne 
      .ActiveLoadRPhase = 145 
      .AvgActiveLoad = 2.56 
      .AvgActiveLoadUnit = ActiveLoadUnit.Watt 
      .AvgPowerFactor = 0 
      .AvgPowerFactorType = PowerFactorType.PFLag 
      .ConditionalFlag1 = 0 
      .ConsumerNo = "343122050242" 
      .CurrentRPhase = 1 
      .GeneralFlag1 = 0 
      .InstantaneousPFRPhase = 2 
      .ManufacturingYear = 2009 
      .MeterActiveEnergy = 258.89 
      .MeterActiveEnergyUnit = ActiveEnergyUnit.KiloWattHour 
      .MeterActiveError = 20 
      .MeterApparentError = 14 
      .MeterConstant = 3200 
      .MeterConstantUnit = MeterConstantUnit.RevsPerkVAh 
      .MeterMake = "DS" 
      .MeterSNo = "6563402" 
      .MeterTypeAndClass = MeterTypeAndClass.MTCElectorMechWith20 
      .MTFID = "123456789" 
      .NoofTestRevolutions = 100 
      .PulseCriteria = 0 
      .RatedBasic = 25 
      .RatedMax = 30 
      .RatedVoltage = 15 
      .ReactiveCurrentRPhase = 145 
      .RemarkID = 0 
      .TestDateAndTime = "100320101545" 
      .TestDuration = 2145 
      .TesterCode = 0 
      .TestID = "147852" 
      .TestMode = TestMode.TMOpticalScanner 
      .TestNumber = 0 
      .VoltageRPhase = 145 
     End With 

     Dim accuchek3TestParameters1 As New Accuchek3PhaseTestParameters 

     With accuchek3TestParameters1 
      .AccuchekReactiveLagEnergy = 2.46 
      .AccuchekReactiveLagEnergyUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour 
      .AccuchekReactiveLeadEnergy = 2.56 
      .AccuchekReactiveLeadEnergyUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour 
      .ActiveLoadBPhase = 14 
      .ActiveLoadYPhase = 15 
      .AvgApparentLoad = 10 
      .AvgApparentLoadUnit = ApparentLoadUnit.KiloVoltAmpere 
      .AvgReactiveLagLoad = 14 
      .AvgReactiveLagLoadUnit = ReactiveLoadUnit.KiloVoltAmpereReactive 
      .AvgReactiveLeadLoad = 15 
      .AvgReactiveLeadLoadUnit = ReactiveLoadUnit.KiloVoltAmpereReactive 
      .ConditionalFlag2 = 0 
      .ConditionalFlag3 = 0 
      .CTRatio = 1.23 
      .CurrentBPhase = 10 
      .CurrentYPhase = 11 
      .InstantaneousPFBPhase = 0 
      .InstantaneousPFYPhase = 1 
      .MeterApparentEnergy = 1.01 
      .MeterApparentUnit = ApparentEnergyUnit.KiloVoltAmpereHour 
      .MeterReactiveLagEnergy = 1.25 
      .MeterReactiveLagError = 1.25 
      .MeterReactiveLagUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour 
      .MeterReactiveLeadEnergy = 1.45 
      .MeterReactiveLeadError = 1.56 
      .MeterReactiveLeadUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour 
      .PercentageLoad = 1 
      .PTRatio = 1 
      .ReactiveCurrentBPhase = 10 
      .ReactiveCurrentYPhase = 11 
      .VoltageBPhase = 10 
      .VoltageYPhase = 10 
     End With 

     testData_List1.accuchek3TestParameters = accuchek3TestParameters1 

     testData.Add(testData_List1) 

有人能指導我嗎?

回答

3

你的第一行是:

Dim testData As List(Of TestData) = Nothing 

然後在底部你做

testData.Add(testData_List1) 

我看不到任何地方之間,你做這樣的事情:

testData = New List(Of TestData)() 

雖然它有點難以閱讀,因爲你已經有了一個變量和類型,TestData作爲他們的名字(或者他們的一部分) ame),所以我可能會錯過。

+0

這個觀察獨自告訴我他發佈的代碼不完整。 @Kangkan:當您不包含完整的代碼示例時,要幫助您排除故障非常困難。 – 2010-07-09 11:01:20

+0

對不起,發佈不完整的代碼。下次我會照顧的。 – Kangkan 2010-07-09 11:22:00

+0

現在我已經糾正了問題,Nullable屬性尚未設置。有人可以看看它嗎? – Kangkan 2010-07-09 11:30:11

相關問題