TextStream ファイルで、指定された読み込み位置に移動(Skip,SkipLine)
Skip メソッド
開いた TextStream ファイルで、指定された文字数をスキップした場所へ読み込み位置を移動します。
<取得>
object.Skip ( characters )
引数・戻り値
- object ・・・ TextStream オブジェクトを指定します。
- characters ・・・ スキップする文字数を指定します。
読み取り専用モード以外で開かれたファイルで使用すると、エラーが発生します。
SkipLine メソッド
開いた TextStream ファイルで、1行下の行頭に読み込み位置を移動します。
<取得>
object.SkipLine
引数・戻り値
- object ・・・ TextStream オブジェクトを指定します。
読み取り専用モード以外で開かれたファイルで使用すると、エラーが発生します。
Skip メソッド・SkipLine メソッド 使用例
サンプルVBAソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Sub Sample_Skip() Dim fso As New FileSystemObject Dim f1 As TextStream, f2 As TextStream, f3 As TextStream Dim str1 As String, str2 As String, str3 As String Dim fname As String fname = "C:\Documents\mydata5\test01.txt" Set f1 = fso.OpenTextFile(fname) str1 = "【test01.txt の内容すべて】" & vbCrLf & f1.ReadAll f1.Close 'Skip メソッド Set f2 = fso.OpenTextFile(fname) f2.Skip 5 str2 = "【test01.txt 6文字目から読み込み】" & vbCrLf & f2.ReadAll f2.Close 'SkipLine メソッド Set f3 = fso.OpenTextFile(fname) f3.SkipLine str3 = "【test01.txt 2行目から読み込み】" & vbCrLf & f3.ReadAll f3.Close MsgBox str1 & vbCrLf & str2 & vbCrLf & str3 End Sub |
実行結果
関連記事
-
-
FileSystemObject:ファイルを開く(OpenAsTextStream メソッド)
ファイルを開く(OpenAsTextStream メソッド) 指定されたファイル …
-
-
FileSystemObject:フォルダの存在確認(FolderExists メソッド)
フォルダの存在確認(FolderExists メソッド) FileSystemO …
-
-
FileSystemObject:ドライブの存在確認(DriveExists メソッド)
ドライブの存在確認(DriveExists メソッド) FileSystemOb …
-
-
FileSystemObject:ファイルを移動する(MoveFile)
ファイルを移動する(MoveFile メソッド) FileSystemObjec …
-
-
FileSystemObject:フォルダ内のすべてのファイルを取得(Files プロパティ)
フォルダ内のすべてのファイルを取得(Files プロパティ) フォルダ内のすべて …
-
-
FileSystemObject:ルートフォルダかどうかを調べる(IsRootFolder プロパティ)
ルートフォルダかどうかを調べる(IsRootFolder プロパティ) File …
-
-
FileSystemObject:Folder オブジェクトの取得
Folder オブジェクトの取得 Folder オブジェクト を取得するには、F …
-
-
FileSystemObject:Drive オブジェクトの主なプロパティ
Drive オブジェクトの取得 Drive オブジェクト を取得するには、FSO …
-
-
FileSystemObject:ファイル・フォルダの作成日時を取得(DateCreated プロパティ)
ファイル・フォルダの作成日時を取得(DateCreated プロパティ) Fil …
-
-
FileSystemObject:フォルダやファイルを削除(Delete メソッド)
フォルダやファイルを削除(Delete メソッド) FileSystemObje …