求助:存取外部文件数据
系统登陆如何记住用户名和密码,下次登陆只需要点击确定按钮就自动登陆系统。Option Explicit '写 Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long '读 Public Declare 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 '保存到INI文件 Public Function Wini(ByVal 段 As String, ByVal 键 As String, ByVal 值 As String, IniFile As String) As Boolean Dim X As Long, buff As String * 128, i As Long '警告:最大长度不得超过127,否则会导致错误 buff = 值 & Chr(0) X = WritePrivateProfileString(段, 键, buff, IniFile) Wini = X End Function '从INI文件中读取 Public Function Rini(ByVal 段 As String, ByVal 键 As String, IniFile As String) As String Dim X As Long, buff As String * 128, i As Long '警告:最大长度不得超过127,否则会导致数据不完整 X = GetPrivateProfileString(段, 键, "", buff, 128, IniFile) i = InStr(buff, Chr(0)) Rini = Trim(Left(buff, i - 1)) End Function
Wini "Print", "左边距", 左边距, Path & ConfigPath & "\" & 打印设置 Wini "Print", "右边距", 右边距, Path & ConfigPath & "\" & 打印设置
左边距 = Val(Rini("Print", "左边距", Path & ConfigPath & "\" & 打印设置)) 右边距 = Val(Rini("Print", "右边距", Path & ConfigPath & "\" & 打印设置))