菜鸟求教关于结构数组的问题
最近开始尝试使用结构进行编程,结果遇到以下问题,还请大神们赐教。
代码:
结构定义
Public Structure Loadset
Public load As Single
Public peried As String
Public P3 As Single
Public V2 As Single
Public Cor As Single
Public Pwboil As Single
Public TExout As Single
End Structure
定义结构体数组
Public LoadArray As New ArrayList
定义临时结构实例
Dim tempLoad As Loadset
给结构体数组赋值
For i As Integer = 0 To NumLoad - 1
NoData = 0
For Each a In GroupBox1.Controls
If TypeOf (a) Is TextBox Then
If a.Name = "Load" & i Then
If a.text = "" Then
NoData = 1
Exit For
Else
tempLoad.load = Val(a.Text)
End If
End If
If a.Name = "Peried" & i Then tempLoad.peried = a.Text
If a.Name = "P3" & i Then tempLoad.P3 = Val(a.Text)
If a.Name = "V2" & i Then tempLoad.V2 = Val(a.Text)
If a.Name = "COR" & i Then tempLoad.Cor = Val(a.Text)
If a.Name = "Pwboil" & i Then tempLoad.Pwboil = Val(a.Text)
End If
Next
If NoData = 0 Then
LoadArray.Add(tempLoad)
End If
Next
在使用时,需要给某一结构体赋值时出错。
LoadArray(0).texout = Val(TextBox13.Text)
以下是出错信息:
Late-bound assignment to a field of value type 'Loadset' is not valid when 'Loadset' is the result of a late-bound expression.
看各位大神能否出招帮我解决一下,谢谢!
------解决方案--------------------
Dim tempLoad As Loadset
tempLoad = CType(LoadArray(0), Loadset)
tempLoad.texout = Val(TextBox13.Text)
建议你用泛型List
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
[解决办法]
Dim tempLoad As New Loadset