Results 1 to 12 of 12
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Word / ADO (Word 2003)

    It has been my practice to store data in INI-style files. Each user might have 30 or 40 such files, each with 6 "fields". It's an efficient way to store data, and 40 files consume about 15k of disk space.

    I've been thinking about storing this data in a small database. I found some code for creating an MDB table, and I created that easily with the 6 fields which I require. I now need to be able to read, write and delete records. Can someone recommend a good resource for this? My requirements are very basic, but I have no experience with ADO.

    Thanks.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word / ADO (Word 2003)

    When I was learning ADO many years ago, the Access forum was a good place to get advice on particular questions. For a general overview, sites that have articles and tutorials on ASP "Classic" often have useful examples.

    Since you are starting from scratch, have you considered using XML? If you need the query tools of a database, then ADO probably is best. If not, you could use the XML library. Here's an example of how to dump settings into and pull all settings from a very simple XML file: http://www.wopr.com/cgi-bin/w3t/showflat.p...9818#Post343644 (the lost attachment is in the post that follows). In that case, because writing XML can be very verbose/repetitive, I collapsed several values into a "|" delimited string which I then parsed using Split().

    As between the two, I'm not sure there is any appreciable difference in performance. However, XML is easily human-readable and can be altered in a text editor, which can be a plus or a minus.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Word / ADO (Word 2003)

    Thank you for the info. I'm not really starting from scratch. I'm currently using INI-style files to hold the data, and they function beautifully. I hear criticism that they are out-dated and "16 bit." They are efficient, and there is less overhead than reading/writing with XML (which I considered). I do as you have done.... concatenate the data in a single string delimited with "|".

  4. #4
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Word / ADO (Word 2003)

    You've got me interested in XML again. It may be easier than I anticipated, and provide similar functionality to the INI format.

    What version of the XML library do you recommend? I'm writing my code in VBA/Word. I'm not clear on whether version 5 is intended only for XML related to Office documents. Or doesn't it matter?

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Word / ADO (Word 2003)

    I'm not really in a position to recommend a particular version. I haven't had to share code with others, so I'm not sure what compatibility concerns might arise from coding a specific reference.

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Word / ADO (Word 2003)

    Fair enough. Thanks again for the sample code. I have had success using it as a guide, referencing version MSXLM 4.0. System.PrivateProfileString is much easier and perfectly suited to my needs, but others seem to feel I'm out of step with current technology. I hate to sacrifice efficiency just to be au courrant, but I'm giving it a shot. I suppose it makes sense to let go of it before Microsoft drops it.

  7. #7
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Word / ADO (Word 2003)

    Hello Richard
    I am just getting my mind wrapped around creating an INI file and writing to it. Can you provide me with a small example of deleting a key and section?

    Many thanks in advance.
    Regards
    Don

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word / ADO (Word 2003)

    You need the following declaration at the top of the module where you want to use it:
    <code>
    Private Declare Function WritePrivateProfileString _
    Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
    ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, _
    ByVal lpString As Any, _
    ByVal lpFileName As String) As Long
    </code>
    lpApplicationName is the name of the section.
    lpKeyName is the name of the entry.
    lpString is the value
    lpFileName is the path+filename of the ini file.

    To delete an entry, pass vbNullString as lpString (its value):
    <code>
    Sub DeleteEntry()
    WritePrivateProfileString "SectionOne", "EntryFive", vbNullString, "C:Test.ini"
    End Sub
    </code>
    To delete an entire section, pass vbNullString as both lpKeyName and lpString:
    <code>
    Sub DeleteSection()
    WritePrivateProfileString "SectionTwo", vbNullString, vbNullString, "C:Test.ini"
    End Sub</code>

  9. #9
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Word / ADO (Word 2003)

    Thank you for that Hans,

    At the risk of trying your patience; do you happen to know a technique for
    <UL><LI>extracting each of the section names from an ini file; and
    <LI>extracting each of the entry names from a given section.[/list]T.I.A.
    Regards
    Don

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word / ADO (Word 2003)

    To retrieve entries from a section, include the following declaration at the top of the module:
    <code>
    Declare Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringA" ( _
    ByVal sSectionName As String, _
    ByVal sKeyName As String, _
    ByVal sDefault As String, _
    ByVal sReturnedString As String, _
    ByVal lSize As Long, _
    ByVal sFileName As String) As Long
    </code>
    Here is an example of how to use it:
    <code>
    Dim strRet As String
    Dim lngN As Long
    Dim arrValues() As String
    Dim i As Integer
    lngN = 255
    strRet = String(lngN, 0)
    lngN = GetPrivateProfileString("MySection", vbNullString, vbNullString, strRet, lngN, "C:Test.ini")
    arrValues = Split(Left(strRet, lngN), Chr(0))
    For i = 0 To UBound(arrValues) - 1
    Debug.Print arrValues(i)
    Next i
    End Sub</code>

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Word / ADO (Word 2003)

    And to retrieve the section names, add this declaration at the top of the module:
    <code>
    Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll" _
    Alias "GetPrivateProfileSectionNamesA" ( _
    ByVal lpszReturnBuffer As String, _
    ByVal nSize As Long, _
    ByVal lpFileName As String) As Long
    </code>
    Example of use:
    <code>
    Dim strRet As String
    Dim lngN As Long
    Dim arrSections() As String
    Dim i As Integer
    lngN = 255
    strRet = String(lngN, 0)
    lngN = GetPrivateProfileSectionNames(strRet, lngN, "C:Test.ini")
    arrSections = Split(Left(strRet, lngN), Chr(0))
    For i = 0 To UBound(arrSections) - 1
    Debug.Print arrSections(i)
    Next i</code>

  12. #12
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Word / ADO (Word 2003)

    Champion!
    Hans, you are a wonder. <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Regards
    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •