100 行 8 列の .csv ファイルがあります。各行は以下のように見えます
0,0,0,0,0,0,0,5
0,1,0,0,1,0,0,6
各フィールドを評価する必要があります。フィールド = 1 (行 1 と 7 の間) の場合、その行の 8 列目の値をテキスト ボックスに書き込む必要があります。フィールド = 0 の場合、その行には何も書き込みません。
各フィールドを評価する方法について非常に混乱しています。
Jet-Driver で ADO を使用しています。インポートの結果は、簡単にナビゲートできる ADO.Recordset であり、非常に簡単です。
Dim cnCSV As ADODB.Connection
Set cnCSV = New ADODB.Connection
cnCSV.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Chr(34) & lFilePath & Chr(34) & ";Extended Properties=" & Chr(34) & "text;HDR=Yes;FMT=Delimited" & Chr(34) & ";"
cnCSV.Open
Dim p_ImportRst As ADODB.Recordset
Set p_ImportRst = New ADODB.Recordset
lstrSQL = "SELECT * FROM [" & lFileName & "]"
Set p_ImportRst = cnCSV.Execute(lstrSQL)
これがうまくいくはずのアプローチです。疑似コードっぽい...
dim vData() as variant
dim nHandle as integer
dim sTextLine as string
nHandle = FreeFile
open "c:\filename.csv" for input as nHandle
Do While Not EOF(nHandle)
Line Input #nHandle, sTextLine '// Read line into variable.
' break up the line into multiple pieces
vData = split(sTextLine, ",")
' your criteria here
if vData(0) = 0 then ...
if vData(1) = ...
Loop
Close #nHandle
「割る」を使う
「区切り文字 (カンマやスペースなど) に基づいて文字列を個別の要素に分割し、結果の要素をゼロから始まる配列に格納します」
http://www.vb6.us/tutorials/vb-string-array-functions-split-join-filter
可変サイズの配列を作成します。lbound と ubound を使用してそのサイズを取得し、for ループを実行して数値を加算します。