Dim rootlist() As String
站在用戶的角度思考問題,與客戶深入溝通,找到銅陵網(wǎng)站設(shè)計(jì)與銅陵網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋銅陵地區(qū)。
Dim data(0, 0) As String
Dim tmp() As String
Dim listLengh As Int32
Dim I As Integer, II As Integer
rootlist = Split(IO.File.OpenText("C:/001.txt").ReadToEnd, vbCrLf)
listLengh = UBound(rootlist)
ReDim data(listLengh, 0)
For I = 0 To listLengh
tmp = Split(rootlist(I), ",")
ReDim Preserve data(listLengh, UBound(tmp))
For II = 0 To UBound(tmp)
data(I, II) = tmp(II)
Next
Next
For I = 0 To 2
For II = 0 To 2
MsgBox(data(I, II))
Next
Next
根據(jù)你的語句,上下標(biāo)是確定的,所以定義語句修改為:
Dim ary(UBound(temp), 1) As String '聲明二維數(shù)組
將二位數(shù)組轉(zhuǎn)成DataTable,網(wǎng)上找的不知道成不成
public static DataTable ConvertToDataTable(string[,] arr)
{
DataTable dataSouce = new DataTable();
for (int i = 0; i arr.GetLength(1); i++)
{
DataColumn newColumn = new DataColumn(i.ToString(), arr[0, 0].GetType());
dataSouce.Columns.Add(newColumn);
}
for (int i = 0; i arr.GetLength(0); i++)
{
DataRow newRow = dataSouce.NewRow();
for (int j = 0; j arr.GetLength(1); j++)
{
newRow[j.ToString()] = arr[i, j];
}
dataSouce.Rows.Add(newRow);
}
return dataSouce;
}
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)
for i =0 to ...
for j =0 to ...
keyarray(i,j)=
next
next
雙重循環(huán),賦值和讀取一樣