VB程序初始化ini文件时出错
我通过程序运行初始化时从INI文件中获取数据库地址,然后进行打开等操作,文件出现如图上的错误是什么原因??我用Msgbox试过了API函数GetPrivateprofilestring获取的地址没有问题!!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
'声明API函数
Public inifilename As String '声明变量
Public Sub Main() '主函数
Dim n As Integer
Dim DbName As String * 255
inifilename = App.Path & "\DB_GCYF.ini" '将初始化ini文件赋值给变量
n = GetPrivateProfileString("数据库", "namepath", "", DbName, Len(DbName), inifilename) '获取ini文件中的数据库地址赋予变量
DbName = Left(DbName, n)
frm_strat.Show '显示登陆主窗体
End Sub
Public Function cnn() As ADODB.Connection '在模块中声明一个接连函数cnn 类型为ADODB连接类型
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DbName;Persist Security Info=False" '建立连接
cnn.Open '打开数据库连接
End Function