for i =0 to ...
創(chuàng)新互聯(lián)公司是一家專業(yè)從事網(wǎng)站設(shè)計(jì)、網(wǎng)站制作的網(wǎng)絡(luò)公司。作為專業(yè)網(wǎng)站制作公司,創(chuàng)新互聯(lián)公司依托的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營(yíng)經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、成都全網(wǎng)營(yíng)銷及網(wǎng)站設(shè)計(jì)開(kāi)發(fā)服務(wù)!
for j =0 to ...
keyarray(i,j)=
next
next
雙重循環(huán),賦值和讀取一樣
窗體上添加3個(gè)標(biāo)簽,1個(gè)按鈕,在按鈕的單擊事件里寫代碼,如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a(,) As Integer = {{5, 6}, {1, 3}, {8, 9}, {72, 1}, {63, 4}}
Dim Temp As Integer
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim y As Integer
'顯示排序前的數(shù)據(jù)
Label1.Text = "排序前數(shù)據(jù):" vbCrLf
For i = 0 To 4
Label1.Text = Label1.Text a(i, 0) " " a(i, 1) vbCrLf
Next
For i = 0 To 3
For j = i + 1 To 4
If a(i, 0) a(j, 0) Then
Temp = a(i, 0)
a(i, 0) = a(j, 0)
a(j, 0) = Temp
Temp = a(i, 1)
a(i, 1) = a(j, 1)
a(j, 1) = Temp
End If
Next
Next
'顯示排序前的數(shù)據(jù)
Label2.Text = "排序后數(shù)據(jù):" vbCrLf
For i = 0 To 4
Label2.Text = Label2.Text a(i, 0) " " a(i, 1) vbCrLf
Next
'把第3行元素賦予X,Y
x = a(2, 0)
y = a(2, 1)
'輸出X,Y
Label3.Text = "X=" x vbCrLf "Y=" y
End Sub
OPCItemIDsData(j,其中一維)即可。
如果前面方法有規(guī)定,不能用二維數(shù)組的格式,那么你可以自己定義一個(gè)一維數(shù)組,將二維數(shù)組的某一維度的全部數(shù)值賦值給這個(gè)數(shù)組,在引用這個(gè)數(shù)組:
dim OPCItemIDsDataBuf(x) as ...
for i = 1 to x
OPCItemIDsDataBuf(j)=OPCItemIDsData(j,其中一維)
next i
其中x是數(shù)組的最大下標(biāo)
根據(jù)你的語(yǔ)句,上下標(biāo)是確定的,所以定義語(yǔ)句修改為:
Dim ary(UBound(temp), 1) As String '聲明二維數(shù)組