views:

28

answers:

1

Hi, I am new to VB.net and facing a strange situation. I have a structure that contains another structure. The inner structure is nullable. Now wht I do is something like the following. I create a new instance of the inner structure, set the member variables and assign the whole structure to the inner structure of the parent. But it is giving an error. The assignment is not successful. If I try to peek into the structure in the watch window, it says "property evaluation failed" for the HasValue and Value properties.

 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)

Can somebody please guide me?

+3  A: 

Your first line is:

Dim testData As List(Of TestData) = Nothing

Then at the bottom you do

testData.Add(testData_List1)

I can't see anywhere in between where you do something like:

testData = New List(Of TestData)()

Though it's slightly hard to read since you've got both a variables and types with TestData as their name (or part of their name) so I might just be missing that.

ho1
This observation alone tells me the code he's posted is not complete. @Kangkan: It's very difficult to help you troubleshoot when you don't include a complete code example.
Dan Tao
Sorry for posting the incomplete code. I shall take care next time.
Kangkan
Now that I have corrected the issue, the Nullable property is not yet set. Can somebody look into it?
Kangkan
@Kangkan: I'm not sure if I understand, but I suggest that you update your question above with your current code but trim out some irrelevant lines to keep it easy to read. Difficult to be sure what's relevant sometimes but I'd suggest removing all the `.MeterActiveError = 20` and `.MeterApparentError = 14` etc lines and just have a comment `' setting various properties`.
ho1