Option Explicit
'INI文件的文件名
Public File As String#If Win32 Then
   Private 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 Integer, ByVal lpFileName As String) As Integer
   Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal FileName As String) As Integer
#Else
   Private Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
   Private Declare Function WritePrivateProfileString Lib "Kernel" (ByVal Appname As String, ByVal KeyName As Any, ByVal NewString As Any, ByVal FileName As String) As Integer
#End If'删除一个[OPITION]
Sub DeleteSection(ByVal Section As String)Dim retval As Integer   retval = WritePrivateProfileString(Section, 0&, "", File)End Sub
'保存一个key
Public Function SaveSetting(ByVal Section$, ByVal Key$, ByVal Value$)Dim retval As Integer   SaveSetting = WritePrivateProfileString(Section$, Key$, Value$, File)End Function
'得到一个key值
Public Function GetSettingB(ByVal Section As String, ByVal KeyName As String) As StringDim retval As Integer
Dim t As String * 255
   retval = GetPrivateProfileString(Section, KeyName, "unknown value", t, Len(t), File)
   If retval > 0 Then
      GetSettingB = Left$(t, retval)
   Else
      GetSettingB = "Unknown section or key"
   End If
End Function'得到一个[OPITION]
Public Function GetSection(ByVal Section As String, KeyArray() As String) As IntegerDim retval As Integer
Dim t As String * 2500
Dim lastpointer As Integer
Dim nullpointer As Integer
Dim ArrayCount As Integer
Dim keystring As String
   
   ReDim KeyArray(0)
   
   retval = GetPrivateProfileString(Section, 0&, "", t, Len(t), File)
   
   ' If there is one, return it
   If retval > 0 Then
      '
      ' Separate the keys and store them in the array
      nullpointer = InStr(t, Chr$(0))
      lastpointer = 1
      Do While (nullpointer <> 0 And nullpointer > lastpointer + 1)
         '
         ' Extract key string
         keystring = Mid$(t, lastpointer, nullpointer - lastpointer)
         '
         ' Now add to array
         ArrayCount = ArrayCount + 1
         ReDim Preserve KeyArray(ArrayCount)
         KeyArray(ArrayCount) = keystring
         '
         ' Find next null
         lastpointer = nullpointer + 1
         nullpointer = InStr(nullpointer + 1, t, Chr$(0))
      Loop
   End If
   '
   ' Return the number of array elements
   GetSection = ArrayCount
   
End Function保存在一个模块中.

解决方案 »

  1.   

    保存后并存为只读格式
    ====================================================================
    SetAttr 语句
          为一个文件设置属性信息。语法SetAttr pathname, attributesSetAttr 语句的语法含有以下这些命名参数:部分 描述 
    pathname 必要参数。用来指定一个文件名的字符串表达式,可能包含目录或文件夹、以及驱动器。 
    Attributes 必要参数。常数或数值表达式,其总和用来表示文件的属性。 
    设置值attributes 参数设置可为:常数 值 描述 
    vbNormal 0 常规(缺省值) 
    VbReadOnly 1 只读。 
    vbHidden 2 隐藏。 
    vbSystem 4 系统文件 
    vbArchive 32 上次备份以后,文件已经改变 
    注意 这些常数是由 VBA 所指定的,在程序代码中的任何位置,可以使用这些常数来替换真正的数值。说明如果想要给一个已打开的文件设置属性,则会产生运行时错误。SetAttr 语句示例
    本示例使用 SetAttr 语句来设置文件属性。SetAttr"TESTFILE", vbHidden   ' 设置隐含属性。
    SetAttr"TESTFILE", vbHidden + vbReadOnly   ' 设置隐含并只读。
      

  2.   

    to: zqfleaf(啊风) 
       没有太明白,能不能具体一点,我怎样查找、替换?
    to: zyl910(910:分儿,我来了!) 
       文件属性可以,怎样查找、替换其中的部分字符串?