如何在 vb.net 中定义、动态初始化和打印 3D 数组?
我有这个返回 3d 数组的代码,我有错误告诉我有一个参数超出范围.. 当我寻找该行时,我发现没有错?
这是功能代码:
Private Function readFESTWERTEBLOCK(ByVal FESTWERTEBLOCKString As String ) _
As String (,,)
Dim allX As System.Text.RegularExpressions .Group
Dim allY As System.Text.RegularExpressions.Group
Dim allZ As System.Text.RegularExpressions.Group
Dim tempArray (,,) As String
Dim allXval As System.Text.RegularExpressions .MatchCollection
Dim allYval As System.Text.RegularExpressions.MatchCollection
Dim allZval As System.Text.RegularExpressions.MatchCollection
Dim oldUp ,midUp,newUp As Integer
Dim a,b,c
Dim myRegExpallX As New System.Text.RegularExpressions.Regex("WERT([\-\s\.0-9e]+)")
Dim myRegExpallY As New System.Text.RegularExpressions.Regex("WERT([\-\s\.0-9e]+)")
Dim myRegExpallZ As New System.Text.RegularExpressions.Regex("WERT([\-\s\.0-9e]+)")
Dim myRegExpallXval As New System.Text.RegularExpressions.Regex("[\w\-\.]+")
Dim myRegExpallYval As New System.Text.RegularExpressions.Regex("[\w\-\.]+")
Dim myRegExpallZval As New System.Text.RegularExpressions.Regex("[\w\-\.]+")
ReDim tempArray (0 To 2 ,0 To -1, 0 To -1 )
For a=0 To myRegExpallX.Matches(FESTWERTEBLOCKString).Count-1
If myRegExpallX.Matches(FESTWERTEBLOCKString).Item(a).Groups.Count>1 And myRegExpallY.Matches(FESTWERTEBLOCKString).item(a).Groups.Count>1 AndAlso myRegExpallZ.Matches(FESTWERTEBLOCKString).item(a).Groups.Count>1 Then
allX = myRegExpallX.Matches(FESTWERTEBLOCKString).Item(a).Groups.Item(1)
allXval= myRegExpallXval.Matches(allX.Value.ToString())
allY = myRegExpallY.Matches(FESTWERTEBLOCKString).Item(a).Groups.Item(1)
allYval= myRegExpallYval.Matches(allY.Value.ToString())
allZ = myRegExpallZ.Matches(FESTWERTEBLOCKString).Item(a).Groups.Item(1)
allZval= myRegExpallZval.Matches(allZ.Value.ToString())
oldUp= UBound(tempArray,3)
midUp= UBound(tempArray , 3) + allXval.Count
newUp=UBound(tempArray,3)+allXval.Count+allYval.Count
ReDim Preserve tempArray(0 To 2 ,0 To midUp ,0 To newUp)
For c=oldUp+2 To (allXval.Count+allYval.Count+oldUp)
For b= midUp+2 To allXval.Count+midUp
Dim tmpMatchX As System.Text.RegularExpressions.Match=allXval.Item(b-oldUp-2)
tempArray(0,b,c)=tmpMatchX.Value.ToString()
Dim tmpMatchY As System.Text.RegularExpressions.Match=allYval.Item(b-oldUp-2)
tempArray(1,b,c)=tmpMatchY.Value.ToString()
Dim tmpMatchZ As System.Text.RegularExpressions.Match=allZval.Item(b-oldUp-2)
tempArray(2,b,c)=tmpMatchZ.Value.ToString()
Next
Next
End If
Next
readFESTWERTEBLOCK = tempArray
End Function