Welcome Guest!
 VB 6 Helper
 Previous Message All Messages Next Message 
VB 6 Helper Newsletter  Rod Stephens
 Jun 27, 2009 08:29 PDT 

Microsoft is pushing Windows 7 early. For a limited time only (until
July 11 "or while supplies last" (How can they run out? Did Microsoft
only give them permission to sell a certain number of copies? Seems hard
to believe that Microsoft would want to restrict the number of people
signing on early.) you can pre-order Windows 7 for at least 50% off at
Amazon. Here are some links:

    Windows 7 Resource Center
    http://www.amazon.com/b/?node=1286119011&tag=vbhelper

    Windows7 Home Premium Upgrade
    
http://www.amazon.com/Microsoft-GFC-00020-W7HPU/dp/B002DHLUWK?tag=vbhelper


    Windows7 Professional Upgrade
    
http://www.amazon.com/Microsoft-GFC-00020-W7HPU/dp/B002DHGM50?tag=vbhelper


In fact, I'll be without my computer for a few days because I'm having
the hard disk enlarged to make room for a Windows 7 partition in
addition to my existing XP and Vista partitions. (They must have some
sort of stretching machine to enlarge the disk.)
----------
People posted two new reviews of my book "Visual Basic 2008 Programmer's
Reference"
(http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/). Thanks!

Also if you have a copy of my book "Beginning Database Design Solutions"
(http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/), please
post a review when you have a few moments.
----------
Have a great week and thanks for subscribing!

Rod
RodSte-@vb-helper.com

Books To Keep: http://www.BooksToKeep.com
----------
*** Now Available ***

Beginning Database Design Solutions
http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/

Visual Basic 2008 Programmer's Reference
http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
==========

    VB6 Contents:
1. Updated Tip: Use ADOX to make a database without leaving the database
files locked
2. Updated HowTo: Set a file's creation, last access, and last modified
times

    Both Contents:
3. New Tip: Use proper data delimiters for different databases
==========
++++++++++
   <VB6>
++++++++++
==========
1. Updated Tip: Use ADOX to make a database without leaving the database
files locked
http://www.vb-helper.com/tip_adox_make_db_unlocked.html

This tip comes from Adam Kelly who says:

This drove me nuts for hours so I am passing the tip on.....

If you use ADOX to make a database with the following code snippet then
.net leaves the database connection open and a .ldb file remains. That
means regardless you cannot compact and repair the database or do
ANYTHING that requires exclusive access to the database! Very annoying!

    Friend Sub MakeDB(ByVal strDBPathAndName As String)
        Dim cat As ADOX.Catalog

        Cat = New ADOX.Catalog
        cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& strDBPathAndName & ";")
        cat = Nothing
    End Sub

Here is the fix, add the line:

    CType(cat.ActiveConnection, ADODB.Connection).Close()

SO my question is WHY do I have to cast a connection "close" to the
catalog Active connection? Why is there not a cat.ActiveConnection.close
OR better yet cat.Close?????? This is at the least bad design by MS or
worse a bug!

    Friend Sub MakeDB(ByVal strDBPathAndName As String)
        Dim cat As ADOX.Catalog

        Cat = New ADOX.Catalog
        cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="
& strDBPathAndName & ";")
        CType(cat.ActiveConnection, ADODB.Connection).Close()
        cat = Nothing
    End Sub

Bottom line if you ever use a ADOX.Catalog then make sure you close it
after use as outlined above or you will leave a pool of open connections
to the database!
==========
2. Updated HowTo: Set a file's creation, last access, and last modified
times
http://www.vb-helper.com/howto_set_file_times.html
http://www.vb-helper.com/HowTo/howto_set_file_times.zip

Thanks to Timothy Ward for finding a bug in the SetFileTimes subroutine.
(It was using GENERIC_READ instead of GENERIC_WRITE to open the file.)

Function GetFileTimes uses the GetFileTime API function to read the
file's times. If necessary, it uses the FileTimeToLocalFileTime API
function to convert the results into local times.

' Return True if there is an error.
Private Function GetFileTimes(ByVal file_name As String, _
    ByRef creation_date As Date, ByRef access_date As Date, _
    ByRef modified_date As Date, ByVal local_time As _
    Boolean) As Boolean
Dim file_handle As Long
Dim creation_filetime As FILETIME
Dim access_filetime As FILETIME
Dim modified_filetime As FILETIME
Dim file_time As FILETIME

    ' Assume something will fail.
    GetFileTimes = True

    ' Open the file.
    file_handle = CreateFile(file_name, GENERIC_READ, _
        FILE_SHARE_READ Or FILE_SHARE_WRITE, _
        0&, OPEN_EXISTING, 0&, 0&)
    If file_handle = 0 Then Exit Function

    ' Get the times.
    If GetFileTime(file_handle, creation_filetime, _
        access_filetime, modified_filetime) = 0 Then
        CloseHandle file_handle
        Exit Function
    End If

    ' Close the file.
    If CloseHandle(file_handle) = 0 Then Exit Function

    ' See if we should convert to the local
    ' file system time.
    If local_time Then
        ' Convert to local file system time.
        FileTimeToLocalFileTime creation_filetime, file_time
        creation_filetime = file_time

        FileTimeToLocalFileTime access_filetime, file_time
        access_filetime = file_time

        FileTimeToLocalFileTime modified_filetime, file_time
        modified_filetime = file_time
    End If

    ' Convert into dates.
    creation_date = FileTimeToDate(creation_filetime)
    access_date = FileTimeToDate(access_filetime)
    modified_date = FileTimeToDate(modified_filetime)

    GetFileTimes = False
End Function

Function SetFileTimes converts local times into file times. See the code
to learn how DateToFileTime works. It then uses the SetFileTime API
function to set the file's times.

' Return True if there is an error.
Private Function SetFileTimes(ByVal file_name As String, _
    ByVal creation_date As Date, ByVal access_date As Date, _
    ByVal modified_date As Date, ByVal local_times As _
    Boolean) As Boolean
Dim file_handle As Long
Dim creation_filetime As FILETIME
Dim access_filetime As FILETIME
Dim modified_filetime As FILETIME
Dim file_time As FILETIME

    ' Assume something will fail.
    SetFileTimes = True

    ' Convert the dates into FILETIMEs.
    creation_filetime = DateToFileTime(creation_date)
    access_filetime = DateToFileTime(access_date)
    modified_filetime = DateToFileTime(modified_date)

    ' Convert the file times into system file times.
    If local_times Then
        LocalFileTimeToFileTime creation_filetime, file_time
        creation_filetime = file_time

        LocalFileTimeToFileTime access_filetime, file_time
        access_filetime = file_time

        LocalFileTimeToFileTime modified_filetime, file_time
        modified_filetime = file_time
    End If

    ' Open the file.
    file_handle = CreateFile(file_name, GENERIC_WRITE, _
        FILE_SHARE_READ Or FILE_SHARE_WRITE, _
        0&, OPEN_EXISTING, 0&, 0&)
    If file_handle = 0 Then Exit Function

'creation_date = FileTimeToDate(creation_filetime)

    ' Set the times.
    If SetFileTime(file_handle, creation_filetime, _
        access_filetime, modified_filetime) = 0 Then
        CloseHandle file_handle
        Exit Function
    End If

    ' Close the file.
    If CloseHandle(file_handle) = 0 Then Exit Function

    SetFileTimes = False
End Function

See the code for other details such as time format conversions.
==========
++++++++++
<Both>
++++++++++
==========
3. New Tip: Use proper data delimiters for different databases
http://www.vb-helper.com/tip_database_date_delimiters.html

In SQL statements, all databases use quotes to delimit strings but
different databases use different delimiters for dates. This is one of
the most common problems when trying to port database code from Access
to SQL Server or vice versa but at least it's easy to fix once you
understand what the problem is.

    * SQL Server uses quotes (') as in '4/1/2010'
    * Access (Jet) uses number signs (#) as in #4/1/2010#
==========
Archives:
    http://www.topica.com/lists/VBHelper
    http://www.topica.com/lists/VB6Helper
    http://www.topica.com/lists/VBNetHelper

Post questions at:
    http://www.topica.com/lists/VBHelperQA
	
 Previous Message All Messages Next Message 
  Check It Out!

  Topica Channels
 Best of Topica
 Art & Design
 Books, Movies & TV
 Developers
 Food & Drink
 Health & Fitness
 Internet
 Music
 News & Information
 Personal Finance
 Personal Technology
 Small Business
 Software
 Sports
 Travel & Leisure
 Women & Family

  Start Your Own List!
Email lists are great for debating issues or publishing your views.
Start a List Today!

© 2001 Topica Inc. TFMB
Concerned about privacy? Topica is TrustE certified.
See our Privacy Policy.