可以利用 INI 文件和Windows95/98的注册数据库来保存,下面讲解如何使用 INI 文件来保存和读取内容。假设当前有 Text1、Text2、Text3三个文本框的内容需要保存,INI文件名为 ABC.INI。 首先新建一个Module,然后,在此Module中说明 API 函数: Declare Function WritePrivateProfileString Lib ″ker nel32″ Alias ″WritePrivateProfileStringA″ (ByVal lpApplica tionName As String, ByVal lpKeyName As Any, ByVal lp String As Any, ByVal lpFileName As String) As Long 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 为了简化工作,最好定义好几个函数,给程序提供更简单的操作,首先定义一个用于输入的函数WriteOneString: Private Function WriteOneString(ByVal Section As String, ByVal Key As String, ByVal value As String) As Boolean Dim x As Long, buff As String * 128, I As Integer buff = value + Chr(0) x = WritePrivateProfileString(Section, Key, buff, ″ABC.INI″) WriteOneString = x End Function 然后定义一个用于输出的函数 ReadOneString : Private Function ReadOneString(ByVal Section As String, ByVal Key As String) As String Dim x As Long, buff As String * 128, I As Integer x = GetPrivateProfileString(Section, Key, ″″, buff, 128, ″ABC.INI″) I = InStr(buff, Chr(0)) ReadOneString = Trim(Left(buff, I - 1)) End Function 这时,你就可以在 Form 的 Load 和 UnLoad 事件里分别进行保存和读取操作。 Private Sub Form_Load() Text1 = ReadOneString(″Option″,″Text1″) Text2 = ReadOneString(″Option″,″Text2″) Text3 = ReadOneString(″Option″,″Text3″) End Sub Private Sub Form_Unload(Cancel As Integer) Text1 = WriteOneString(″Option″,″Text1″,Text1) Text2 = WriteOneString(″Option″,″Text2″,Text2) Text3 = WriteOneString(″Option″,″Text3″,Text3) End Sub  
|