プログラマメモ

VBScript_Class

最終更新:

inouework

- view
管理者のみ編集可
  • ファイルアクセスクラス
Option Explicit

Class CFileAcs
	
	Private m_strPath
	Private m_strUpdateDate
	Private m_nLastLine
	Private m_nReadPointer
	Private m_astrData
	
	'ファイルパス
	Public Property Let FilePath(ByVal value)
		m_strPath = value
	End Property
	Public Property Get FilePath()
		FilePath = m_strPath
	End Property
	
	'ファイル更新日付
	Public Property Let FileUpdateDate(ByVal value)
		m_strUpdateDate = value
	End Property
	Public Property Get FileUpdateDate()
		FileUpdateDate = m_strUpdateDate
	End Property
	
	'読込最終行数
	Public Property Let LastLine(ByVal value)
		m_nLastLine = value
	End Property
	Public Property Get LastLine()
		LastLine = m_nLastLine
	End Property
	
	'読込データ
	Public Property Get ReadData()
		Set ReadData = m_astrData
	End Property
	Public Property Get ReadLineData(Byval vIndex)
	    ReadLineData = vbNullString
	    If vIndex <= UBound(m_astrData) Then
	        ReadLineData = m_astrData(vIndex)
	    End If
	End Property
	
	Public Sub init(ByVal strFilePath)
	    m_strPath       = strFilePath
	    m_strUpdateDate = vbNullString
	    m_nLastLine     = 0
	    m_nReadPointer  = 1
	End Sub
	
	Public Sub FileRandomRead()
		Dim objFSO      ' FileSystemObject
		Dim objFile     ' ファイル読み込み用
		Dim strData     ' ファイル読み込み用
		Set objFSO = CreateObject( "Scripting.FileSystemObject")
		If Err.Number = 0 Then
		    Set objFile = objFSO.OpenTextFile( m_strPath)
		    If Err.Number = 0 Then
		        strData = objFile.ReadAll
		        objFile.Close
		    Else
		        MsgBox "ファイルオープンエラー: " & Err.Description
		    End If
		Else
		    MsgBox "エラー: " & Err.Description
		End If
		
		m_astrData = split( strData,vbCrLf)
		
		m_nLastLine = UBound( m_astrData)
		Set objFile = Nothing
		Set objFSO = Nothing
	
	End Sub
	
	Public Function ChkFileChange()
	    If g_strFileUpdate = FileDateTime( g_strFilePath) Then
	        ChkFileChange = False
	    Else
	        ChkFileChange = True
	    End If
	End Function
	
End Class
記事メニュー
人気記事ランキング
目安箱バナー