목차 열기
티스토리 뷰
728x90
반응형
선언
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
Private Declare PtrSafe Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" ( _
ByVal lpApplicationName As String, ByVal lpKeyName As Any, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String _
) As Long
Private Declare PtrSafe Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As String _
) As Long
|
cs |
(64Bit 환경이어서 PtrSafe가 추가 되었음.)
예제 함수
읽기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
Public Function readIniFile(ByVal strSec As String, _
ByVal strKey As String) As String
'20200216
'ini파일 [Section]에서 Key의 값을 읽어 반환한다.
Dim buffer As String * 128 '데이터가 들어갈 버퍼
Dim int_Max_buffer As Integer '버퍼의 크기
Dim strFilePath As String 'ini 파일의 경로
Dim strReturn As String '반환 값
Dim strReturnGPPS As Long 'GPPS 변수
strReturn = "#SecOrKey"
If strSec <> "" And strKey <> "" Then
buffer = space(128)
int_Max_buffer = Len(buffer)
strFilePath = "ini 파일의 경로" 'ini 파일의 경로
strReturnGPPS = GetPrivateProfileString(strSec, strKey, "", _
buffer, int_Max_buffer, strFilePath) 'ini Core
If strReturnGPPS Then
strReturn = Left$(buffer, strReturnGPPS) '찾은 값 저장
End If
End If
readIniFile = strReturn '값 반환
End Function
|
cs |
쓰기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Public Function writeIniFile(ByVal strSec As String, _
ByVal strKey As String, ByVal strCon As String) As String
'20200216
'ini파일 [Section]에서 Key의 값에 Content를 쓰고 성공여부를 Boolean으로 반환한다.
Dim strFilePath As String 'ini 파일의 경로
Dim strReturn As String '반환 값
strReturn = False
If strSec <> "" And strKey <> "" Then
strFilePath = "ini 파일의 경로" 'ini 파일의 경로
strReturnGPPS = WritePrivateProfileString(strSec, strKey, _
strCon, strFilePath) 'ini Core
strReturn = True
End If
writeIniFile = strReturn '값 반환
End Function
|
cs |
연관검색어
더보기
vbs vba VBA 비주얼베이직 엑셀 코딩 excel visual basic for application
728x90
반응형
'VBA' 카테고리의 다른 글
VBA / InputBox / 메서드 (0) | 2020.07.09 |
---|---|
VBA / MsgBox / 함수 (0) | 2020.07.09 |
VBA / Workbook 개체 / 워크북 (0) | 2020.02.24 |
VBA / String / 문자 (0) | 2020.02.20 |
VBA / Worksheet 개체 / 워크시트 (0) | 2020.02.18 |
VBA / Declare 64Bit 오류 (0) | 2020.02.14 |
VBA / 대입의 왼쪽에서 호출하는 함수는 Variant나 Object를 변환해야 합니다. (0) | 2020.02.12 |
댓글