Home > Software engineering >  VB code using a one-dimensional array how to write
VB code using a one-dimensional array how to write

Time:11-15



How great god VB code using a one-dimensional array to write? ! Genuflect is begged! thank you

CodePudding user response:

Can write like this:
 
Dim arr (1 to 25) as an integer
A (1)=1
'...
A (25)=9

CodePudding user response:

The magic of love turned around
 
Option Explicit
Dim aryOut (0 To 24) As Byte 'one dimensional array
Private Sub Command1_Click ()

Dim intDirect As Integer 'right direction 0 1 2 in the left 3
Dim x As an Integer, y As Integer 'current filling location coordinates in the matrix
Dim As Integer I
For I=1 To 25 'number 25 each fill in the one dimensional array, the current position from matrix coordinates (0, 0) direction starting from 0 r
AryOut (GetAryPos (x, y)) numerical fill in
=I 'GetNext x, y, intDirect
Next
'to produce output string
Dim strout As String
For I=LBound (aryOut) To UBound (aryOut)
Strout=strout & amp; The Format (aryOut (I), "00") & amp; "
"If (I + 1) Mod 5=0 Then strout=strout & amp; VbCrLf
Next
'print
The Debug. Print strout

End Sub
'coordinates according to the matrix, obtain in the array subscript
Private Function GetAryPos (ByVal x As an Integer, ByVal y As an Integer) As an Integer
GetAryPos=5 * y + x
End the Function
'edge detection based on matrix coordinate, direction, get the next coordinates, and see if the data on the coordinates have values (touching the edge of the)
Private Sub getNext (ByRef x As an Integer, ByRef y As an Integer, ByRef direct As an Integer, Optional turntimes As Integer=0)
Dim TMPX As an Integer, tmpy As Integer
Dim Turnflag As Boolean 'whether to sign
If turntimes & gt; 4 Then Exit Sub
'along the direction of the input before further, get coordinates
TMPX=x: tmpy=y
The Select Case direct
Case 0
TMPX=x + 1
Case 1
Tmpy=y + 1
Case 2
TMPX=x - 1
Case 3
Tmpy=y - 1
End the Select

If TMPX & gt; 4 the Or TMPX & lt; 0 Or tmpy & gt; 4 the Or tmpy & lt; 0 Then
'if beyond the scope of matrix, the edge is detected, the need to turn clockwise
Turnflag=True
The Else
'not beyond the scope of matrix, the matrix have been detected to fill a value, need to turn clockwise, otherwise don't need
Turnflag=IIf (aryOut (GetAryPos (TMPX tmpy)) & gt; 0, True, False)
End the If
If Turnflag Then
'if you need to, then the direction change
Direct=(+ 1) direct Mod 4
'and then try to get to the next step after
GetNext x, y, direct, turntimes + 1
The Else
'don't need to, return have a step the coordinates of the
X=TMPX: y=tmpy
End the If

End Sub



  • Related