Home All Groups Group Topic Archive Search About
Author
7 Jul 2005 12:32 AM
Alexandre
Hi

I have a strange problem that I would appreciate any help

Dim a1 As Currency
Dim a2 As Currency

a1  =  a2  =  0

' result:  a1 = -1 ???

' result:  a2 = 0


Why A1 = -1 ?

Thanks & Regards,

Author
7 Jul 2005 12:33 AM
Duane Bozarth
Alexandre wrote:
Show quoteHide quote
>
> Hi
>
> I have a strange problem that I would appreciate any help
>
> Dim a1 As Currency
> Dim a2 As Currency
>
> a1  =  a2  =  0
>
> ' result:  a1 = -1 ???
>
> ' result:  a2 = 0
>
> Why A1 = -1 ?
>
> Thanks & Regards,

Because there is no multiple assignment in VB (and because the logical
equality operator is the same as the assignment operator it's possible
to misread the meaning easily).

a1  =  a2  =  0 actually means

a1  =  (a2  =  0)

Since variables in VB are (guaranteed) initialized to 0 on creation, a2
==0 so a1 is True and True is numerically -1 (all bits set).
Author
7 Jul 2005 12:44 AM
Duane Bozarth
Duane Bozarth wrote:
Show quoteHide quote
>
> Alexandre wrote:
> >
> > Hi
> >
> > I have a strange problem that I would appreciate any help
> >
> > Dim a1 As Currency
> > Dim a2 As Currency
> >
> > a1  =  a2  =  0
> >
> > ' result:  a1 = -1 ???
> >
> > ' result:  a2 = 0
> >
> > Why A1 = -1 ?
> >
> > Thanks & Regards,
>
> Because there is no multiple assignment in VB (and because the logical
> equality operator is the same as the assignment operator it's possible
> to misread the meaning easily).
>
>  a1  =  a2  =  0 actually means
>
>  a1  =  (a2  =  0)
>
> Since variables in VB are (guaranteed) initialized to 0 on creation, a2
> ==0 so a1 is True and True is numerically -1 (all bits set).

And, btw, shows the willingness of VB to coerce types as needed
sometimes when you really would rather (or at least would be better off
if) it didn't...
Author
7 Jul 2005 12:58 AM
Alexandre
Duane Bozarth,

Thanks for the response.



Show quoteHide quote
"Duane Bozarth" <dpboza***@swko.dot.net> escreveu na mensagem
news:42CC7AFF.5B516E95@swko.dot.net...
> Duane Bozarth wrote:
>>
>> Alexandre wrote:
>> >
>> > Hi
>> >
>> > I have a strange problem that I would appreciate any help
>> >
>> > Dim a1 As Currency
>> > Dim a2 As Currency
>> >
>> > a1  =  a2  =  0
>> >
>> > ' result:  a1 = -1 ???
>> >
>> > ' result:  a2 = 0
>> >
>> > Why A1 = -1 ?
>> >
>> > Thanks & Regards,
>>
>> Because there is no multiple assignment in VB (and because the logical
>> equality operator is the same as the assignment operator it's possible
>> to misread the meaning easily).
>>
>>  a1  =  a2  =  0 actually means
>>
>>  a1  =  (a2  =  0)
>>
>> Since variables in VB are (guaranteed) initialized to 0 on creation, a2
>> ==0 so a1 is True and True is numerically -1 (all bits set).
>
> And, btw, shows the willingness of VB to coerce types as needed
> sometimes when you really would rather (or at least would be better off
> if) it didn't...
Author
7 Jul 2005 7:09 AM
J French
On Wed, 6 Jul 2005 21:58:58 -0300, "Alexandre" <news.microsoft.com>
wrote:

>Duane Bozarth,
>
>Thanks for the response.
Just for fun try this :-

Private Sub Command1_Click()
   Dim A$, B$, C$

   A$ = B$ = C$
   Me.Print A$
End Sub
Author
7 Jul 2005 8:00 AM
Rick Rothstein
> >Thanks for the response.
> Just for fun try this :-
>
> Private Sub Command1_Click()
>    Dim A$, B$, C$
>
>    A$ = B$ = C$
>    Me.Print A$
> End Sub

....and then try this for the first executable statement instead

A$ = B$ = C$ = True

and try to figure out why it prints what it does.<g>

Rick
Author
7 Jul 2005 9:40 AM
J French
On Thu, 7 Jul 2005 04:00:10 -0400, "Rick Rothstein"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote:

<snip>

>...and then try this for the first executable statement instead
>
>A$ = B$ = C$ = True
>
>and try to figure out why it prints what it does.<g>

A$ = ((B$ = C$) = True)

It really annoys me when I type '=' instead of '+'

VB should not allow such coercion to strings
Author
7 Jul 2005 11:57 PM
Michael C
Show quote Hide quote
"J French" <erew***@nowhere.uk> wrote in message
news:42ccf8b1.186960254@news.btopenworld.com...
> On Thu, 7 Jul 2005 04:00:10 -0400, "Rick Rothstein"
> <rickNOSPAMnews@NOSPAMcomcast.net> wrote:
>
> <snip>
>
>>...and then try this for the first executable statement instead
>>
>>A$ = B$ = C$ = True
>>
>>and try to figure out why it prints what it does.<g>
>
> A$ = ((B$ = C$) = True)
>
> It really annoys me when I type '=' instead of '+'
>
> VB should not allow such coercion to strings

It seems a bit funny reading this newsgroup all the things that VB 'should'
do and to note that .net does do these things :-)

Michael
Author
8 Jul 2005 12:49 AM
Bob Butler
"Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message
news:uDz7L80gFHA.3164@TK2MSFTNGP15.phx.gbl
> It seems a bit funny reading this newsgroup all the things that VB
> 'should' do and to note that .net does do these things :-)

Yes, in many, many ways it's a shame they didn't make a VB compiler for .Net

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
8 Jul 2005 3:44 AM
Michael C
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:eSm2pb1gFHA.4000@TK2MSFTNGP12.phx.gbl...
> Yes, in many, many ways it's a shame they didn't make a VB compiler for
> .Net

They did, didn't they?

Michael
Author
8 Jul 2005 1:53 PM
Bob Butler
"Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message
news:e6T%23E72gFHA.1432@TK2MSFTNGP10.phx.gbl
> "Bob Butler" <tiredofit@nospam.com> wrote in message
> news:eSm2pb1gFHA.4000@TK2MSFTNGP12.phx.gbl...
>> Yes, in many, many ways it's a shame they didn't make a VB compiler
>> for .Net
>
> They did, didn't they?

No.  As your last post pointed out, VB syntax is rejected. 

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
10 Jul 2005 11:24 PM
Michael C
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:exS23R8gFHA.3448@TK2MSFTNGP12.phx.gbl...
> No.  As your last post pointed out, VB syntax is rejected.

Don't you agree it should be rejected tho? You can't have it both ways,
something that is compatible with current syntax but has new features.

Michael
Author
11 Jul 2005 1:27 AM
Bob Butler
"Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message
news:OJq2hXahFHA.2424@TK2MSFTNGP09.phx.gbl
> "Bob Butler" <tiredofit@nospam.com> wrote in message
> news:exS23R8gFHA.3448@TK2MSFTNGP12.phx.gbl...
>> No.  As your last post pointed out, VB syntax is rejected.
>
> Don't you agree it should be rejected tho? You can't have it both
> ways, something that is compatible with current syntax but has new
> features.

VB4 added new features and still ran most, if not all, VB3 code.
VB5 added new features and still ran VB4 code.
VB6 added new features and still ran VB5 code.

Most every language I've ever used evolved over time with new versions
accepting existing code while supporting new features.  When some syntax did
need to be dropped for some reason it was still supported for at least 1 or
2 versions with the compiler reporting warnings that the syntax was
deprecated and would not be supported in the next version.  That's how
vendors actually *support* a language and allow developers to move along
easily into new versions.  What MS did with VB.Net was something totally
different.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
11 Jul 2005 4:09 AM
Michael C
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:et7A1ebhFHA.3316@TK2MSFTNGP14.phx.gbl...
> Most every language I've ever used evolved over time with new versions
> accepting existing code while supporting new features.  When some syntax
> did
> need to be dropped for some reason it was still supported for at least 1
> or
> 2 versions with the compiler reporting warnings that the syntax was
> deprecated and would not be supported in the next version.  That's how
> vendors actually *support* a language and allow developers to move along
> easily into new versions.  What MS did with VB.Net was something totally
> different.

Makes sense but I don't think MS would have been able to achieve what they
did with .net if they'd done that, certainly not for many years. It would
have held it back too much.

Michael
Author
11 Jul 2005 10:03 AM
J French
On Mon, 11 Jul 2005 14:09:00 +1000, "Michael C"
<mculley@NOSPAMoptushome.com.au> wrote:

Show quoteHide quote
>"Bob Butler" <tiredofit@nospam.com> wrote in message
>news:et7A1ebhFHA.3316@TK2MSFTNGP14.phx.gbl...
>> Most every language I've ever used evolved over time with new versions
>> accepting existing code while supporting new features.  When some syntax
>> did
>> need to be dropped for some reason it was still supported for at least 1
>> or
>> 2 versions with the compiler reporting warnings that the syntax was
>> deprecated and would not be supported in the next version.  That's how
>> vendors actually *support* a language and allow developers to move along
>> easily into new versions.  What MS did with VB.Net was something totally
>> different.

>Makes sense but I don't think MS would have been able to achieve what they
>did with .net if they'd done that, certainly not for many years. It would
>have held it back too much.

I don't follow that - if anything it would have been easier

..NET is a combination of two things, one is a layer or 'slice' that
permits MS to port to different hardware, that is the long term goal

The other is a collection of languages that run on (or can compile
for) the 'slice'

If anything, it would have been easier to just create a VB7 that does
exactly the same as VB6 but produces .NET PCode
- reverse engineering ones own system is not that difficult
Author
11 Jul 2005 1:33 PM
Bob Butler
"Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message
news:O1koS2chFHA.3256@TK2MSFTNGP12.phx.gbl
> Makes sense but I don't think MS would have been able to achieve what
> they did with .net if they'd done that, certainly not for many years.
> It would have held it back too much.

That's what they want you to believe.  There is very little VB syntax that
could not have been implemented unchanged if they had any interest in
supporting the development community at all.  The fact that they didn't
tells me that they have zero regard for VB as a language and that I should
definitely look elsewhere for whatever I use next.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
12 Jul 2005 4:16 AM
Michael C
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:OPQ3c0hhFHA.3544@TK2MSFTNGP15.phx.gbl...
> That's what they want you to believe.  There is very little VB syntax that
> could not have been implemented unchanged if they had any interest in
> supporting the development community at all.  The fact that they didn't
> tells me that they have zero regard for VB as a language and that I should
> definitely look elsewhere for whatever I use next.

I don't think that's true. As an example, most of VB code can't work in
vb.net because it doesn't have reference counting.

Michael
Author
12 Jul 2005 1:45 PM
Bob Butler
"Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message
news:essUJfphFHA.1052@TK2MSFTNGP10.phx.gbl
> "Bob Butler" <tiredofit@nospam.com> wrote in message
> news:OPQ3c0hhFHA.3544@TK2MSFTNGP15.phx.gbl...
>> That's what they want you to believe.  There is very little VB
>> syntax that could not have been implemented unchanged if they had
>> any interest in supporting the development community at all.  The
>> fact that they didn't tells me that they have zero regard for VB as
>> a language and that I should definitely look elsewhere for whatever
>> I use next.
>
> I don't think that's true. As an example, most of VB code can't work
> in vb.net because it doesn't have reference counting.

No, that has little or nothing to do with syntax.  The loss of reference
counting will affect the design of many apps and would be a (big) hurdle to
overcome in moving from VB6 to a hypothetical VB7 but it is an issue that
relates to a change in the underlying platform.  What I'm talking about is
the gratuitous changes made in the syntax like
Dim X(1 To 5) As String

See http://vb.mvps.org/vfred/breaks.asp for a lot more; a large number of
the breaking changes were simply not required to move to the new platform
and yet require rewriting extensive quantities of code.  Even where the
syntax is accepted you have to be careful. case in point: the DateDiff
function, provided in a VB6 compatibility library, returns different results
for the same values.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
7 Jul 2005 6:29 AM
Michael C
"Alexandre" <news.microsoft.com> wrote in message
news:eGw2ZtogFHA.2152@TK2MSFTNGP14.phx.gbl...
> Why A1 = -1 ?

consider it the same as

a1 = (a2 == 0);

Michael