> 2004/01/17 (土) 00:42:24 ◆ ▼ ◇ [mirai]> > .NET以降VBは全然別物になってるので注意な
> 何が違うよ?
VB6
1: Private Sub Form_Load()
2: Const ForReading = 1
3: Const TristateTrue = -1
4: Dim fs, f
5: Set fs = CreateObject("Scripting.FileSystemObject")
6: Set f = fs.OpenTextFile("c:\testfile.txt", ForReading, False, TristateTrue)
7: Do While f.AtEndOfStream <> True
8: s = f.ReadLine
9: Debug.Print s
10: Loop
11: f.Close
12: End Sub
VB.NET
1: Imports System.IO
2:
3: Public Class Form1
4: Inherits System.Windows.Forms.Form
5:
6: #Region " Windows Form Designer generated code "
7:
8: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
9: Dim reader As StreamReader
10: reader = New StreamReader( _
11: New FileStream("c:\testfile.txt", FileMode.Open, FileAccess.Read), _
12: System.Text.Encoding.GetEncoding("UTF-16"))
13: Do
14: Dim s As String
15: s = reader.ReadLine()
16: If s = Nothing Then Exit Do
17: Debug.WriteLine(s)
18: Loop
19: reader.Close()
20: End Sub
21: End Class
参考:2004/01/17(土)00時34分42秒