0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

テキストファイルリード

Last updated at Posted at 2025-04-27

指定したTextStreamのテキストファイルをリードする。
1行読み込み、1行ごと全ファイル読み込み、全ファイル読み込みが指定可能

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' テキストファイルリード
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Public Function F_File_GetReadTextFile( _
        ByRef aRtn As Variant, _
        ByRef aTs As TextStream, _
        ByVal aTextSpec As E_FILE_SPEC_TEXT, _
        Optional ByVal aPath As String = "") As Boolean
    Dim wkRet As Boolean: wkRet = False
    Dim wkRtn As Variant
    
    '引数チェック
    If aTs Is Nothing Then
        'パスでファイルオープンできなかった場合は終了
        If F_File_GetOpenTextFile(aTs, aPath, aIOMode:=ForReading, aCreate:=False) <> True Then
            Exit Function
        End If
    End If
    
    '行ごとにリードする場合
    If M_Common.F_CheckBitOn(aTextSpec, E_FILE_SPEC_TEXT_LINE) = True Then
        '全行リードする場合
        If M_Common.F_CheckBitOn(aTextSpec, E_FILE_SPEC_TEXT_ALL) = True Then
            '最終行でない間はループ
            Do While aTs.AtEndOfStream <> True
                '行を配列で設定
                wkRtn = M_Common.F_ReturnArrayAdd(wkRtn, aTs.ReadLine)
                wkRet = True
            Loop
        '1行読み込む場合は最終行でなければリード
        ElseIf aTs.AtEndOfStream <> True Then
            wkRtn = aTs.ReadLine
            wkRet = True
        End If
    'ファイル全てを読み込む場合
    ElseIf M_Common.F_CheckBitOn(aTextSpec, E_FILE_SPEC_TEXT_ALL) = True Then
        wkRtn = aTs.ReadAll
        wkRet = True
    End If
    
    If wkRet = True Then
        aRtn = wkRtn
        F_File_GetReadTextFile = True
    End If
End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?