转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
DAO Advanced Programming         ★★★★

DAO Advanced Programming

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3927 更新时间:2009/4/23 16:38:42
nteger) As Integer '''' Comments : Dumps the database structure to a text file '''' In : strFile - path and name of file '''' fProperties - true to dump properties '''' fErrors - true to write errors '''' Out : True/False - success/failure '''' Revisions '''' 04/08/96 djh initial version '''' Dim dbsCurrent As Database Dim tdfTmp As TableDef Dim fldTmp As Field Dim qdfTmp As QueryDef Dim relTmp As Relation Dim idxTmp As Index Dim cntTmp As Container Dim docTmp As Document Dim prpTmp As Property Dim intCounter As Integer Dim intBCounter As Integer Dim intCCounter As Integer Dim intPCounter As Integer '''' Delete the output file On Error Resume Next Kill strFile On Error GoTo fDumpDAO_Err '''' Initialize intFileOut = FreeFile Open strFile For Output As intFileOut Set dbsCurrent = CurrentDB() lngLines = 0 '''' Write the database info Call WriteOutput("FMS DAO Dumper Version " & FMSVersion, 0) Call WriteOutput("Generated: " & Now, 0) Call WriteOutput("--------------------------------------------------------------------", 0) If fProps Then For intPCounter = 0 To dbsCurrent.Properties.Count - 1 Set prpTmp = dbsCurrent.Properties(intPCounter) Call WriteProps(prpTmp, 1) Next intPCounter End If '''' Iterate the Tabledefs collection For intCounter = 0 To dbsCurrent.Tabledefs.Count - 1 Set tdfTmp = dbsCurrent.Tabledefs(intCounter) Call WriteOutput("TABLE: " & tdfTmp.Name, 1) If fProps Then For intPCounter = 0 To tdfTmp.Properties.Count - 1 Set prpTmp = tdfTmp.Properties(intPCounter) Call WriteProps(prpTmp, 2) Next intPCounter End If '''' Iterate the fields collection For intBCounter = 0 To tdfTmp.Fields.Count - 1 Set fldTmp = tdfTmp.Fields(intBCounter) Call WriteOutput("TABLE FIELD: " & fldTmp.Name, 2) If fProps Then For intPCounter = 0 To fldTmp.Properties.Count - 1 Set prpTmp = fldTmp.Properties(intPCounter) Call WriteProps(prpTmp, 3) Next intPCounter End If Next intBCounter '''' Iterate the Indexes collection For intBCounter = 0 To tdfTmp.Indexes.Count - 1 Set idxTmp = tdfTmp.Indexes(intBCounter) Call WriteOutput("INDEX: " & idxTmp.Name, 2) If fProps Then For intPCounter = 0 To idxTmp.Properties.Count - 1 Set prpTmp = idxTmp.Properties(intPCounter) Call WriteProps(prpTmp, 3) Next intPCounter End If '''' Iterate the index fields collection For intCCounter = 0 To idxTmp.Fields.Count - 1 Set fldTmp = idxTmp.Fields(intCCounter) Call WriteOutput("INDEX FIELD: " & fldTmp.Name, 3) If fProps Then For intPCounter = 0 To fldTmp.Properties.Count - 1 Set prpTmp = fldTmp.Properties(intPCounter) Call WriteProps(prpTmp, 4) Next intPCounter End If Next intCCounter Next intBCounter Next intCounter '''' Iterate the Relations collection For intCounter = 0 To dbsCurrent.Relations.Count - 1 Set relTmp = dbsCurrent.Relations(intCounter) Call WriteOutput("RELATION: " & relTmp.Name, 1) If fProps Then For intPCounter = 0 To relTmp.Properties.Count - 1 Set prpTmp = relTmp.Properties(intPCounter) Call WriteProps(prpTmp, 2) Next intPCounter End If '''' Iterate the fields collection For intBCounter = 0 To relTmp.Fields.Count - 1 Set fldTmp = relTmp.Fields(intBCounter) Call WriteOutput("RELATION FIELD: " & fldTmp.Name, 2) If fProps Then For intPCounter = 0 To fldTmp.Properties.Count - 1 Set prpTmp = fldTmp.Properties(intPCounter) Call WriteProps(prpTmp, 2) Next intPCounter End If Next intBCounter Next intCounter '''' Iterate the querydefs collection For intCounter = 0 To dbsCurrent.Querydefs.Count - 1 Set qdfTmp = dbsCurrent.Querydefs(intCounter) Call WriteOutput("QUERY: " & qdfTmp.Name, 1) If fProps Then For intPCounter = 0 To qdfTmp.Properties.Count - 1 Set prpTmp = qdfTmp.Properties(intPCounter) Call WriteProps(prpTmp, 2) Next intPCounter End If '''' Iterate the fields collection For intBCounter = 0 To qdfTmp.Fields.Count - 1 Set fldTmp = qdfTmp.Fields(intBCounter) Call WriteOutput("QUERY FIELD: " & fldTmp.Name, 2) If fProps Then For intPCounter = 0 To fldTmp.Properties.Count - 1 Set prpTmp = fldTmp.Properties(intPCounter) Call WriteProps(prpTmp, 2) Next intPCounter End If Next intBCounter Next intCounter '''' Iterate the Containers collection For intCounter = 0 To dbsCurrent.Containers.Count - 1 Set cntTmp = dbsCurrent.Containers(intCounter) Call WriteOutput("CONTAINER: " & cntTmp.Name, 1) If fProps Then For intPCounter = 0 To cntTmp.Properties.Count - 1 Set prpTmp = cntTmp.Properties(intPCounter) Call WriteProps(prpTmp, 2) Next intPCounter End If '''' Iterate the Documents collection For intBCounter = 0 To cntTmp.Documents.Count - 1 Set docTmp = dbsCurrent.Containers(intCounter).Documents(intBCounter) Call WriteOutput("DOCUMENT: " & docTmp.Name, 2) If fProps Then For intPCounter = 0 To docTmp.Properties.Count - 1 Set prpTmp = docTmp.Properties(intPCounter) Call WriteProps(prpTmp, 3) Next intPCounter End If Next intBCounter Next intCounter fDumpDAO = True Close intFileOut fDumpDAO_Exit: Exit Function fDumpDAO_Err: If fErrors Then WriteOutput "************** Error: " & Error$, 0 End If Resume Next End Function Sub Form_Open (Cancel As Integer) Me!lblVersion.Caption = "Version " & FMSVersion Me!txtFileName = "C:\DAO_DUMP.TXT" Me!chkProperties = True Me!chkErrors = True Me!txtTabs = 4 End Sub Sub WriteOutput (strOut As String, intIndent As Integer) '''' Comments : Writes the string out to the file '''' In : strOut - string to write '''' intIndent - number of indents '''' Out '''' Revisions '''' Dim strTabs As String strTabs = Space(intIndent * intTabs) Print #intFileOut, strTabs & strOut lngLines = lngLines + 1 End Sub Sub WriteProps (prpIn As Property, intIndent As Integer) '''' Comments : Writes the name and value of the supplied property '''' In : prpIn - property object '''' intIndent - number of indents (hobo variable) '''' Out : '''' Revisions '''' Dim intSaveErr As Integer Dim strSaveErr As String Dim strName As String Dim varVal As Variant '''' Disable error handler On Error Resume Next '''' Get the property name and value strName = prpIn.Name varVal = prpIn.Value intSaveErr = Err strSaveErr = Error$ '''' Reset error handler On Error GoTo 0 If intSaveErr = 0 Then Call WriteOutput(strName & ": " & varVal, intIndent) Else If fErrors Then Call WriteOutput("************** " & strName & ": Error (" & strSaveErr & ")", intIndent) End If End If End Sub

The Access 95/VBA Way

Now let''''s look at the VBA implementation of the same code base. You can see that code is much more efficient because we can now use "late binding"-that is we can Dim Foo As Object, and pass that Object around to subroutines. Also, we can use the For Each…Next construct to walk through collections:

Option Explicit
Dim intFileOut As Integer
Dim fErrors As Integer
Dim intTabs As Integer
Dim lngLines As Long
Const FMSVersion = "7.0"
Private Sub cmdCancel_Click()
  DoCmd.Close
End Sub
Private Sub cmdClose_Click()
  DoCmd.Close
End Sub
Private Sub cmdNotepad_Click()
  Dim x As Variant
  x = Shell("write.exe " & Me!txtFileName, 1)
End Sub
Private Sub cmdStart_Click()
  Dim fOK As Integer
  
  If Me!txtFileName <> "" Then
    If Me!txtTabs <> "" Then
      intTabs = Me!txtTabs
    End If
    DoCmd.Hourglass True
    DoCmd.GoToPage 2
    fOK = fDumpDAO(CStr(Me!txtFileName), CInt(Me!chkProperties), CInt(Me!chkErrors))
    Me!cmdNotepad.Enabled = True
    DoCmd.Hourglass False
    Me!txtLines.Caption = lngLines & " lines were written to file: " & Me!txtFileName
    DoCmd.GoToPage 3
  End If
End Sub
Private Function fDumpDAO(strFile As String, fProps As Integer, fErrors As Integer) As Integer
  '''' Comments  : Dumps the database structure to a text file
  '''' In        : strFile     - path and name of file
  ''''             fProperties - true to dump properties
  ''''             fErrors     - true to write errors
  '''' Out       : True/False  - success/failure
  '''' Revisions
  '''' 04/08/96 djh initial version
  ''''
  Dim dbsCurrent As DATABASE
  Dim tdfTmp As TableDef
  Dim fldTmp As Field
  Dim qdfTmp As QueryDef
  Dim relTmp As Relation
  Dim idxTmp As INDEX
  Dim cntTmp As Container
  Dim docTmp As Document
  Dim prpTmp As Property
  Dim intCounter As Integer
  Dim intBCounter As Integer
  Dim intCCounter As Integer
  Dim intPCounter As Integer
  '''' Delete the output file
  On Error Resume Next
  Kill strFile
  On Error GoTo fDumpDAO_Err
  '''' Initialize
  intFileOut = FreeFile
  Open strFile For Output As intFileOut
  Set dbsCurrent = CurrentDb()
  lngLines = 0
  '''' Write the database info
  Call WriteOutput("FMS DAO Dumper Version " & FMSVersion, 0)
  Call WriteOutput("Generated: " & Now, 0)
  Call WriteOutput("--------------------------------------------------------------------", 0)
  If fProps Then Call WriteProps(dbsCurrent, 1)
  '''' Iterate the Tabledefs collection
  For Each tdfTmp In dbsCurrent.TableDefs
    Call WriteOutput("TABLE:

上一页  [1] [2] [3] [4] [5]  下一页


[常用软件]Dao ne Deepnet 三合一的浏览器 浏览器  [Web开发]DAO RDO ADO ADO.NET
[Sql Server]ASP编程入门进阶(廿一):DAO SQL之建立数据库表  
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台