Set Fil = Fso.GetFile(App.Path & "\db.ini") '使用活动路径
上面这句话不通。
INI文件中的路径你读取了吗?
上面这句话不通。
INI文件中的路径你读取了吗?
解决方案 »
- VBA应用基础与实例教程
- 这个问题困扰我好多好多天了!!!
- 用过MSComm控件的帮帮忙啊~~~
- 菜鸟问 请问怎么读取数据库中的表字段名,并且重第2列字段开始
- 用vb从sqlserv中导出数据到excel,由于数据量很大如何提高程序的性能(在线等代)
- CrystalReport的问题!急啊!饭碗啊!
- 送分100分:关于去除重复记录的SQL问题
- 有一个两表合并的问题,头大了~~~
- VB关于求图像rbg其中的某一分量在某一范围值的总和.
- 轉換語言
- 请问怎样使ado的recordset根据datagrid的任何改变自动更新数据(而不需要使用update、refresh等命令)?
- 有谁知道模拟键盘(需按键延时)的请进来。
'首先必须定义读取INI文件的API函数
''从INI文件中读写的WINAPI文件定义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 LongDeclare Function writeprivateprofilestring Lib "kerneL32" _
Alias "writeprivateprofilestringa" (ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, lpstring As Any, ByVal lpFilename _
As String) As LongDeclare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer _
, ByVal lParam As Long) As Long‘然后写一函数读取INI文件
''从INI文件中读取数据
Public Function readini(appname, keyname As String, _
filename As String) As String
Dim inireturn As String
inireturn = String(255, Chr(0))
readini = Left(inireturn, GetPrivateProfileString _
(appname, ByVal keyname, "", inireturn, _
Len(inireturn), filename))
End Function’下面的句子读取了INI文件中ACCESS段中定义的数据库位置,你写的要根据需要修改
g_dbname = readini("ACCESS", "dbname", inipath) ''数据库所在目录
g_dbname定义在模块中;sale.ini[parameters]
didian=1
KW=1
FK=3
zd=3
CK=1
shuilv=0.17
xiee=10000
kaipiao=T
gongsi=1[access]
dsn=
dbname=D:\cmis\sale.mdb
dbserver=
其他的一些相应函数
''得到应用程序的当前的位置和路径
Public Function getapppath()
Dim path$
path$ = App.path
If Right$(path$, 1) <> "\" Then path$ = path$ + "\"
getapppath = path$
End Function
inipath = getapppath() & "sale.ini"DBEngine.inipath = inipath
Public cnn As String
Public Conn As ADODB.ConnectionSub Main()
Dim ini1 As New clsIniFile
Dim strFile As String
If App.PrevInstance Then
MsgBox ("程序已经运行,不能再次装载。"), vbExclamation
End
End If
If Not (FileExists(App.Path & "\db.ini")) Then
MsgBox "初始化文件丢失", vbOKOnly, "严重错误"
End
End If
Load frmSplash
frmSplash.Show
delay 0
Screen.MousePointer = vbHourglass
DoEvents
' Load frmMain
' frmMain.Enabled = False
Load frmMain1
frmMain1.Enabled = False
Set Conn = New ADODB.Connection
ini1.File = App.Path & "\db.ini"
strFile = ini1.GetSetting("系统", "数据文件")
If Not FileExists(strFile) Then
MsgBox "数据文件找不到.请首先进行系统设置->数据文件选择,然后退出系统,重新进入.", vbOKOnly, "提示"
With frmMain1
' With frmMain
.mnuQuery.Visible = False
.mnuFund.Visible = False
.mnuEquip.Visible = False
.mnuPublicBase.Visible = False
.Enabled = True
End With
frmLogin.Visible = False
Else
'设置连接字符串
'ACCESS2000格式
' cnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Jet OLEDB:Database Password=lq;Data Source=" & strFile
'ACCESS97格式
cnn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Jet OLEDB:Database Password=lq;Data Source=" & strFile
'打开数据库
frmLogin.Show
On Error GoTo errDB
Conn.Open cnn
On Error GoTo 0
End If
1: Unload frmSplash
Screen.MousePointer = vbArrow
Exit Sub
errDB:
MsgBox "数据文件打不开.请首先进行系统设置->数据文件选择,然后退出系统,重新进入.", vbOKOnly, "提示"
With frmMain1
' With frmMain
.mnuQuery.Visible = False
.mnuFund.Visible = False
.mnuEquip.Visible = False
.mnuPublicBase.Visible = False
.Enabled = True
End With
frmLogin.Visible = False
Resume 1
Exit Sub
End Sub
别的文件使用该数据库都正常