Home All Groups Group Topic Archive Search About

I must be blind -- what's wrong with this sub?

Author
10 Oct 2005 6:07 AM
LurfysMa
Please help. I am about to break something. I cannot see what's wrong
with this module.

I created an EXE project with one module, which contains:

Option Explicit
Public Sub Zzz(p1)
Debug.Print "p1 = " & p1
End Sub

From the Immediate window:

zzz(12)
p1 = 12

Good.

I change the code as follows:

Option Explicit
Public Sub Zzz(p1, p2)
Debug.Print "p1 = " & p1
End Sub

Now from the immediate window:

zzz(12,13)

Causes:

"Compiler error:"

"Expected: ="

What the heck is wrong?

--
For email, use Usenet-20031220@spamex.com

Author
10 Oct 2005 6:37 AM
Michael C
"LurfysMa" <invalid@invalid.invalid> wrote in message
news:4t0kk1lsbd43lergjaa0i131jat5aiq0qb@4ax.com...
> Now from the immediate window:
>
> zzz(12,13)

try
zzz 12,13

Michael
Author
10 Oct 2005 6:44 AM
Lorin
or
Call Zzz(12,13)    ' the other way to call a Sub

To the first Sub call the () means evaluate sort of like ByVal.
Then when you have two parameters the () is interpreted as trying to be part
of a Function call not a Sub.


Show quoteHide quote
"Michael C" wrote:

> "LurfysMa" <invalid@invalid.invalid> wrote in message
> news:4t0kk1lsbd43lergjaa0i131jat5aiq0qb@4ax.com...
> > Now from the immediate window:
> >
> > zzz(12,13)
>
> try
> zzz 12,13
>
> Michael
>
>
>
Author
10 Oct 2005 7:04 AM
LurfysMa
On Sun, 9 Oct 2005 23:44:03 -0700, "Lorin"
<Lo***@discussions.microsoft.com> wrote:

>
>or
>Call Zzz(12,13)    ' the other way to call a Sub
>
>To the first Sub call the () means evaluate sort of like ByVal.

Of course. I remember reading about that recently. For a constant
(literal), it makes no difference, but if it were a variable, the ()
wold cause it to pass the value rather than the variable even if the
parameter was defined as ByRef. Correct?

>Then when you have two parameters the () is interpreted as trying to be part
>of a Function call not a Sub.

So, since "(13)" can be an expression, it is taken that way, but
"(12,13)" is not a valid expression, so it is taken as function call
syntax. Quirky syntax rules. I would hate to write the parser.

Thanks for the help.

Show quoteHide quote
>"Michael C" wrote:
>
>> "LurfysMa" <invalid@invalid.invalid> wrote in message
>> news:4t0kk1lsbd43lergjaa0i131jat5aiq0qb@4ax.com...
>> > Now from the immediate window:
>> >
>> > zzz(12,13)
>>
>> try
>> zzz 12,13
>>
>> Michael
>>
>>
>>


--
For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 1:08 PM
Bob Butler
"LurfysMa" <invalid@invalid.invalid> wrote in message
news:5d4kk1tffrpda4ejqlihte2hteonk2kctr@4ax.com
> Of course. I remember reading about that recently. For a constant
> (literal), it makes no difference, but if it were a variable, the ()
> wold cause it to pass the value rather than the variable even if the
> parameter was defined as ByRef. Correct?

It has nothing to do with constant vs expression

> So, since "(13)" can be an expression, it is taken that way, but
> "(12,13)" is not a valid expression, so it is taken as function call
> syntax. Quirky syntax rules. I would hate to write the parser.

Nothing quirky about it at all.  VB has two syntaxes used to call a
subroutine (or a function when you are discarding the return value):

Call xyz(argumentlist)
xyz argumentlist

If you omit the CALL keyword then you are using the second syntax and
everything after the procedurename is the argument list.  In your case you
have
   zzz (12,13)
Note that VB inserted a space after 'zzz' which indicates that it is not
expecting () around the arguments.  It then attempts to resolve '(12,13)' as
an expression and fails.  You would get the same error if you did
   Call zzz((12,13),1)
since VB would be attempting to evaluate '(12,13)' as the first expression.
You can however use either of the following:
  zzz (10+2),13
  Call zzz((12),(10+3))

The 'byval' issue is more of a side effect.  If you have a ByRef paremeter
and you pass in an expression then on return VB can't update the expression
so it discards the changes.  That makes it effectively 'ByVal'.  For
example:
   zzz a,b ' pass variables (they will be updated if they are defined
'byref')
   zzz 12,13 ' constants can't be updated so are effectively byval
   zzz a+1,b+0 ' pass expressions which also can't be updated
   zzz (a),(b) ' pass simpler expressions
   Call zzz((a),(b)) ' pass expressions using CALL

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
10 Oct 2005 6:53 AM
LurfysMa
On Sun, 09 Oct 2005 23:07:09 -0700, LurfysMa <invalid@invalid.invalid>
wrote:

Show quoteHide quote
>Please help. I am about to break something. I cannot see what's wrong
>with this module.
>
>I created an EXE project with one module, which contains:
>
>Option Explicit
>Public Sub Zzz(p1)
>Debug.Print "p1 = " & p1
>End Sub
>
>From the Immediate window:
>
>zzz(12)
>p1 = 12
>
>Good.
>
>I change the code as follows:
>
>Option Explicit
>Public Sub Zzz(p1, p2)
>Debug.Print "p1 = " & p1
>End Sub
>
>Now from the immediate window:
>
>zzz(12,13)
>
>Causes:
>
>"Compiler error:"
>
>"Expected: ="
>
>What the heck is wrong?

OK, I finally realized one problem, but created another.

The "zzz(12,13)" statement fails because implicit calls to subs do not
use parentheses. So, I changed it to:

   zzz 12,13

This is in the Immediate window. Now I get a new error:

   Compile error:

  Expected variable or procedure, not project

Huh?

But if I put the exact same code into another sub, it works:



Option Explicit

Public Sub asd()
temp 12, 13
End Sub

Public Sub temp(p1, p2)
Debug.Print "p1 = " & p2
End Sub

Public Function zzz(p1, p2)
zzz = p1 + p2
End Function



Then in the Immediate window:

asd
p1 = 13


The "temp 12,13" works in one place, but not the other. Now I really
need to break something.

--
For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 7:11 AM
LurfysMa
On Sun, 09 Oct 2005 23:53:40 -0700, LurfysMa <invalid@invalid.invalid>
wrote:

Show quoteHide quote
>On Sun, 09 Oct 2005 23:07:09 -0700, LurfysMa <invalid@invalid.invalid>
>wrote:
>
>>Please help. I am about to break something. I cannot see what's wrong
>>with this module.
>>
>>I created an EXE project with one module, which contains:
>>
>>Option Explicit
>>Public Sub Zzz(p1)
>>Debug.Print "p1 = " & p1
>>End Sub
>>
>>From the Immediate window:
>>
>>zzz(12)
>>p1 = 12
>>
>>Good.
>>
>>I change the code as follows:
>>
>>Option Explicit
>>Public Sub Zzz(p1, p2)
>>Debug.Print "p1 = " & p1
>>End Sub
>>
>>Now from the immediate window:
>>
>>zzz(12,13)
>>
>>Causes:
>>
>>"Compiler error:"
>>
>>"Expected: ="
>>
>>What the heck is wrong?
>
>OK, I finally realized one problem, but created another.
>
>The "zzz(12,13)" statement fails because implicit calls to subs do not
>use parentheses. So, I changed it to:
>
>   zzz 12,13
>
>This is in the Immediate window. Now I get a new error:
>
>   Compile error:
>
>  Expected variable or procedure, not project
>
>Huh?
>
>But if I put the exact same code into another sub, it works:
>
>
>
>Option Explicit
>
>Public Sub asd()
>temp 12, 13
>End Sub
>
>Public Sub temp(p1, p2)
>Debug.Print "p1 = " & p2
>End Sub
>
>Public Function zzz(p1, p2)
>zzz = p1 + p2
>End Function
>
>
>
>Then in the Immediate window:
>
>asd
>p1 = 13
>
>
>The "temp 12,13" works in one place, but not the other. Now I really
>need to break something.

OK. I think I found the other error. I had been experimenting with
DLLs and named one "temp". Dumb.

I have deleted the DLL file, but do I need to unregister it?

--
For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 7:40 AM
Michael C
"LurfysMa" <invalid@invalid.invalid> wrote in message
news:rl4kk1paatjq0m70ndd5ur0f5kghoka8qq@4ax.com...
> I have deleted the DLL file, but do I need to unregister it?

You should have done that before deleting it.

Show quoteHide quote
>
> --
> For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 8:08 AM
LurfysMa
On Mon, 10 Oct 2005 17:40:00 +1000, "Michael C"
<mculley@NOSPAMoptushome.com.au> wrote:

>"LurfysMa" <invalid@invalid.invalid> wrote in message
>news:rl4kk1paatjq0m70ndd5ur0f5kghoka8qq@4ax.com...
>> I have deleted the DLL file, but do I need to unregister it?
>
>You should have done that before deleting it.

I see that now. Scanning the registry with regedit, I see that
something by that name is still in there.

Now I can't run regsrv32 with the "/u" option, right?

Is there some safe way for me to unregister that DLL?

>> --
>> For email, use Usenet-20031220@spamex.com
>


--
For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 8:56 AM
Michael Cole
LurfysMa wrote:
Show quoteHide quote
> On Mon, 10 Oct 2005 17:40:00 +1000, "Michael C"
> <mculley@NOSPAMoptushome.com.au> wrote:
>
>> "LurfysMa" <invalid@invalid.invalid> wrote in message
>> news:rl4kk1paatjq0m70ndd5ur0f5kghoka8qq@4ax.com...
>>> I have deleted the DLL file, but do I need to unregister it?
>>
>> You should have done that before deleting it.
>
> I see that now. Scanning the registry with regedit, I see that
> something by that name is still in there.
>
> Now I can't run regsrv32 with the "/u" option, right?
>
> Is there some safe way for me to unregister that DLL?

If it was deleted to the Recycle Bin, you could always retrieve it, and then
do the unregistering and deletion...

--
Regards,

Michael Cole
Author
10 Oct 2005 9:14 AM
LurfysMa
Show quote Hide quote
On Mon, 10 Oct 2005 18:56:52 +1000, "Michael Cole" <no***@hansen.com>
wrote:

>LurfysMa wrote:
>> On Mon, 10 Oct 2005 17:40:00 +1000, "Michael C"
>> <mculley@NOSPAMoptushome.com.au> wrote:
>>
>>> "LurfysMa" <invalid@invalid.invalid> wrote in message
>>> news:rl4kk1paatjq0m70ndd5ur0f5kghoka8qq@4ax.com...
>>>> I have deleted the DLL file, but do I need to unregister it?
>>>
>>> You should have done that before deleting it.
>>
>> I see that now. Scanning the registry with regedit, I see that
>> something by that name is still in there.
>>
>> Now I can't run regsrv32 with the "/u" option, right?
>>
>> Is there some safe way for me to unregister that DLL?
>
>If it was deleted to the Recycle Bin, you could always retrieve it, and then
>do the unregistering and deletion...

Good idea. I did that. It said the unregister succeeded. But then, I
repeated the command and it said it succeeded again, and again, etc.

It probably says "succeeded" if it's no longer registered even if it
never was, but it would be nicer to get a different message.

Thanks for the suggestion

--
For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 10:44 PM
Michael C
"LurfysMa" <invalid@invalid.invalid> wrote in message
news:03ckk19ah8d0j3r5rvtqmob1394groevcj@4ax.com...
> Good idea. I did that. It said the unregister succeeded. But then, I
> repeated the command and it said it succeeded again, and again, etc.
>
> It probably says "succeeded" if it's no longer registered even if it
> never was, but it would be nicer to get a different message.

That would just add extra unecessary complexity.

Michael
Author
10 Oct 2005 7:33 AM
Ralph
Show quote Hide quote
"LurfysMa" <invalid@invalid.invalid> wrote in message
news:9e3kk1l56somvjmibav556jf5oqpqti1pl@4ax.com...
> On Sun, 09 Oct 2005 23:07:09 -0700, LurfysMa <invalid@invalid.invalid>
> wrote:
>
> >Please help. I am about to break something. I cannot see what's wrong
> >with this module.
> >
> >I created an EXE project with one module, which contains:
> >
> >Option Explicit
> >Public Sub Zzz(p1)
> >Debug.Print "p1 = " & p1
> >End Sub
> >
> >From the Immediate window:
> >
> >zzz(12)
> >p1 = 12
> >
> >Good.
> >
> >I change the code as follows:
> >
> >Option Explicit
> >Public Sub Zzz(p1, p2)
> >Debug.Print "p1 = " & p1
> >End Sub
> >
> >Now from the immediate window:
> >
> >zzz(12,13)
> >
> >Causes:
> >
> >"Compiler error:"
> >
> >"Expected: ="
> >
> >What the heck is wrong?
>
> OK, I finally realized one problem, but created another.
>
> The "zzz(12,13)" statement fails because implicit calls to subs do not
> use parentheses. So, I changed it to:
>
>    zzz 12,13
>
> This is in the Immediate window. Now I get a new error:
>
>    Compile error:
>
>   Expected variable or procedure, not project
>
> Huh?
>
> But if I put the exact same code into another sub, it works:
>
>
>
> Option Explicit
>
> Public Sub asd()
> temp 12, 13
> End Sub
>
> Public Sub temp(p1, p2)
> Debug.Print "p1 = " & p2
> End Sub
>
> Public Function zzz(p1, p2)
> zzz = p1 + p2
> End Function
>
>
>
> Then in the Immediate window:
>
> asd
> p1 = 13
>
>
> The "temp 12,13" works in one place, but not the other. Now I really
> need to break something.
>
> --
> For email, use Usenet-20031220@spamex.com

I wasn't able to reproduce your error. Likely because I didn't reproduce
your exact steps. Not sure if this is what is happening in your case, but be
aware the Intermediate Window can have a long memory.

While playing you often need to stop and clear it out.

-ralph
Author
10 Oct 2005 8:10 AM
LurfysMa
On Mon, 10 Oct 2005 02:33:50 -0500, "Ralph"
<nt_consultin***@yahoo.com> wrote:

Show quoteHide quote
>
>"LurfysMa" <invalid@invalid.invalid> wrote in message
>news:9e3kk1l56somvjmibav556jf5oqpqti1pl@4ax.com...
>> On Sun, 09 Oct 2005 23:07:09 -0700, LurfysMa <invalid@invalid.invalid>
>> wrote:
>>
>> >Please help. I am about to break something. I cannot see what's wrong
>> >with this module.
>> >
>> >I created an EXE project with one module, which contains:
>> >
>> >Option Explicit
>> >Public Sub Zzz(p1)
>> >Debug.Print "p1 = " & p1
>> >End Sub
>> >
>> >From the Immediate window:
>> >
>> >zzz(12)
>> >p1 = 12
>> >
>> >Good.
>> >
>> >I change the code as follows:
>> >
>> >Option Explicit
>> >Public Sub Zzz(p1, p2)
>> >Debug.Print "p1 = " & p1
>> >End Sub
>> >
>> >Now from the immediate window:
>> >
>> >zzz(12,13)
>> >
>> >Causes:
>> >
>> >"Compiler error:"
>> >
>> >"Expected: ="
>> >
>> >What the heck is wrong?
>>
>> OK, I finally realized one problem, but created another.
>>
>> The "zzz(12,13)" statement fails because implicit calls to subs do not
>> use parentheses. So, I changed it to:
>>
>>    zzz 12,13
>>
>> This is in the Immediate window. Now I get a new error:
>>
>>    Compile error:
>>
>>   Expected variable or procedure, not project
>>
>> Huh?
>>
>> But if I put the exact same code into another sub, it works:
>>
>>
>>
>> Option Explicit
>>
>> Public Sub asd()
>> temp 12, 13
>> End Sub
>>
>> Public Sub temp(p1, p2)
>> Debug.Print "p1 = " & p2
>> End Sub
>>
>> Public Function zzz(p1, p2)
>> zzz = p1 + p2
>> End Function
>>
>>
>>
>> Then in the Immediate window:
>>
>> asd
>> p1 = 13
>>
>>
>> The "temp 12,13" works in one place, but not the other. Now I really
>> need to break something.
>>
>> --
>> For email, use Usenet-20031220@spamex.com
>
>I wasn't able to reproduce your error. Likely because I didn't reproduce
>your exact steps. Not sure if this is what is happening in your case, but be
>aware the Intermediate Window can have a long memory.

It turned out to be a stray DLL I had been fooling around with. My
mother always told me not to play with those kinds of DLLs, but would
I listen? Nooooooooo.

>While playing you often need to stop and clear it out.

By clear it out, do you mean Ctrl+A then Del?

Or something like closing the project?

--
For email, use Usenet-20031220@spamex.com
Author
10 Oct 2005 8:43 AM
Ralph
Show quote Hide quote
"LurfysMa" <invalid@invalid.invalid> wrote in message
news:2c8kk1p7k8mkdadca7f9m2fsv6lu9l6naa@4ax.com...
> On Mon, 10 Oct 2005 02:33:50 -0500, "Ralph"
> <nt_consultin***@yahoo.com> wrote:
>
> >
> >"LurfysMa" <invalid@invalid.invalid> wrote in message
> >news:9e3kk1l56somvjmibav556jf5oqpqti1pl@4ax.com...
> >> On Sun, 09 Oct 2005 23:07:09 -0700, LurfysMa <invalid@invalid.invalid>
> >> wrote:
> >>
> >> >Please help. I am about to break something. I cannot see what's wrong
> >> >with this module.
> >> >
> >> >I created an EXE project with one module, which contains:
> >> >
> >> >Option Explicit
> >> >Public Sub Zzz(p1)
> >> >Debug.Print "p1 = " & p1
> >> >End Sub
> >> >
> >> >From the Immediate window:
> >> >
> >> >zzz(12)
> >> >p1 = 12
> >> >
> >> >Good.
> >> >
> >> >I change the code as follows:
> >> >
> >> >Option Explicit
> >> >Public Sub Zzz(p1, p2)
> >> >Debug.Print "p1 = " & p1
> >> >End Sub
> >> >
> >> >Now from the immediate window:
> >> >
> >> >zzz(12,13)
> >> >
> >> >Causes:
> >> >
> >> >"Compiler error:"
> >> >
> >> >"Expected: ="
> >> >
> >> >What the heck is wrong?
> >>
> >> OK, I finally realized one problem, but created another.
> >>
> >> The "zzz(12,13)" statement fails because implicit calls to subs do not
> >> use parentheses. So, I changed it to:
> >>
> >>    zzz 12,13
> >>
> >> This is in the Immediate window. Now I get a new error:
> >>
> >>    Compile error:
> >>
> >>   Expected variable or procedure, not project
> >>
> >> Huh?
> >>
> >> But if I put the exact same code into another sub, it works:
> >>
> >>
> >>
> >> Option Explicit
> >>
> >> Public Sub asd()
> >> temp 12, 13
> >> End Sub
> >>
> >> Public Sub temp(p1, p2)
> >> Debug.Print "p1 = " & p2
> >> End Sub
> >>
> >> Public Function zzz(p1, p2)
> >> zzz = p1 + p2
> >> End Function
> >>
> >>
> >>
> >> Then in the Immediate window:
> >>
> >> asd
> >> p1 = 13
> >>
> >>
> >> The "temp 12,13" works in one place, but not the other. Now I really
> >> need to break something.
> >>
> >> --
> >> For email, use Usenet-20031220@spamex.com
> >
> >I wasn't able to reproduce your error. Likely because I didn't reproduce
> >your exact steps. Not sure if this is what is happening in your case, but
be
> >aware the Intermediate Window can have a long memory.
>
> It turned out to be a stray DLL I had been fooling around with. My
> mother always told me not to play with those kinds of DLLs, but would
> I listen? Nooooooooo.
>
> >While playing you often need to stop and clear it out.
>
> By clear it out, do you mean Ctrl+A then Del?
>
> Or something like closing the project?
>
> --
> For email, use Usenet-20031220@spamex.com

A select/delete usually does it.
Download MZTools and save a few keystrokes...
http://www.mztools.com/