ForNext
Only Do What Only You Can Do
25. テキストファイルを読む
VBScript
JScript
Perl
PHP
Python
Ruby
PowerShell
Scala
F#
C
C++
C++Builder
更新日 : 2005.12.13
void __fastcall TForm1::Button21Click(TObject *Sender) { const int adOpenForwardOnly = 0; const int adLockReadOnly = 1; //表示用コントロールをクリア ListBox1->Items->Clear(); ListBox2->Items->Clear(); Variant cn = Variant::CreateObject("ADODB.Connection"); //Edit3 に テキストファイルのパスを入力 cn.Exec(PropertySet("ConnectionString")<<"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" + Edit3->Text + ";"); cn.Exec(Procedure("Open")); //Edit4 に テキストファイル名を入力 Variant rs = Variant::CreateObject("ADODB.Recordset"); rs.Exec(PropertySet("Source")<<Edit4->Text); rs.Exec(PropertySet("Activeconnection")<<cn); rs.Exec(PropertySet("CursorType")<<adOpenForwardOnly); rs.Exec(PropertySet("LockType")<<adLockReadOnly); rs.Exec(Procedure("Open")); while (!rs.Exec(PropertyGet("EOF"))) { //表示用コントロールに項目内容をセット Variant fd = rs.Exec(PropertyGet("Fields")<<0); ListBox1->Items->Add(fd.Exec(PropertyGet("Value"))); fd = rs.Exec(PropertyGet("Fields")<<1); ListBox2->Items->Add(fd.Exec(PropertyGet("Value"))); rs.Exec(Function("MoveNext")); } rs.Exec(Procedure("Close")); cn.Exec(Procedure("Close")); }
VC++
C#
Java
Objective-C
D
VB
VB.NET
Delphi
更新日 : 2005.12.13
procedure TForm1.Button21Click(Sender: TObject); var cn :Variant;//Connection rs :Variant;//Recordset const adOpenDynamic: Integer = 2; adOpenForwardOnly: Integer = 0; adOpenKeyset: Integer = 1; adOpenStatic: Integer = 3; adOpenUnspecified: Integer = -1; adLockBatchOptimistic: Integer = 4; adLockOptimistic: Integer = 3; adLockPessimistic: Integer = 2; adLockReadOnly: Integer = 1; adLockUnspecified: Integer = -1; begin //表示用コントロールをクリア ListBox1.Items.Clear; ListBox2.Items.Clear; cn := CreateOleObject('ADODB.Connection'); //Edit3 に テキストファイルのパスを入力 cn.ConnectionString := 'Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=' + Edit3.Text + ';'; cn.Open; //Edit4 に テキストファイル名を入力 rs := CreateOleObject('ADODB.Recordset'); rs.Source := Edit4.Text; rs.Activeconnection := cn; rs.CursorType := adOpenForwardOnly; rs.LockType := adLockReadOnly; rs.Open; while not rs.EOF do begin //表示用コントロールに項目内容をセット ListBox1.Items.Add(rs.Fields[0].Value); ListBox2.Items.Add(rs.Fields[1].Value); rs.MoveNext; end; rs.Close; cn.Close; end;