PDA

View Full Version : VBA comma method?



theta
07-05-2012, 04:10 AM
I was playing around with this simple code - but wondered what the convention is for , "CheckDongle" as I have not seen a sub called this way before?

I am now looking at different referencing methods e.g. Range("A1:Z10") (1,3) instead of cells (or using [A1]) as I would like my code to be more efficient.

Any help appreciated



Public Sub CheckDongle()
'check that a file exists, if it doesn't then close Excel, if it does check again in 15 seconds
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("c:\test.txt") = False Then
Application.Quit
Else
Application.OnTime Now + TimeValue("00:00:15"), "CheckDongle"
End If
Set fs = Nothing
End Sub

snb
07-05-2012, 04:32 AM
Sub CheckDongle()
If Dir("c:\test.txt")="" Then
Application.Quit
Else
Application.OnTime dateadd("s",15,Now), "CheckDongle"
End If
End Sub

Bob Phillips
07-05-2012, 04:43 AM
You are not just calling CheckDongle, you are issuing a delayed call, that is it waits 15 seconds before the procedure is invoked again.

I see nothing there about ranges in that code, so what are you trying to achieve?

theta
07-05-2012, 04:58 AM
Sorry I was referring specifically to the , "CheckDongle"

I would normally Call or Run the sub. I haven't seen this method before of enclosing a sub call within "" "" ?

I mentioned the ranges as this is part of my exploratory phase of investigating different methods of referencing and calling.

Bob Phillips
07-05-2012, 05:13 AM
It is in quotes because the OnTime method requires the name of the procedure that it will invoke, which means text, which means quotes if a variable is not used.

But, you should only use this method if you require a delayed call, otherwise Call is far better.

snb
07-05-2012, 08:37 AM
All the information on 'ontime' is available in the VBEditor's help files. (F1)