如何计算VB6中的数组
答
在一个文件中读取,并在数组中,你可以做如下:
'1 form with
' 1 command button: name=Command1
Option Explicit
Private Sub Command1_Click()
Dim lngLine As Long
Dim intFile As Integer
Dim strFile As String
Dim strData As String
Dim strLine() As String
'select file
strFile = "c:\temp\file.txt"
'read file
intFile = FreeFile
Open strFile For Input As #intFile
strData = Input(LOF(intFile), #intFile)
Close #intFile
'put into array
strLine = Split(strData, vbCrLf)
'loop through complete array and print each element
For lngLine = 0 To UBound(strLine)
Print strLine(lngLine)
Next lngLine
End Sub
这将读取文件中的,把它变成一个数组(有自己的元素每一行),然后循环通过整个阵列打印每行/元件的形式上
[编辑]
下面是示例了如何从另一阵列的相应项。减去从一个数组项:
Private Sub Command1_Click()
Dim lngIndex As Long
Dim lngA(7) As Long
Dim lngB(7) As Long
'fill the arrays
For lngIndex = 0 To UBound(lngA)
lngA(lngIndex) = lngIndex + 1
Next lngIndex
For lngIndex = 0 To UBound(lngA)
lngB(lngIndex) = (lngIndex + 1)^2
Next lngIndex
'substract array a from array b
For lngIndex = 0 To UBound(lngB)
lngB(lngIndex) = lngB(lngIndex) - lngA(lngIndex)
Next lngIndex
'print arrays
For lngIndex = 0 To UBound(lngA)
Print CStr(lngA(lngIndex)) & " | " & CStr(lngB(lngIndex))
Next lngIndex
End Sub
有多大? “计算数组”是什么意思?你的意思是你想读入文件并将每行放在数组的单独元素中? – Hrqls
阵列中的1400个数据很大。我问是否有可能获得阵列与阵列的区别。 – bebebe