-
Notifications
You must be signed in to change notification settings - Fork 9
/
modReadfile.bas
27 lines (22 loc) · 1.1 KB
/
modReadfile.bas
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
Attribute VB_Name = "modReadfile"
Option Explicit
Private Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lread Lib "kernel32" Alias "_lread" (ByVal hFile As Long, lpBuffer As Any, ByVal wBytes As Long) As Long
Private Declare Function llseek Lib "kernel32" Alias "_llseek" (ByVal hFile As Long, ByVal lOffset As Long, ByVal iOrigin As Long) As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
Function ReadFile(ByRef sFileName As String) As String
Dim hFile As Long
Dim sFileContent As String
Dim lFileLength As Long
If (Dir$(sFileName, 16) <> "") Then
hFile = lopen(sFileName, 0)
lFileLength = llseek(hFile, 0, 2)
llseek hFile, 0, 0
sFileContent = Space$(lFileLength)
lread hFile, ByVal sFileContent, lFileLength
lclose hFile
ReadFile = sFileContent
Else
MsgBox "File " & sFileName & " not accessible.", vbExclamation + vbOKOnly, "Open file error"
End If
End Function