某些程序运行中需要大量存取数据,以前问过得到2种解决方案,一是用INI文件做中介,另一种是用EXCEL文件做中介,前者不便于后端维护,后者存取大量数据发现速度较慢,且2种方案都要写大量代码,有没有既方便又快捷的方法呢?我想用数据库文件应该能解决问题!但不知怎样"引用"?
下面建个简单模型来探讨一下!目标:从某外部文件取出3组数据,将其和显示在Text1上。用EXCEL做外部文件(目录D:\Data.Xls,3组数据分别在B3、B4和B5上),代码如下:Private Sub Command1_Click()
Text1.Text = Val(GetData1) + Val(GetData2) + Val(GetData3)
End SubPrivate Function GetData1() As String
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1) '设置活动工作表
GetData1 = xlSheet.Range("$B$3")
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
End FunctionPrivate Function GetData2() As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1)
GetData2 = xlSheet.Range("$B$4")
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End FunctionPrivate Function GetData3() As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1)
GetData3 = xlSheet.Range("$B$5")
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End Function那么用Access数据库做外部文件应该怎样实现上述目标呢?
下面建个简单模型来探讨一下!目标:从某外部文件取出3组数据,将其和显示在Text1上。用EXCEL做外部文件(目录D:\Data.Xls,3组数据分别在B3、B4和B5上),代码如下:Private Sub Command1_Click()
Text1.Text = Val(GetData1) + Val(GetData2) + Val(GetData3)
End SubPrivate Function GetData1() As String
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1) '设置活动工作表
GetData1 = xlSheet.Range("$B$3")
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
End FunctionPrivate Function GetData2() As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1)
GetData2 = xlSheet.Range("$B$4")
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End FunctionPrivate Function GetData3() As String
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1)
GetData3 = xlSheet.Range("$B$5")
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End Function那么用Access数据库做外部文件应该怎样实现上述目标呢?
解决方案 »
- 救助有没有什么好的关于DataReport的书或实例!!!!!!!!!!!
- 初学VB者的问题?
- VB访问其他机器的指定目录,要输入用户名何密码,能否通过API在程序里验证??
- data的刷新问题
- 怎么样把DataGrid1里显示的数据全部打印出来?
- 很菜的,关于窗体的问题
- 有关类似数字地图的东西。
- c#中的Math.Atan2(v, u)在VB中该怎么写啊
- ~~~h-e--l--p.......~~~~~~ 锁类型为adlockpessimistic 意味着多人不许修改,添加,但....这是为什么????? 求助: foolishtiger(吴文智),阿木等高手!!谢谢!!!
- 请问在什么地方能找到制作chm文件的软件?请E_mail给我[email protected] .谢谢!!!
- web桌面与注册表,急~
- 托盘代码
Private Sub Command1_Click()
Text1.Text = Val(GetData(1)) + Val(GetData(2)) + Val(GetData(3))
End Sub
Private Function GetData() As String
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1) '设置活动工作表
GetData(1) = xlSheet.Range("$B$3")
GetData(2) = xlSheet.Range("$B$4")
GetData(3) = xlSheet.Range("$B$5")
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
End Function
Private Sub Command1_Click()
call getdata()
Text1.Text = data1+ data2+ data3
End Sub
Private Function GetData() As String
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.open("D:\Data.Xls")
Set xlSheet = xlBook.Worksheets(1) '设置活动工作表
data1 = xlSheet.Range("$B$3")
data2 = xlSheet.Range("$B$4")
data3 = xlSheet.Range("$B$5")
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
Set xlApp = Nothing '释放xlApp对象
End Function