Discussion:
Newbie question about nested subroutines
(too old to reply)
Dimmer
2011-10-06 18:48:15 UTC
Permalink
Hi all

I am trying to arrange to access this sub a number of times in a program.

The sub works fine in intercepting ESC and certain other keystrokes.

I want to somehow arrange to repeatedly use it and this instictively
suggests that it should be in a subroutine. But it is already in one! Is
there such a thing as nested subroutines? I want to call it and pass to it
the particular Textboxes and Label concerned. I emphasise that it works
fine but I just don't want to have to have it appearing 13 times in a 13
field form I have designed.

Any ideas?

Private Sub Text8_KeyPress(KeyAscii As Integer)
Label23.Caption = "" '*** this label is used elsewhere for warning
messages against that (8 in this case) text field
If KeyAscii = 27 Then '*** ESC to blank and step back
Text8.Text = ""
Text7.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
Text8.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii) 'this is a standard routine (Alib
is Alan library!) I have developed that treats ENTER and TAB the same. It
works fine
End Sub


The above all works fine. It's just that I want to avoid typing it all out
again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Bob Butler
2011-10-06 20:54:04 UTC
Permalink
Post by Dimmer
Hi all
I am trying to arrange to access this sub a number of times in a program.
The sub works fine in intercepting ESC and certain other keystrokes.
I want to somehow arrange to repeatedly use it and this instictively
suggests that it should be in a subroutine. But it is already in one! Is
there such a thing as nested subroutines? I want to call it and pass to it
the particular Textboxes and Label concerned. I emphasise that it works
fine but I just don't want to have to have it appearing 13 times in a 13
field form I have designed.
Any ideas?
Private Sub Text8_KeyPress(KeyAscii As Integer)
Label23.Caption = "" '*** this label is used elsewhere for warning
messages against that (8 in this case) text field
If KeyAscii = 27 Then '*** ESC to blank and step back
Text8.Text = ""
Text7.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
Text8.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii) 'this is a standard routine (Alib
is Alan library!) I have developed that treats ENTER and TAB the same. It
works fine
End Sub
First, do yourself a huge favor and rename your controls. "Text8" and
"Label23" will mean nothing when you look at the code 6 months from now.

Second, try something lie this:

Private Sub Text8_KeyPress(KeyAscii As Integer)
ProcessDelandEsc KeyAscii, Text7, Text8, Label23
End Sub

Private Sub ProcessDelandEsc(KeyAscii As Integer, _
ByVal TBack As TextBox, ByVal TCheck As TextBox, _
ByVal LWarn As Label)
LWarn.Caption = ""
If KeyAscii = 27 Then '*** ESC to blank and step back
TCheck.Text = ""
TBack.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
TCheck.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii)
End Sub
Dimmer
2011-10-06 23:39:28 UTC
Permalink
Thanks Bob. Looks like you have solved my problem with Process (a keyword I
was unfamiliar with) and By Val (an asepct that I am only just coming to
terms with.

I totally agree with you about giving Text boxes and Labels meaningful names
and I do in most of my projects. With this one, I have printed images of the
form and marked the text boxes and labels with their numeric (default)
names, precisely for the reason you say.

I'll try this later and let you know how I go.

Thanks again. A concise solution that I understand.
Post by Bob Butler
Post by Dimmer
Hi all
I am trying to arrange to access this sub a number of times in a program.
The sub works fine in intercepting ESC and certain other keystrokes.
I want to somehow arrange to repeatedly use it and this instictively
suggests that it should be in a subroutine. But it is already in one! Is
there such a thing as nested subroutines? I want to call it and pass to
it the particular Textboxes and Label concerned. I emphasise that it
works fine but I just don't want to have to have it appearing 13 times in
a 13 field form I have designed.
Any ideas?
Private Sub Text8_KeyPress(KeyAscii As Integer)
Label23.Caption = "" '*** this label is used elsewhere for warning
messages against that (8 in this case) text field
If KeyAscii = 27 Then '*** ESC to blank and step back
Text8.Text = ""
Text7.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
Text8.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii) 'this is a standard routine
(Alib is Alan library!) I have developed that treats ENTER and TAB the
same. It works fine
End Sub
First, do yourself a huge favor and rename your controls. "Text8" and
"Label23" will mean nothing when you look at the code 6 months from now.
Private Sub Text8_KeyPress(KeyAscii As Integer)
ProcessDelandEsc KeyAscii, Text7, Text8, Label23
End Sub
Private Sub ProcessDelandEsc(KeyAscii As Integer, _
ByVal TBack As TextBox, ByVal TCheck As TextBox, _
ByVal LWarn As Label)
LWarn.Caption = ""
If KeyAscii = 27 Then '*** ESC to blank and step back
TCheck.Text = ""
TBack.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
TCheck.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii)
End Sub
Bob Butler
2011-10-06 23:54:00 UTC
Permalink
Post by Dimmer
Thanks Bob. Looks like you have solved my problem with Process (a keyword
I was unfamiliar with)
'Process' is not a keyword; I just created a sub and named it
"ProcessDelAndESC" so that loking at the calling code I would have some idea
what it does. You can name it anything you like within the rules for
procedure and variable names.

Thorsten is right that a control array might also work for you; it depends
on what else you are doing with the controls. The more they have in common
the easier a conrol array would make things.
Post by Dimmer
and By Val (an asepct that I am only just coming to terms with.
'byval' and 'byref' are important to understand; I typically use ByVal out
of habit unless I need ByRef or performance is critical. Either would work
here and a case can be made that ByRef would be more efficient.
Post by Dimmer
I totally agree with you about giving Text boxes and Labels meaningful
names and I do in most of my projects. With this one, I have printed
images of the form and marked the text boxes and labels with their numeric
(default) names, precisely for the reason you say.
That's fine until you can't find the printed image
Dimmer
2011-10-07 00:34:18 UTC
Permalink
Thanks Bob for this further elucidation!
Post by Bob Butler
Post by Dimmer
Thanks Bob. Looks like you have solved my problem with Process (a keyword
I was unfamiliar with)
'Process' is not a keyword; I just created a sub and named it
"ProcessDelAndESC" so that loking at the calling code I would have some idea
Oh, I see. I was just going to look up the syntax for 'Process'!
Post by Bob Butler
what it does. You can name it anything you like within the rules for
procedure and variable names.
Thorsten is right that a control array might also work for you; it depends
on what else you are doing with the controls. The more they have in
common the easier a conrol array would make things.
Post by Dimmer
and By Val (an asepct that I am only just coming to terms with.
'byval' and 'byref' are important to understand; I typically use ByVal out
of habit unless I need ByRef or performance is critical. Either would
work here and a case can be made that ByRef would be more efficient.
(OK, got it)
Post by Bob Butler
Post by Dimmer
I totally agree with you about giving Text boxes and Labels meaningful
names and I do in most of my projects. With this one, I have printed
images of the form and marked the text boxes and labels with their
numeric (default) names, precisely for the reason you say.
That's fine until you can't find the printed image
What, with my super duper filing system! Impossible! Now, where on Earth
is my list of things to remember?.. On it I'm sure I have a note of where it
is?
Access Developer
2011-10-06 21:05:51 UTC
Permalink
Either I don't understand what you want to do, or (and I suspect this is the
case) you don't understand programming with VBA.

You can either put that Sub Procedure in the general section of the Form's
module or in a separate standard Module with a Control object and Label
object as arguments, and call it from an event of the textbox, passing the
textbox and label. If you put it in a standard module, you can call if from
code in multiple Forms' modules.
--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access
Post by Dimmer
Hi all
I am trying to arrange to access this sub a number of times in a program.
The sub works fine in intercepting ESC and certain other keystrokes.
I want to somehow arrange to repeatedly use it and this instictively
suggests that it should be in a subroutine. But it is already in one! Is
there such a thing as nested subroutines? I want to call it and pass to it
the particular Textboxes and Label concerned. I emphasise that it works
fine but I just don't want to have to have it appearing 13 times in a 13
field form I have designed.
Any ideas?
Private Sub Text8_KeyPress(KeyAscii As Integer)
Label23.Caption = "" '*** this label is used elsewhere for warning
messages against that (8 in this case) text field
If KeyAscii = 27 Then '*** ESC to blank and step back
Text8.Text = ""
Text7.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
Text8.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii) 'this is a standard routine (Alib
is Alan library!) I have developed that treats ENTER and TAB the same. It
works fine
End Sub
The above all works fine. It's just that I want to avoid typing it all out
again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Dimmer
2011-10-06 23:41:36 UTC
Permalink
Many thanks, but this is not VBA; it is VB6. I have been given the answer by
Bob (lloks like you are explaining much the same thing, but it is too
abstract for this newbie!. Bob has answered me in terms I can understand.

Thanks again for responding.
Post by Access Developer
Either I don't understand what you want to do, or (and I suspect this is
the case) you don't understand programming with VBA.
You can either put that Sub Procedure in the general section of the Form's
module or in a separate standard Module with a Control object and Label
object as arguments, and call it from an event of the textbox, passing the
textbox and label. If you put it in a standard module, you can call if
from code in multiple Forms' modules.
--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access
Post by Dimmer
Hi all
I am trying to arrange to access this sub a number of times in a program.
The sub works fine in intercepting ESC and certain other keystrokes.
I want to somehow arrange to repeatedly use it and this instictively
suggests that it should be in a subroutine. But it is already in one! Is
there such a thing as nested subroutines? I want to call it and pass to
it the particular Textboxes and Label concerned. I emphasise that it
works fine but I just don't want to have to have it appearing 13 times in
a 13 field form I have designed.
Any ideas?
Private Sub Text8_KeyPress(KeyAscii As Integer)
Label23.Caption = "" '*** this label is used elsewhere for warning
messages against that (8 in this case) text field
If KeyAscii = 27 Then '*** ESC to blank and step back
Text8.Text = ""
Text7.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
Text8.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii) 'this is a standard routine
(Alib is Alan library!) I have developed that treats ENTER and TAB the
same. It works fine
End Sub
The above all works fine. It's just that I want to avoid typing it all
out again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Access Developer
2011-10-07 03:49:38 UTC
Permalink
Yes, my mistyping. Glad it's "under control now". And, yes, VBA is nearly
identical to VB6 code, but the environment in which it runs (MS Office and
other apps) is different.
--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access
Post by Dimmer
Many thanks, but this is not VBA; it is VB6. I have been given the answer
by Bob (lloks like you are explaining much the same thing, but it is too
abstract for this newbie!. Bob has answered me in terms I can understand.
Thanks again for responding.
Post by Access Developer
Either I don't understand what you want to do, or (and I suspect this is
the case) you don't understand programming with VBA.
You can either put that Sub Procedure in the general section of the
Form's module or in a separate standard Module with a Control object and
Label object as arguments, and call it from an event of the textbox,
passing the textbox and label. If you put it in a standard module, you
can call if from code in multiple Forms' modules.
--
Larry Linson, Microsoft Office Access MVP
Co-author: "Microsoft Access Small Business Solutions", published by Wiley
Access newsgroup support is alive and well in USENET
comp.databases.ms-access
Post by Dimmer
Hi all
I am trying to arrange to access this sub a number of times in a program.
The sub works fine in intercepting ESC and certain other keystrokes.
I want to somehow arrange to repeatedly use it and this instictively
suggests that it should be in a subroutine. But it is already in one!
Is there such a thing as nested subroutines? I want to call it and pass
to it the particular Textboxes and Label concerned. I emphasise that it
works fine but I just don't want to have to have it appearing 13 times
in a 13 field form I have designed.
Any ideas?
Private Sub Text8_KeyPress(KeyAscii As Integer)
Label23.Caption = "" '*** this label is used elsewhere for warning
messages against that (8 in this case) text field
If KeyAscii = 27 Then '*** ESC to blank and step back
Text8.Text = ""
Text7.SetFocus
ElseIf KeyAscii <> 8 Then '***overtype
Text8.SelLength = 1
End If
Call AlibModule.EnterTabKey(KeyAscii) 'this is a standard routine
(Alib is Alan library!) I have developed that treats ENTER and TAB the
same. It works fine
End Sub
The above all works fine. It's just that I want to avoid typing it all
out again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Thorsten Albers
2011-10-06 23:16:49 UTC
Permalink
Post by Dimmer
The above all works fine. It's just that I want to avoid typing it all out
again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Either use the code of Bob or use control arrays. A control array is an
array of controls of the same control type in which all controls have the
same name but a different index number. To create a control array put the
control on a form and set its index property (usually to 0). With a control
array you have only _one_ event procedure for all controls of the array.
--
Thorsten Albers

gudea at gmx.de
Dimmer
2011-10-07 00:36:07 UTC
Permalink
Post by Thorsten Albers
Post by Dimmer
The above all works fine. It's just that I want to avoid typing it all
out
Post by Dimmer
again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Either use the code of Bob or use control arrays. A control array is an
array of controls of the same control type in which all controls have the
same name but a different index number. To create a control array put the
control on a form and set its index property (usually to 0). With a control
array you have only _one_ event procedure for all controls of the array.
--
Thorsten Albers
Right. Got that. That actually did occur to me, but because I am developing
the form on the fly, the arrany elemnts would get out of order, so I've not
done that when invited in the IDE! Thanks for this further point.
ralph
2011-10-07 04:58:04 UTC
Permalink
Post by Dimmer
Post by Thorsten Albers
Post by Dimmer
The above all works fine. It's just that I want to avoid typing it all
out
Post by Dimmer
again and again with different values for the LabelNo, TextNo, and
PriorTextNo.
Either use the code of Bob or use control arrays. A control array is an
array of controls of the same control type in which all controls have the
same name but a different index number. To create a control array put the
control on a form and set its index property (usually to 0). With a control
array you have only _one_ event procedure for all controls of the array.
--
Thorsten Albers
Right. Got that. That actually did occur to me, but because I am developing
the form on the fly, the arrany elemnts would get out of order, so I've not
done that when invited in the IDE! Thanks for this further point.
It is not necessary to be concerned the array elements "would get out
of order" for a Control Array. (Unlike, say a TabIndex.) To attach a
'name' for each specific control create an Enum at the top of your
Form source.

[Public | Private] Enum TextBoxEnum
eText1
eTextPictFour
eTextIn
eTextOut
End Enum
#If 0 Then ' include the following to preserve case
Private eText1, eTextPictFour, eTextIn, eTextOut
#End If

You can then go back and change 'order' or rename by simply editing
the Enum and doing a quick find and replace.

But it sounds like your real problem is the extra clicking and typing
in the beginning when you first add a control. You need to check out
MZTools at
http://www.mztools.com/v3/mztools3.aspx
[Price is right - Free.]

One of its many features is one where each time you add a control to a
form you are asked for the Name of the new control. MZTools will make
providing unique names and subsequent renaming of those controls very
convenient.
http://www.mztools.com/v3/features.aspx

I consider the MZTools Addon an absolute requirement for any VB
development.

-ralph
Dimmer
2011-10-08 08:37:55 UTC
Permalink
"ralph" <***@yahoo.net> wrote in message news:***@4ax.com...
You need to check out
Post by ralph
MZTools at
http://www.mztools.com/v3/mztools3.aspx
[Price is right - Free.]
One of its many features is one where each time you add a control to a
form you are asked for the Name of the new control. MZTools will make
providing unique names and subsequent renaming of those controls very
convenient.
http://www.mztools.com/v3/features.aspx
I consider the MZTools Addon an absolute requirement for any VB
development.
-ralph
Ralph, is there a foolproof procedure for *un*installing MZTools if I don't
like it. I just love the IDE as it is.

I am horrified by the comparative crudeness of Java, which I've had a look
at thinking it would be step forward.
ralph
2011-10-08 15:53:27 UTC
Permalink
Post by ralph
You need to check out
Post by ralph
MZTools at
http://www.mztools.com/v3/mztools3.aspx
[Price is right - Free.]
One of its many features is one where each time you add a control to a
form you are asked for the Name of the new control. MZTools will make
providing unique names and subsequent renaming of those controls very
convenient.
http://www.mztools.com/v3/features.aspx
I consider the MZTools Addon an absolute requirement for any VB
development.
-ralph
Ralph, is there a foolproof procedure for *un*installing MZTools if I don't
like it. I just love the IDE as it is.
Yes. From the VBIDE main menu go to Add Ons->Add On Manager and select
one of the unload options.

Installing MZTools does nothing magical or complex. It consists of one
DLL and a few Registry Entries. To completely remove MZTools you can
run the MZTools uninstaller or manually delete the DLL and Registery
Entries.

MZTools merely adds features MS forgot. You will love it.

-ralph

Dimmer
2011-10-07 01:15:09 UTC
Permalink
Hi again Bob

Looking at my code, I originally got most of it exactly as you have just
shown me but without the ByVal.

It now works fine (once I had realised that there's no space between By and
Val!) A great introduction to this concept.

Many thanks again. You approach in showing a practical snippet is just right
for me.
Dimmer
2011-10-07 01:32:48 UTC
Permalink
Also Bob, I have found out that if I use the word CALL it is OK as long as
the arguments are in brackets. Without CALL as in your example also works
but then brackets must not be used. I imagine that the two syntaxes are
optional?
Bob Butler
2011-10-07 02:28:34 UTC
Permalink
Post by Dimmer
Also Bob, I have found out that if I use the word CALL it is OK as long as
the arguments are in brackets. Without CALL as in your example also works
but then brackets must not be used. I imagine that the two syntaxes are
optional?
Correct

Call procedurename(argumentlist)
-or-
procedurename argumentlist
Deanna Earley
2011-10-07 08:17:09 UTC
Permalink
Post by Bob Butler
Post by Dimmer
Also Bob, I have found out that if I use the word CALL it is OK as
long as the arguments are in brackets. Without CALL as in your example
also works but then brackets must not be used. I imagine that the two
syntaxes are optional?
Correct
Call procedurename(argumentlist)
-or-
procedurename argumentlist
And just a warning that while mixing them is syntactically valid for one
parameter, it does NOT always do what you expect and will catch you out
with a bug at some point:
procedurename (argument)

It evaluates 'argument', which for objects, gets the default property,
and other types, converts to a variant with an implicit byval.
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
ralph
2011-10-07 15:26:22 UTC
Permalink
On Fri, 07 Oct 2011 09:17:09 +0100, Deanna Earley
Post by Deanna Earley
Post by Bob Butler
Post by Dimmer
Also Bob, I have found out that if I use the word CALL it is OK as
long as the arguments are in brackets. Without CALL as in your example
also works but then brackets must not be used. I imagine that the two
syntaxes are optional?
Correct
Call procedurename(argumentlist)
-or-
procedurename argumentlist
And just a warning that while mixing them is syntactically valid for one
parameter, it does NOT always do what you expect and will catch you out
procedurename (argument)
It evaluates 'argument', which for objects, gets the default property,
and other types, converts to a variant with an implicit byval.
Always a good warning.

Procedurename argument
is not semantically the same as
Procedurename (argument)

However, I disagree with the characterization that it is a 'bug' or
that the results should even be 'unexpected'. The grammatic rules for
calling VB procedures and using parathentheses are very clear. If one
doesn't follow the rules then surprises are to be expected. <g>

-ralph
Deanna Earley
2011-10-07 16:34:38 UTC
Permalink
Post by ralph
Procedurename argument
is not semantically the same as
Procedurename (argument)
However, I disagree with the characterization that it is a 'bug' or
that the results should even be 'unexpected'. The grammatic rules for
calling VB procedures and using parathentheses are very clear. If one
doesn't follow the rules then surprises are to be expected.<g>
Of course, but I expect people to not read/know the rules and so will
not be expecting defined behaviour :p
That and the amount of people I've had to tell this to when they were
bitten by it...
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
Deanna Earley
2011-10-07 16:37:04 UTC
Permalink
Post by Deanna Earley
Post by ralph
Procedurename argument
is not semantically the same as
Procedurename (argument)
However, I disagree with the characterization that it is a 'bug' or
that the results should even be 'unexpected'. The grammatic rules for
calling VB procedures and using parathentheses are very clear. If one
doesn't follow the rules then surprises are to be expected.<g>
Of course, but I expect people to not read/know the rules and so will
not be expecting defined behaviour :p
That and the amount of people I've had to tell this to when they were
bitten by it...
Oh, and by bug I meant a bug in people's code that has the () when it
shouldn't, not a bug in the VB libs/parsing.
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
ralph
2011-10-07 17:04:13 UTC
Permalink
On Fri, 07 Oct 2011 17:34:38 +0100, Deanna Earley
Post by Deanna Earley
Post by ralph
Procedurename argument
is not semantically the same as
Procedurename (argument)
However, I disagree with the characterization that it is a 'bug' or
that the results should even be 'unexpected'. The grammatic rules for
calling VB procedures and using parathentheses are very clear. If one
doesn't follow the rules then surprises are to be expected.<g>
Of course, but I expect people to not read/know the rules and so will
not be expecting defined behaviour :p
That and the amount of people I've had to tell this to when they were
bitten by it...
In the old days being bitten invariably resulted in some manager or
tech lead to decree - "Forthwith all Subroutine calls shall use the
Call keyword." <bg>

-ralph
Dimmer
2011-10-07 18:32:49 UTC
Permalink
Post by ralph
On Fri, 07 Oct 2011 09:17:09 +0100, Deanna Earley
Post by Deanna Earley
Post by Bob Butler
Post by Dimmer
Also Bob, I have found out that if I use the word CALL it is OK as
long as the arguments are in brackets. Without CALL as in your example
also works but then brackets must not be used. I imagine that the two
syntaxes are optional?
Correct
Call procedurename(argumentlist)
-or-
procedurename argumentlist
And just a warning that while mixing them is syntactically valid for one
parameter, it does NOT always do what you expect and will catch you out
procedurename (argument)
It evaluates 'argument', which for objects, gets the default property,
and other types, converts to a variant with an implicit byval.
Always a good warning.
Procedurename argument
is not semantically the same as
Procedurename (argument)
However, I disagree with the characterization that it is a 'bug' or
that the results should even be 'unexpected'. The grammatic rules for
calling VB procedures and using parathentheses are very clear. If one
doesn't follow the rules then surprises are to be expected. <g>
-ralph
My instinct is to use eg Call Bloggs(Arguments...) as it is clearer when
reading the code (well I think so anyway) so presumably that's OK?
ralph
2011-10-07 19:30:52 UTC
Permalink
Post by Dimmer
Post by ralph
On Fri, 07 Oct 2011 09:17:09 +0100, Deanna Earley
Post by Deanna Earley
Post by Bob Butler
Post by Dimmer
Also Bob, I have found out that if I use the word CALL it is OK as
long as the arguments are in brackets. Without CALL as in your example
also works but then brackets must not be used. I imagine that the two
syntaxes are optional?
Correct
Call procedurename(argumentlist)
-or-
procedurename argumentlist
And just a warning that while mixing them is syntactically valid for one
parameter, it does NOT always do what you expect and will catch you out
procedurename (argument)
It evaluates 'argument', which for objects, gets the default property,
and other types, converts to a variant with an implicit byval.
Always a good warning.
Procedurename argument
is not semantically the same as
Procedurename (argument)
However, I disagree with the characterization that it is a 'bug' or
that the results should even be 'unexpected'. The grammatic rules for
calling VB procedures and using parathentheses are very clear. If one
doesn't follow the rules then surprises are to be expected. <g>
-ralph
My instinct is to use eg Call Bloggs(Arguments...) as it is clearer when
reading the code (well I think so anyway) so presumably that's OK?
Due to the possiblilty of trouble as pointed out by Ms Earley, always
using the Call keyword with a subroutine or any function where you are
not expecting nor using a return value, is not a bad idea. Especially
when learning the language.

-ralph
Loading...