|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
problem with variableHi
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, Alexandre wrote:
Show quoteHide quote > Because there is no multiple assignment in VB (and because the logical> 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, 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). Duane Bozarth wrote:
Show quoteHide quote > And, btw, shows the willingness of VB to coerce types as needed> 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). sometimes when you really would rather (or at least would be better off if) it didn't... 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... On Wed, 6 Jul 2005 21:58:58 -0300, "Alexandre" <news.microsoft.com> Just for fun try this :-wrote: >Duane Bozarth, > >Thanks for the response. Private Sub Command1_Click() Dim A$, B$, C$ A$ = B$ = C$ Me.Print A$ End Sub > >Thanks for the response. ....and then try this for the first executable statement instead> Just for fun try this :- > > Private Sub Command1_Click() > Dim A$, B$, C$ > > A$ = B$ = C$ > Me.Print A$ > End Sub A$ = B$ = C$ = True and try to figure out why it prints what it does.<g> Rick 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)> >A$ = B$ = C$ = True > >and try to figure out why it prints what it does.<g> It really annoys me when I type '=' instead of '+' VB should not allow such coercion to strings
Show quote
Hide quote
"J French" <erew***@nowhere.uk> wrote in message It seems a bit funny reading this newsgroup all the things that VB 'should' 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 do and to note that .net does do these things :-) Michael "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message Yes, in many, many ways it's a shame they didn't make a VB compiler for .Netnews: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 :-) -- Reply to the group so all can participate VB.Net: "Fool me once..." "Bob Butler" <tiredofit@nospam.com> wrote in message They did, didn't they?news:eSm2pb1gFHA.4000@TK2MSFTNGP12.phx.gbl... > Yes, in many, many ways it's a shame they didn't make a VB compiler for > .Net Michael "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message No. As your last post pointed out, VB syntax is rejected. 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? -- Reply to the group so all can participate VB.Net: "Fool me once..." "Bob Butler" <tiredofit@nospam.com> wrote in message Don't you agree it should be rejected tho? You can't have it both ways, news:exS23R8gFHA.3448@TK2MSFTNGP12.phx.gbl... > No. As your last post pointed out, VB syntax is rejected. something that is compatible with current syntax but has new features. Michael "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message VB4 added new features and still ran most, if not all, VB3 code.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. 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..." "Bob Butler" <tiredofit@nospam.com> wrote in message Makes sense but I don't think MS would have been able to achieve what they 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. did with .net if they'd done that, certainly not for many years. It would have held it back too much. Michael 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 I don't follow that - if anything it would have been easier>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. ..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 "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message That's what they want you to believe. There is very little VB syntax thatnews: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. 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..." "Bob Butler" <tiredofit@nospam.com> wrote in message I don't think that's true. As an example, most of VB code can't work in 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. vb.net because it doesn't have reference counting. Michael "Michael C" <mculley@NOSPAMoptushome.com.au> wrote in message No, that has little or nothing to do with syntax. The loss of referencenews: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. 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..." "Alexandre" <news.microsoft.com> wrote in message consider it the same asnews:eGw2ZtogFHA.2152@TK2MSFTNGP14.phx.gbl... > Why A1 = -1 ? a1 = (a2 == 0); Michael
simple counter variable.
Search Engine CONTROL? Date Time Picker Question Nonmodal form on Modal form? Terminate a called DLL from within the DLL Adding a VB6 module to a VB.NET project Reszing form highlights combo box Application setup (deployment) wizard bug Flat File Processing Tab Question or is it? |
|||||||||||||||||||||||