سؤال

I have a CSV file that will parse and put it to array. Note this is a big file.My questions are this how can i compute an Array in Vb6? Is it possible to have a computation in Array?

هل كانت مفيدة؟

المحلول

to read in a file and it in an array you can do as follows:

'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

this will read in the file, put it into an array (each line with its own element), and then loop through the whole array to print each line/element on the form

[EDIT]

below is an example how to substract items from an array from corresponding items from another array:

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top