ini文件 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 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, App.Path + "\ABC.INI") WriteOneString = x End Function 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, App.Path + "\ABC.INI") I = InStr(buff, Chr(0)) ReadOneString = Trim(Left(buff, I - 1)) End Function 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
把文本文件内容读取TextBox: Dim TempFile As Long Dim LoadBytes() As ByteTempFile=FreeFile Open 文件名 For Binary As #TempFile Redim LoadBytes(1 To Lof(TempFile)) As Byte Get #TempFile,,LoadBytes Close TempFileText1.Text=StrConv(LoadBytes,vbUniCode)把TextBox内容写入文本文件: Dim TempFile As Long Dim SaveBytes() As ByteSaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile Open 文件名 For Binary As #TempFile Put #TempFile,,SaveBytes Close TempFile
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
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, App.Path + "\ABC.INI")
WriteOneString = x
End Function
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, App.Path + "\ABC.INI")
I = InStr(buff, Chr(0))
ReadOneString = Trim(Left(buff, I - 1))
End Function
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
Dim TempFile As Long
Dim LoadBytes() As ByteTempFile=FreeFile
Open 文件名 For Binary As #TempFile
Redim LoadBytes(1 To Lof(TempFile)) As Byte
Get #TempFile,,LoadBytes
Close TempFileText1.Text=StrConv(LoadBytes,vbUniCode)把TextBox内容写入文本文件:
Dim TempFile As Long
Dim SaveBytes() As ByteSaveBytes=StrConv(Text1.Text,vbFromUniCode)TempFile=FreeFile
Open 文件名 For Binary As #TempFile
Put #TempFile,,SaveBytes
Close TempFile