Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access 如何查看access数据库ini文件记录?_Ms Access_Vb6_Ini - Fatal编程技术网

Ms access 如何查看access数据库ini文件记录?

Ms access 如何查看access数据库ini文件记录?,ms-access,vb6,ini,Ms Access,Vb6,Ini,我有一个vb6项目。它是由高级工程师开发的。现在我想更改现有的代码。我是vb6新手。数据库文件类似ini格式。事实上,他是用access数据库工作的。我想在此数据库中创建一些表。请给出在access数据库中打开ini文件的想法或打开ini文件的想法。哦,天哪,这是老东西: Jose的VB提示和技巧 使用初始化文件 用伟大的美国作家马克·吐温的话说,关于死亡的报道 ini文件的数量被大大夸大了 而微软已经宣布注册中心是一个合适的信息仓库 初始化信息,.ini文件仍有其用途。在人群中 .ini文件

我有一个vb6项目。它是由高级工程师开发的。现在我想更改现有的代码。我是vb6新手。数据库文件类似ini格式。事实上,他是用access数据库工作的。我想在此数据库中创建一些表。请给出在access数据库中打开ini文件的想法或打开ini文件的想法。

哦,天哪,这是老东西:

Jose的VB提示和技巧

使用初始化文件


用伟大的美国作家马克·吐温的话说,关于死亡的报道 ini文件的数量被大大夸大了

而微软已经宣布注册中心是一个合适的信息仓库 初始化信息,.ini文件仍有其用途。在人群中 .ini文件的优点是:

  • 使用任何简单的文本编辑器,这些文件都很容易“让人可读” 比如记事本
  • 用于处理.ini文件的API代码比 等效的注册表API
  • 通过网络,只需使用 两端都安装了基本重定向器
  • 安装.ini文件非常简单,只需将文件复制到 Windows目录
Windows提供了各种用于处理.ini文件的API,包括 GetProfileXXX和WriteProfileXXX函数专用于处理 win.ini和以下用于读取和写入的函数 初始化文件:

GetPrivateProfileString 从.ini文件中读取字符串。 GetPrivateProfileInt 从.ini文件中读取整数。 WritePrivateProfileString 将字符串写入.ini文件。 WritePrivateProfileInt 将整数写入.ini文件

但是,鉴于.ini文件中的所有数据都是纯文本, 实际上,没有必要对这些工具的xxxInt版本进行单独编码 功能。在VB中,使用 CInt()或Val()函数,因此只有GetPrivateProfileString和 需要WritePrivateProfileString函数

这两个都是简单的API调用。有一个例外情况是 读取返回C字符串的.ini文件,该字符串包含多个由分隔的值 空值。为了解析该字符串,我包含了multicStringToStringAray 功能

在继续之前,您需要向声明中添加两个声明 某个模块的某个部分。作为一种习惯,我使用别名win32api 使用“w32_389;”,这样我就可以编写一个VB包装函数并给它命名 API函数的

以下是声明部分:

Option Explicit

Private Declare Function w32_GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" ( _
  ByVal lpAppName As String, _
  ByVal lpKeyName As String, _
  ByVal lpDefault As String, _
  ByVal lpReturnedString As String, _
  ByVal nSize As Long, _
  ByVal lpFileName As String) As Long

Private Declare Function w32_WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
  ByVal lpApplicationName As String, _
  ByVal lpKeyName As Any, _
  ByVal lpString As Any, _
  ByVal lpFileName As String) As Long
以下是GetPrivateProfileString的代码:

Public Function GetPrivateProfileString( _
  psAppName As String, _
  psKeyName As String, _
  Optional pvsDefault As Variant, _
  Optional pvsFileName As Variant) As String
'********************
' Purpose:    Get a string from a private .ini file
' Parameters:
' (Input)
'   psApplicationName - the Application name
'   psKeyName - the key (section) name
'   pvsDefault - Default value if key not found (optional)
'   pvsFileName - the name of the .ini file
' Returns:  The requested value
' Notes:
'   If no value is provided for pvsDefault, a zero-length string is used
'   The file path defaults to the windows directory if not fully qualified
'   If pvsFileName is omitted, win.ini is used
'   If vbNullString is passed for psKeyName, the entire section is returned in
'     the form of a multi-c-string. Use MultiCStringToStringArray to parse it after appending the
'     second null terminator that this function strips. Note that the value returned is all the
'     key names and DOES NOT include all the values. This can be used to setup multiple calls for
'     the values ala the Reg enumeration functions.
'********************

  ' call params
  Dim lpAppName As String
  Dim lpKeyName As String
  Dim lpDefault As String
  Dim lpReturnedString As String
  Dim nSize As Long
  Dim lpFileName As String
  ' results
  Dim lResult As Long
  Dim sResult As String

  sResult = ""

  ' setup API call params
  nSize = 256
  lpReturnedString = Space$(nSize)
  lpAppName = psAppName
  lpKeyName = psKeyName
  ' check for value in file name
  If Not IsMissing(pvsFileName) Then
    lpFileName = CStr(pvsFileName)
  Else
    lpFileName = "win.ini"
  End If
  ' check for value in optional pvsDefault
  If Not IsMissing(pvsDefault) Then
    lpDefault = CStr(pvsDefault)
  Else
    lpDefault = ""
  End If
  ' call
  ' setup loop to retry if result string too short
  Do
    lResult = w32_GetPrivateProfileString( _
        lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName)
    ' Note: See docs for GetPrivateProfileString API
    ' the function returns nSize - 1 if a key name is provided but the buffer is too small
    ' the function returns nSize - 2 if no key name is provided and the buffer is too small
    ' we test for those specific cases - this method is a bit of hack, but it works.
    ' the result is that the buffer must be at least three characters longer than the
    ' longest string(s)
    If (lResult = nSize - 1) Or (lResult = nSize - 2) Then
      nSize = nSize * 2
      lpReturnedString = Space$(nSize)
    Else
      sResult = Left$(lpReturnedString, lResult)
      Exit Do
    End If
  Loop

  GetPrivateProfileString = sResult

End Function
Public Function WritePrivateProfileString( _
  psApplicationName As String, _
  psKeyName As String, _
  psValue As String, _
  psFileName As String) As Boolean
'********************
' Purpose:    Write a string to an ini file
' Parameters: (Input Only)
'   psApplicationName - the ini section name
'   psKeyName - the ini key name
'   psValue - the value to write to the key
'   psFileName - the ini file name
' Returns:    True if successful
' Notes:
'   Path defaults to windows directory if the file name
'   is not fully qualified
'********************

  Dim lResult As Long
  Dim fRV As Boolean

  lResult = w32_WritePrivateProfileString( _
      psApplicationName, _
      psKeyName, _
      psValue, _
      psFileName)
  If lResult <> 0 Then
    fRV = True
  Else
    fRV = False
  End If

  WritePrivateProfileString = fRV

End Function
以下是WritePrivateProfileString:

Public Function GetPrivateProfileString( _
  psAppName As String, _
  psKeyName As String, _
  Optional pvsDefault As Variant, _
  Optional pvsFileName As Variant) As String
'********************
' Purpose:    Get a string from a private .ini file
' Parameters:
' (Input)
'   psApplicationName - the Application name
'   psKeyName - the key (section) name
'   pvsDefault - Default value if key not found (optional)
'   pvsFileName - the name of the .ini file
' Returns:  The requested value
' Notes:
'   If no value is provided for pvsDefault, a zero-length string is used
'   The file path defaults to the windows directory if not fully qualified
'   If pvsFileName is omitted, win.ini is used
'   If vbNullString is passed for psKeyName, the entire section is returned in
'     the form of a multi-c-string. Use MultiCStringToStringArray to parse it after appending the
'     second null terminator that this function strips. Note that the value returned is all the
'     key names and DOES NOT include all the values. This can be used to setup multiple calls for
'     the values ala the Reg enumeration functions.
'********************

  ' call params
  Dim lpAppName As String
  Dim lpKeyName As String
  Dim lpDefault As String
  Dim lpReturnedString As String
  Dim nSize As Long
  Dim lpFileName As String
  ' results
  Dim lResult As Long
  Dim sResult As String

  sResult = ""

  ' setup API call params
  nSize = 256
  lpReturnedString = Space$(nSize)
  lpAppName = psAppName
  lpKeyName = psKeyName
  ' check for value in file name
  If Not IsMissing(pvsFileName) Then
    lpFileName = CStr(pvsFileName)
  Else
    lpFileName = "win.ini"
  End If
  ' check for value in optional pvsDefault
  If Not IsMissing(pvsDefault) Then
    lpDefault = CStr(pvsDefault)
  Else
    lpDefault = ""
  End If
  ' call
  ' setup loop to retry if result string too short
  Do
    lResult = w32_GetPrivateProfileString( _
        lpAppName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName)
    ' Note: See docs for GetPrivateProfileString API
    ' the function returns nSize - 1 if a key name is provided but the buffer is too small
    ' the function returns nSize - 2 if no key name is provided and the buffer is too small
    ' we test for those specific cases - this method is a bit of hack, but it works.
    ' the result is that the buffer must be at least three characters longer than the
    ' longest string(s)
    If (lResult = nSize - 1) Or (lResult = nSize - 2) Then
      nSize = nSize * 2
      lpReturnedString = Space$(nSize)
    Else
      sResult = Left$(lpReturnedString, lResult)
      Exit Do
    End If
  Loop

  GetPrivateProfileString = sResult

End Function
Public Function WritePrivateProfileString( _
  psApplicationName As String, _
  psKeyName As String, _
  psValue As String, _
  psFileName As String) As Boolean
'********************
' Purpose:    Write a string to an ini file
' Parameters: (Input Only)
'   psApplicationName - the ini section name
'   psKeyName - the ini key name
'   psValue - the value to write to the key
'   psFileName - the ini file name
' Returns:    True if successful
' Notes:
'   Path defaults to windows directory if the file name
'   is not fully qualified
'********************

  Dim lResult As Long
  Dim fRV As Boolean

  lResult = w32_WritePrivateProfileString( _
      psApplicationName, _
      psKeyName, _
      psValue, _
      psFileName)
  If lResult <> 0 Then
    fRV = True
  Else
    fRV = False
  End If

  WritePrivateProfileString = fRV

End Function
这就是编码.ini文件的全部内容

注释

  • 查看SDK文档以了解这些行为的详细信息 功能
  • 如果向write函数发送长度为零的字符串,则键为 删除
  • 如果试图为不存在的键或 节不存在时,将创建键或节
  • 尽管微软将注册中心描述为中心 Win95、win.ini和 system.ini仍在使用,因此在使用这些文件时要小心 文件(换句话说,在实验之前进行备份)
  • GetPrivateProfileString返回请求的数据,但 WritePrivateProfileString返回指示成功或失败的布尔值 失败。虽然GetPrivateProfileString非常可靠,但它可以 可以轻松修改以返回布尔值或其他类型的状态 指示结果的代码
  • 如果使用GetPrivateProfileString返回整个节, 请记住添加一个额外的null(string&vbNullChar将完成此操作) 调用MultiStringToStringAray之前,因为该函数需要 两个null以终止字符串。此外,请记住,只有 返回的是键名,而不是值

返回页首[返回页首]


|主页| Jose的Visual Basic世界| Jose的VB提示和技巧| |©1997乔·加里克|信息中心|[电子邮件]jgarrick@citilink.com|