int A[12];
位置为:
A[0] A[1] A[2]
A[3] A[4] A[5]
A[6] A[7] A[8]
A[9] A[10] A[11]
我想将0~11分别赋给数组中,赋值方式为
A[0]=0 A[1]=1 A[2]=2
A[3]=5 A[4]=4 A[5]=3
A[6]=6 A[7]=7 A[8]=8
A[9]=10 A[10]=10 A[11]=9请教一下如何实现呀?
着急,烦请达人给个解
位置为:
A[0] A[1] A[2]
A[3] A[4] A[5]
A[6] A[7] A[8]
A[9] A[10] A[11]
我想将0~11分别赋给数组中,赋值方式为
A[0]=0 A[1]=1 A[2]=2
A[3]=5 A[4]=4 A[5]=3
A[6]=6 A[7]=7 A[8]=8
A[9]=10 A[10]=10 A[11]=9请教一下如何实现呀?
着急,烦请达人给个解
dim a(12)
A[0]=0 : A[1]=1 : A[2]=2
A[3]=5 : A[4]=4 : A[5]=3
A[6]=6 : A[7]=7 : A[8]=8
A[9]=10 : A[10]=10 : A[11]=9
Private Sub Command1_Click()
a = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
Me.Cls
For i = 0 To UBound(a)
Print a(i)
Next i
End Sub
a=Array(0,1,2,5,4,3,6,7,8,10,10,9)
Private Sub Command1_Click()
For i = 0 To 11
TmpStr(i) = i
Next i
Me.Cls
For i = 0 To UBound(TmpStr)
Select Case i
Case 3
a(i) = TmpStr(5)
Case 5
a(i) = TmpStr(3)
Case 9
a(i) = TmpStr(11)
Case 11
a(i) = TmpStr(9)
Case Else
a(i) = TmpStr(i)
End Select
Print a(i)
Next i
End Sub
dim A[3,4]这样呢?
应该会方便些吧?
Dim a(11) As Integer
swtch = -1
For i = 0 To 3
swtch = -swtch
For j = 0 To 2
If swtch = 1 Then
a(i * 3 + j) = i * 3 + j
Else
a(i * 3 + j) = i * 3 + 2 - j
End If
Next j
Print
Next i
Sub GetArray(a() As Long, n As Long)
Dim i As Long
Dim b As Boolean
Dim k As Long
For i = 1 To UBound(a) + 1
a(i - 1) = k
If i Mod n = 0 Then
k = k + n
b = Not b
If b Then k = k + 1
If Not b Then k = k - 1
End If
If b Then k = k - 1
If Not b Then k = k + 1
Next
End SubPrivate Sub Command1_Click()
Dim a(12) As Long
GetArray a, 3
Dim i As Long
For i = 0 To ubound(a)
Debug.Print i; a(i)
Next
End Sub
Debug.Print "=============================================="
For i = 0 To 11
Debug.Print "a(" + Str(i) + "):" + Str((((i + (((i \ 3) Mod 2)) * (2 - (i Mod 3) * 2)))))
Next
End Sub
我的那个下班路上想想,优化一下:
Sub GetArray(a() As Long, n As Long)
Dim i As Long
Dim v As Long, k As Long
v = 1
For i = 1 To UBound(a) + 1
a(i - 1) = k
If i Mod n = 0 Then
k = k + n + v
v = -1 * v
End If
k = k + v
Next
End SubPrivate Sub Command1_Click()
Dim a(11) As Long
GetArray a, 3
Dim i As Long
For i = 0 To UBound(a)
Debug.Print "a(" & i & ")="; a(i)
Next
End Sub