开发者

How to store simple contour lines in a Visual basic Array?

HI How can store simple contour lines in a visual basic array?

Example: if there is a 5 x 5 array, the edge = 100 and Centre of array = 110. Then:

100 100 100 100 100

100 105 105 105 100

100 105 110 105 100

100 105 105 105 100

100 100 100 100 100

The outer ring = 100, 1 step inner ring = 105 then center =110.

Is there a generic routine of doing开发者_开发知识库 this? What will happen if the array is for even numbers (say 6 x 6)? 6 x 6 does not have the center and in odd numbers.

Thanks!


Here some code to create the array:

Dim a(1 To 5, 1 To 5) As Integer

Private Sub SetRing(lvl As Long, dimSize As Long, value As Long)
    Call SetHValues(lvl, dimSize, value)
    Call SetVValues(lvl, dimSize, value)
End Sub

Private Sub SetHValues(lvl As Long, dimSize As Long, value As Long)
    Dim i As Long, k As Long

    If lvl > (dimSize / 2) + 1 Then Exit Sub

    For i = lvl To dimSize - lvl + 1
        ' horizontal values'
        a(lvl, i) = value
        a(dimSize - lvl + 1, i) = value
    Next
End Sub

Private Sub SetVValues(lvl As Long, dimSize As Long, value As Long)
    Dim i As Long, k As Long

    If lvl > (dimSize / 2) + 1 Then Exit Sub

    For i = lvl To dimSize - lvl + 1
        ' vertical values'
        a(i, lvl) = value
        a(i, dimSize - lvl + 1) = value
    Next
End Sub

And to create the sample array you would call:

Call SetRing(1, 5, 100)
Call SetRing(2, 5, 105)
Call SetRing(3, 5, 110)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜