How do i check for the availability of a network path ? 
Author Message
 How do i check for the availability of a network path ?

Glad to be of help.

Any time now someone will pipe up saying that one should not use
Str$() and Val()

- rather one should use 'locale aware' functions like CStr() and
CDbl()

As for not honouring the user's date style selection - that is heresy.

Personally I believe that _where_appropriate_ regional settings should
be selected within an App - and not imposed by the 'environment'.

Overriding VB can get very interesting - one little known feature is
that one can have an 'Objectless' Property :-

in a .BAS module

Public Property Let MyThing( Target$, Value$ )
     Mid$( Target$, 2 ) = Value$
End Property

So one can do :-

   MyThing( Target$ ) = Value$

It means that one can outscope 'assignments' as well as functions.

On Wed, 27 Mar 2002 11:25:46 -0000, "David Maz"

Quote:



>> On Wed, 27 Mar 2002 09:36:03 -0000, "David Maz"

>> <snip>



Sun, 12 Sep 2004 20:15:17 GMT  
 How do i check for the availability of a network path ?


Quote:
> Glad to be of help.

> Any time now someone will pipe up saying that one should not use
> Str$() and Val()

> - rather one should use 'locale aware' functions like CStr() and
> CDbl()

> As for not honouring the user's date style selection - that is heresy.

> Personally I believe that _where_appropriate_ regional settings should
> be selected within an App - and not imposed by the 'environment'.

My software is only used in England.  The users can have any locale settings
they like, all my variables storing dates are dimensioned as strings, not
dates.  I would never alter a users settings.  They can only enter dates in
MY style, namely dd/mm/yyyy.  If they try anything else they get an error
message and prompt to correct the date entry.

A bit draconian, but it stops any errors creeping in and that is what I am
most concerned about.

Regards,

David.



Sun, 12 Sep 2004 20:56:26 GMT  
 How do i check for the availability of a network path ?
On Wed, 27 Mar 2002 12:56:26 -0000, "David Maz"

<snip>

Quote:
>My software is only used in England.  The users can have any locale settings
>they like, all my variables storing dates are dimensioned as strings, not
>dates.  

Sensible - more readable than a Julian/Gregorian
Quote:
>I would never alter a users settings.  

Absolutely - ignoring the settings is fine - altering is well ... a
bit beyond our brief.
Quote:
>They can only enter dates in
>MY style, namely dd/mm/yyyy.  If they try anything else they get an error
>message and prompt to correct the date entry.

Like - 'Nice try but 2002 is not a Leap Year'
Quote:

>A bit draconian, but it stops any errors creeping in and that is what I am
>most concerned about.

Was it Rousseau who said 'Man takes on rules in order to be free'

IME users are pretty adaptable - provided they value the end result.

Quote:

>Regards,

>David.



Sun, 12 Sep 2004 21:16:39 GMT  
 How do i check for the availability of a network path ?


Quote:
> On Wed, 27 Mar 2002 12:56:26 -0000, "David Maz"

> <snip>
> >My software is only used in England.  The users can have any locale
settings
> >they like, all my variables storing dates are dimensioned as strings, not
> >dates.
> Sensible - more readable than a Julian/Gregorian

It is really because I don't trust the windows/microsoft settings to work
properly.  Honestly!

Quote:
> >I would never alter a users settings.
> Absolutely - ignoring the settings is fine - altering is well ... a
> bit beyond our brief.

I have seen software that does it.  I agree that this would be completely
unacceptable.

Quote:
> >They can only enter dates in
> >MY style, namely dd/mm/yyyy.  If they try anything else they get an error
> >message and prompt to correct the date entry.
> Like - 'Nice try but 2002 is not a Leap Year'

Very much along those lines actually.  When writing for lawyers (my case) it
really is very important to trap the most trivial of errors.  I actually
once had trouble with a user complaining (back in 1995) that the software
was using the date 29/02/2000.  (future pension rights projection) and this
was incorrect because centuary years were not leap years.  I told them that
the definition of a leap year was divisble by 400, OR divisible by 4 but not
100 and they did not believe me!
Quote:

> >A bit draconian, but it stops any errors creeping in and that is what I
am
> >most concerned about.
> Was it Rousseau who said 'Man takes on rules in order to be free'

> IME users are pretty adaptable - provided they value the end result.

The way I keep my lot happy is to ask for suggestions for improvement, *and*
listen to them and put them in.

Regards,

David.



Sun, 12 Sep 2004 22:16:49 GMT  
 How do i check for the availability of a network path ?
Hi,

sorry for taking so long but i simply had no time to check any ng
yesterday.

Now ive read all your responses and i must say i am really
impressed by this group. That may be the very first time that i asked
about something in Usenet and REALLY got some nice and explanatory
help. Thank you guys. :)
And no, i dont mind being called a newbie as i do that myself
(to others) when it comes to other stuff then coding VB / VBA :)

I really try to learn from you so please have some patience with me.

Quote:

> The FSO is a scripting utility that most sensible users will not have
> on their machines.

> It does very little more than one can do with pure VB - and just as
> simply.

Ok, i see. I didnt recognize the FSO as being an external supplement
to VBA. M$ Scripting stuff is disabled on all my windows machines at
home too as it gets exploited way to much. But i never tried any of my
programs that i write at work at home because there was no need. :/

The reason why i went for the FSO approach was, that i used the VBA
function "DIR" to check for file and directory presence. I also got their
attributes that way.
But supplied with my network path  (\\server01\bla\bl\") i allways got a
runtime error stating something like "illegal characters in path". So i
assumed that VBs "normal" file handling functions dont support any
kind of network path.
I will try the GetAtr function later today and maybe post my results :P

Sorry for my probably harsh answer but i was kinda confused by
being called a fool without knowing why. Just say "its that bad
M$ scripting stuff again" next time and i will keep my hands off. :)

Quote:
> True I do like writing in pure ASM - unfortunately there is little
> need for that nowadays. It is useful to know what is going on 'under
> the hood'.

Hehe i knew it :) No offense though. I wrote some ASM too, back in
the days of the 8086 up to the time the 286s came out. And i also like
it, if i know exactly where and why mit bits are going. Just recently i
took a course in "programming assembler for the c166 microprocessor"
where that kind of knowledge came in quite handy.
Its just that as of now i am much faster in C and more used to the
language too. If nesessary i can still pull in some inline asm there.

Quote:
> It might be an idea for you to check out what other programmers on the
> NGs think of the FSO - you could find that you change your mind.

Did that :)

Ok now its back to work for me. Thank you again for not being like
the classic Usenet trolls we all came to hate somewhat :)

cya
     Johnny

P.S.: If you happen to find any spelling errors you can keep em.
        (I am not a native english speaker, thats why)



Mon, 13 Sep 2004 17:15:39 GMT  
 How do i check for the availability of a network path ?
Interesting - Dir throwing up problems on Network Drives

Generally it is unwise to use Dir in 'utilities' - this is becase one
Dir loop can effect another.  

That is why we normally recommend the GetAttr method.

However it might be an idea to try the FindFirstFile/FindNextFile API

If you have not already got it then download the API Guide from:
www.AllAPI.net

They have a good example

The FindFirstFile API is a jumped up version of the MSDOS FindFirst
routine - it produces a mass of file information

Here is an implementation - however you'll need to make a minor mod to
get the File Date out correctly.

DrvUtils.bas

Option Explicit

Private Declare Function GetDiskFreeSpace Lib "kernel32" _
        Alias "GetDiskFreeSpaceA" _
        (ByVal lpRootPathName As String, _
         lpSectorsPerCluster As Long, _
         lpBytesPerSector As Long, _
         lpNumberOfFreeClusters As Long, _
         lpTtoalNumberOfClusters As Long) As Long ' (sic)

Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
        Alias "GetDiskFreeSpaceExA" _
        (ByVal lpRootPathName As String, _
         lpFreeBytesAvailableToCaller As Currency, _
         lpTotalNumberOfBytes As Currency, _
         lpTotalNumberOfFreeBytes As Currency) As Long

Private Const MAX_PATH = 260
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_COMPRESSED = &H800
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_SYSTEM = &H4
Private Const FILE_ATTRIBUTE_TEMPORARY = &H100

Private Type FILETIME                   ' Win 32 64bit Type
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Private Type TWIN32_FIND_DATA
        dwFileAttributes As String * 4
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As Currency
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
End Type

Private Declare Function FindFirstFile Lib "kernel32" _
        Alias "FindFirstFileA" _
        (ByVal lpFileName As String, _
        lpFindFileData As TWIN32_FIND_DATA) As Long

Private Declare Function FindNextFile Lib "kernel32" Alias _
        "FindNextFileA" _
        (ByVal hFindFile As Long, _
        lpFindFileData As TWIN32_FIND_DATA) As Long

Private Declare Function FindClose_JF Lib "kernel32" Alias _
        "FindClose" _
        (ByVal hFindFile As Long) As Long

Private Type TINT64
     Lo As Long
     Hi As Long
End Type

Private Type TCURRENCY
     Value As Currency     ' 8 bit / 10000
End Type

'
#########################################################################
'
'
'
Public Function DiskFreeSpaceOld#(Drv$)

   Dim S$, Q#, Result&, Secs&, Bytes&, FreeClusters&

   S$ = Left(Drv$, 2) + "\" + Chr$(0) ' it needs the "\"

   Result = GetDiskFreeSpace(S$, Secs, Bytes, FreeClusters, 0)
   If Result = 0 Then
      DiskFreeSpaceOld# = -1
      GoTo QUIT
   End If

   Q# = Secs * Bytes   ' Cluster Size
   Q# = Q# * FreeClusters
   DiskFreeSpaceOld# = Q#

QUIT:
End Function

' 7/10/01 JF
Public Function DiskFreeSpace#(Drv$)

   S$ = Left(Drv$, 2) + "\" + Chr$(0) ' it needs the "\"
   Result = GetDiskFreeSpaceEx(S$, Available, Free, Total)
   If Result = 0 Then
      DiskFreeSpace = -1
      Exit Function
   End If

   DiskFreeSpace = Free * 10000
End Function

'
#########################################################################
'
'
'
Public Function DiskSizeOld#(Drv$)

   Dim S$, Q#, Result&, Secs&, Bytes&, Clusters&

   S$ = Left(Drv$, 2) + "\" + Chr$(0) ' it needs the "\"

   Result = GetDiskFreeSpace(S$, Secs, Bytes, 0, Clusters)
   If Result = 0 Then
      DiskSizeOld# = -1
      GoTo QUIT
   End If

   Q# = Secs * Bytes   ' Cluster Size
   Q# = Q# * Clusters
   DiskSizeOld# = Q#

QUIT:
End Function

' 7/10/01 JF
Public Function DiskSize#(Drv$)


   S$ = Left(Drv$, 2) + "\" + Chr$(0) ' it needs the "\"

   Result = GetDiskFreeSpaceEx(S$, Available, Free, Total)
   If Result = 0 Then
      DiskSize# = -1
      Exit Function
   End If

   DiskSize# = Total * 10000

QUIT:
End Function

'
#########################################################################
'
'
'
Public Function FindFirst$(FileSpec$, FileSize#, FileAtt%, Handle&)

   Dim DTA As TWIN32_FIND_DATA, I64 As TINT64, C As TCURRENCY

   Handle& = FindFirstFile(FileSpec$ + Chr$(0), DTA)
   If Handle& Then
      FindFirst$ = StrExtStr(DTA.cFileName, Chr$(0), 1)
      I64.Hi = DTA.nFileSizeHigh
      I64.Lo = DTA.nFileSizeLow
      LSet C = I64
      FileSize# = C.Value * 10000
      FileAtt% = Asc(DTA.dwFileAttributes)
   End If

End Function

'
#########################################################################
'
'
'
Public Function FindNext$(Handle&, FileSize#, FileAtt%)

   Dim DTA As TWIN32_FIND_DATA, I64 As TINT64, C As TCURRENCY

   If FindNextFile(Handle&, DTA) Then
      FindNext$ = StrExtStr(DTA.cFileName, Chr$(0), 1)
      I64.Hi = DTA.nFileSizeHigh
      I64.Lo = DTA.nFileSizeLow
      LSet C = I64
      FileSize# = C.Value * 10000
      FileAtt% = Asc(DTA.dwFileAttributes)
   End If

End Function

'
#########################################################################
'
'
'
Public Function FindClose&(Handle&)

   FindClose& = FindClose_JF(Handle&)

End Function

'
#########################################################################
'
' The FILETIME structure is a 64-bit value representing
' the number of 100-nanosecond intervals since January 1, 1601.
'
' This returns the number of Seconds elapsed
' -1 if file not found
'
Function FileDateTimeSecs#(FileSpec$)

   Dim DTA As TWIN32_FIND_DATA, S$, Handle&, Result#

   Handle& = FindFirstFile(FileSpec$ + Chr$(0), DTA)
   If Handle& Then
      Result# = DTA.ftLastWriteTime
      ' 100 Nano Secs - to Secs  10^-9
      Result# = Int(Result# / 1000)
      Call FindClose&(Handle&)
   End If

   FileDateTimeSecs# = -1
   If Result# Then
      FileDateTimeSecs# = Result#
   End If

End Function

'
#########################################################################
'
' Return a 70000 number and Time of a files last altered date
'
Sub FileDateTimeNo(FileSpec$, DateNo&, Hours&, Mins&, Secs&)

    Static BaseNo&
    Dim dSecs#, dMins#, dHours#, dDays#

    dSecs# = FileDateTimeSecs(FileSpec$)
    If dSecs# = -1 Then
       DateNo = -1
       Hours = 0
       Mins = 0
       Secs = 0
       GoTo QUIT
    End If

    dMins# = Int(dSecs# / 60)    ' to Minutes
    dHours# = Int(dMins# / 60)   ' to Hours
    dDays# = Int(dHours# / 24)   ' to Days

    Secs = dSecs - dMins * 60
    Mins = dMins - dHours * 60
    Hours = dHours - dDays * 24

    ' --- You'll need to modify this
    If BaseNo = 0 Then
       ' BaseNo = DateToNo("01-01-1601")
    End If

    DateNo = dDays + BaseNo + 3

QUIT:
End Sub



<snip>



Mon, 13 Sep 2004 18:53:28 GMT  
 How do i check for the availability of a network path ?

Quote:

> Its just that as of now i am much faster in C and more used to the
> language too. If nesessary i can still pull in some inline asm there.

What if the network volume goes away right after you check its
availability but before you can write your file, or whatever?

Quote:
> > It might be an idea for you to check out what other programmers on the
> > NGs think of the FSO - you could find that you change your mind.

> Did that :)

Did you find the "Accidental Compatibility" option Microslop
seems to use in SCRRUN's project file?

--
Joe Foster <mailto:jlfoster%40znet.com>     Got Thetans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Tue, 14 Sep 2004 07:11:16 GMT  
 How do i check for the availability of a network path ?


Quote:
>Both Terry and Frank have explained the major reason why it is unwise
>to use the FSO

This has been an interesting thread - I've done some reading around
the various sites and it seems there are a lot of ways to do this
checking, I just thought I'd throw in the fact that I've decided to
use the API FindFirstFile to check drive, directory and file existance
and GetFileAttributes to check if the file is read only - do you feel
I'm now on safer ground than I was with the FSO?

Marshal



Wed, 15 Sep 2004 08:40:00 GMT  
 How do i check for the availability of a network path ?


Quote:
> Both Terry and Frank have explained the major reason why it is unwise
> to use the FSO

Just out of curiosity, have you heard of any similar problems, especially
security ones, related to ADODB.Stream? (Though this applies to
VBScript, but I'll ask here anyway cuz you guys are so smart.)

Terry Austin



Wed, 15 Sep 2004 09:00:05 GMT  
 How do i check for the availability of a network path ?

Quote:



>>Both Terry and Frank have explained the major reason why it is unwise
>>to use the FSO

>This has been an interesting thread - I've done some reading around
>the various sites and it seems there are a lot of ways to do this
>checking, I just thought I'd throw in the fact that I've decided to
>use the API FindFirstFile to check drive, directory and file existance
>and GetFileAttributes to check if the file is read only - do you feel
>I'm now on safer ground than I was with the FSO?

Yup - *much* safer ground - and in a few weeks you'll have created Bas
modules and Classes that do all the 'nice' things that the FSO does -
but you will 'own' them.

The next thing is to make/get Classes to implement all the
CommonDialog APIs - and you'll get rid of another hooky OCX

Quote:

>Marshal



Wed, 15 Sep 2004 17:23:15 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 
 

 
Powered by phpBB® Forum Software