Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Implement time-out

Hi,

I'm using following code witch work fine to select a file on a remote
PC, connected via network.
But there's one withdraw:
If the remote PC is too busy, or the network connection fails, there's
no time-out to escape from the routine.
Question now is if it's possible to implement a time-out so that i can
bail out of the routine, and if possible, how to do it.

frmSelectFMT_Log_Kast.Show
If blCancelSelect = False Then Exit Sub
With Application.FileDialog(msoFileDialogOpen)
If inHassKast = 1 Then
.InitialFileName = FMT_LogFiles1 'FMT LOG files kast
1 !!!
.Title = "FMT LOG files kast 1"
Else
.InitialFileName = FMT_LogFiles2 'FMT LOG files kast
2 !!!
.Title = "FMT LOG files kast 2"
End If
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.Show
'<< hangs when network down or PC too busy to answer
If .SelectedItems.Count = 0 Then Exit Sub
FName = .SelectedItems(1)
End With

Any help is welcome.
Regards,
Ludo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Implement time-out

Ludo was thinking very hard :
Hi,

I'm using following code witch work fine to select a file on a remote
PC, connected via network.
But there's one withdraw:
If the remote PC is too busy, or the network connection fails, there's
no time-out to escape from the routine.
Question now is if it's possible to implement a time-out so that i can
bail out of the routine, and if possible, how to do it.

frmSelectFMT_Log_Kast.Show
If blCancelSelect = False Then Exit Sub
With Application.FileDialog(msoFileDialogOpen)
If inHassKast = 1 Then
.InitialFileName = FMT_LogFiles1 'FMT LOG files kast
1 !!!
.Title = "FMT LOG files kast 1"
Else
.InitialFileName = FMT_LogFiles2 'FMT LOG files kast
2 !!!
.Title = "FMT LOG files kast 2"
End If
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
.Show
'<< hangs when network down or PC too busy to answer
If .SelectedItems.Count = 0 Then Exit Sub
FName = .SelectedItems(1)
End With

Any help is welcome.
Regards,
Ludo


You couldcheck to see if the network drive is available beforehand
using the following function.

' PathExists()
' Checks if a path to a folder exists.
' Arguments: sPath The full path to search
' Returns: TRUE if sPath exists AND is available
Function PathExists(sPath As String) As Boolean
On Error Resume Next
' "\nul" appended to the path makes it work with empty folders
PathExists = (Dir$(sPath & "\nul") < "")
End Function

To use it...

Sub DoStuff()
If PathExists("\\Server\Share") Then
'//do stuff
End If 'PathExists("\\Server\Share")
End Sub

...which only executes your code if the path exists AND is available.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Implement time-out

Optional usage...

Sub DoStuff()
If PathExists("\\Server\Share") Then
'//do stuff

Else
Dim sMsg As String
sMsg = "The network drive is not available." & vbCrLf
sMsg = sMsg & "Please try again later!"
MsgBox sMsg, vbExclamation
End If 'PathExists("\\Server\Share")
End Sub

..which only executes your code if the path exists AND is available.


--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Implement time-out

On 31 aug, 15:31, GS wrote:
Optional usage...

* Sub DoStuff()
* * If PathExists("\\Server\Share") Then
* * * '//do stuff


* * * Else
* * * * Dim sMsg As String
* * * * sMsg = "The network drive is not available." & vbCrLf
* * * * sMsg = sMsg & "Please try again later!"
* * * * MsgBox sMsg, vbExclamation

* * End If 'PathExists("\\Server\Share")
* End Sub


..which only executes your code if the path exists AND is available.


--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Thanks Gary!

Just needed to change PathExists = '(Dir$(sPath & "\nul") < "") into
PathExists = (Dir$(sPath & "\*.log") < "") to get it working.
Otherwise it returned always FALSE.


Keep up the good work!

Regards,
Ludo

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Implement time-out

on 8/31/2011, Ludo supposed :
On 31 aug, 15:31, GS wrote:
Optional usage...

* Sub DoStuff()
* * If PathExists("\\Server\Share") Then
* * * '//do stuff


* * * Else
* * * * Dim sMsg As String
* * * * sMsg = "The network drive is not available." & vbCrLf
* * * * sMsg = sMsg & "Please try again later!"
* * * * MsgBox sMsg, vbExclamation

* * End If 'PathExists("\\Server\Share")
* End Sub


..which only executes your code if the path exists AND is available.


--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Thanks Gary!

Just needed to change PathExists = '(Dir$(sPath & "\nul") < "") into
PathExists = (Dir$(sPath & "\*.log") < "") to get it working.
Otherwise it returned always FALSE.


Keep up the good work!

Regards,
Ludo


That means you're testing for files, NOT a path. In this case I suggest
you use the following function instead, leaving the PathExists function
unchanged.

' Checks if a file exists in the specified folder
' Arguments: fileName The fullname of the file
' Returns: TRUE if the file exists
Function bFileExists(Filename As String) As Boolean
On Error Resume Next
bFileExists = (Dir$(Filename) < "")
' bFileExists = (FileLen(Filename) < 0) '//optional method
End Function

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How best to integrate/implement this? Ed from AZ Excel Programming 2 December 10th 08 09:06 PM
WNetGetUniversalName - how to implement in VBA? KR Excel Programming 1 March 16th 06 03:48 PM
how to implement xbrl mariano Excel Discussion (Misc queries) 0 January 18th 06 02:00 PM
Do anyone know how to implement the function? minrufeng[_3_] Excel Programming 2 August 12th 05 07:38 PM
How to implement an iRtdServer? Hans Guijt Excel Programming 4 October 24th 04 07:17 AM


All times are GMT +1. The time now is 08:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"