如何计算VB6中的数组

如何计算VB6中的数组

问题描述:

我有一个CSV文件将解析并将其放入数组。 注意这是一个很大的文件。我的问题是,我该如何计算Vb6中的数组?是否有可能在Array中进行计算?如何计算VB6中的数组

+1

有多大? “计算数组”是什么意思?你的意思是你想读入文件并将每行放在数组的单独元素中? – Hrqls

+1

阵列中的1400个数据很大。我问是否有可能获得阵列与阵列的区别。 – bebebe

在一个文件中读取,并在数组中,你可以做如下:

'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 
+0

是否有可能像这样Array() - Array()数组中有一个计算? – bebebe

+2

此代码是我需要:)谢谢:) – bebebe

+0

我有下一个问题,也许你也可以帮助我。我将我的数组的总数写入一个CSV文件中,我使用'writeline'将它写入CSV文件。我的问题是这每当我写在CSV文件它会写,但只写在第一列,我的问题是,我怎么能写在下一列使用writeline? – bebebe