 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kostya Guest
|
|
| Back to top |
|
 |
somebody Guest
|
Posted: Mon Jul 25, 2005 1:36 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"Kostya" <thanks (AT) but_no_thanks (DOT) com> wrote
Ok, I'm curious: What's up with c = Not Check1.Value , and what's a static
sub for?
Even though I know next to nil about VB, most other things aren't too weird.
For instance you have to watch out for declarations in C too (which allows
for much more complex ones, btw), one just needs to unlearn the "other"
language and accept the new rules when switching tools.
|
|
| Back to top |
|
 |
Kostya Guest
|
Posted: Mon Jul 25, 2005 1:56 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
| Quote: | For instance you have to watch out for declarations in C too (which allows
for much more complex ones, btw), one just needs to unlearn the "other"
language and accept the new rules when switching tools.
|
However complex, C declarations have logic and make much more sense
IMO. Unless of course someone decides to go wild for purpose, but
that is possible with everything
Kostya
|
|
| Back to top |
|
 |
Erwien Saputra Guest
|
Posted: Mon Jul 25, 2005 3:41 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
somebody wrote:
| Quote: |
Ok, I'm curious: What's up with c = Not Check1.Value , and what's a
static sub for?
|
IIRC, a variable or a sub can be declared as static, the value of
static variable will be persisted after the sub is executed. The next
call to that sub will retain the value from the previous call. I think
static sub means all variables in that sub are static vars.
As for the checkbox, it seems that the value property is not a boolean
value, either variant or integer or something else.
disclaimer, I might be wrong here.... it has been years since I did my
programming in VB.
Wien.
|
|
| Back to top |
|
 |
Edmund Guest
|
Posted: Mon Jul 25, 2005 4:09 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
Erwien Saputra sighed and wrote::
| Quote: | somebody wrote:
Ok, I'm curious: What's up with c = Not Check1.Value , and what's a
static sub for?
IIRC, a variable or a sub can be declared as static, the value of
static variable will be persisted after the sub is executed. The next
|
Kinda like a global variable? But I don't understand how this
would apply to a procedure in VB (ok.. a sub in VB).
| Quote: | As for the checkbox, it seems that the value property is not a boolean
value, either variant or integer or something else.
|
I can't seem to wrap this in my head. You have a value property,
which when assigned to a boolean variable, it becomes a boolean.
Oh wait a sec. But since for the 2nd statement, the NOT takes
precedence before the assignment, and since the resulting
variable hasn't been assigned, the compiler doesn't know
what the future assignment variable is and thusly makes
checkbox1.value false (by default?) and then when NOT'd
it becomes true. It only takes on the property of a
boolean when it finally hits the assignment to a boolean
part of the statement. (How's that a wild stab in the
dark? I know.. just my imagination running wild. )
Talk about quantum duality. Schroedinger anyone?
Edmund
|
|
| Back to top |
|
 |
Dan Barclay Guest
|
Posted: Mon Jul 25, 2005 5:06 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"Edmund" <ed (AT) kdtc (DOT) net> wrote
| Quote: | Erwien Saputra sighed and wrote::
somebody wrote:
Ok, I'm curious: What's up with c = Not Check1.Value , and what's a
static sub for?
IIRC, a variable or a sub can be declared as static, the value of
static variable will be persisted after the sub is executed. The next
Kinda like a global variable? But I don't understand how this
would apply to a procedure in VB (ok.. a sub in VB).
|
No, a global variable has a global scope.
Think of variables in terms of both scope and lifetime, which are
independent. A Static variable has a lifetime of the app, but local scope.
There is also a static procedure in VB. That was created when they first
added callable subs (non static vars weren't working at release time of, as
I recall, QB2). A procedure marked Static causes all vars in the procedure
to be Static.
Dan
|
|
| Back to top |
|
 |
Dan Barclay Guest
|
Posted: Mon Jul 25, 2005 5:17 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"somebody" <somebody (AT) somewhere (DOT) com> wrote
If he can't understand what this is doing, he simply is trying to ignore the
syntax and behavior of the language. VB is not C, nor is it Pascal, or
FORTRAN. This fragment is completely predictable.
Checkbox.Value will return one of three values, 0, 1, or 2.
Boolean operators in Basic are bitwise and the result is *numeric*. "Not
0, 1, or 2" is always nonzero.
Boolean *tests* are based determined by 0=False, nonzero is True.
Boolean assignments using coercion (numeric to Boolean) are done by
testing the numeric value
| Quote: | Even though I know next to nil about VB, most other things aren't too
weird.
For instance you have to watch out for declarations in C too (which allows
for much more complex ones, btw), one just needs to unlearn the "other"
language and accept the new rules when switching tools.
|
Yes, no matter what you're coming from or going to the language behavior is
different. Otherwise it wouldn't be a different language<g>.
Dan
|
|
| Back to top |
|
 |
Dan Barclay Guest
|
Posted: Mon Jul 25, 2005 5:21 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"somebody" <somebody (AT) somewhere (DOT) com> wrote
Also, for more detail, look here:
http://vb.mvps.org/tips/truth.asp
Dan
|
|
| Back to top |
|
 |
Erwien Saputra Guest
|
Posted: Mon Jul 25, 2005 5:50 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
Edmund wrote:
| Quote: |
Kinda like a global variable? But I don't understand how this
would apply to a procedure in VB (ok.. a sub in VB).
|
Well, not exactly. The scope is still in that subs. I guess that it
may be useful when creating a recursive function.
| Quote: | I can't seem to wrap this in my head. You have a value property,
which when assigned to a boolean variable, it becomes a boolean.
Oh wait a sec. But since for the 2nd statement, the NOT takes
precedence before the assignment, and since the resulting
variable hasn't been assigned, the compiler doesn't know
what the future assignment variable is and thusly makes
checkbox1.value false (by default?) and then when NOT'd
it becomes true. It only takes on the property of a
boolean when it finally hits the assignment to a boolean
part of the statement. (How's that a wild stab in the
dark? I know.. just my imagination running wild. )
|
Look at Dan's reply. :)
Wien.
|
|
| Back to top |
|
 |
Richard Grossman Guest
|
Posted: Mon Jul 25, 2005 6:06 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
Actually, it's even *funnier* if you have coded a lot in VB.
My favorite quote from the article was:
"Dim I, J, K, L As Integer
"Actually (haha got you!) this doesn't work. This declares I, J, and K
as variants and only L as an Integer. This almost never matters, except
quite often."
Because I know this and also could not belive it the first time I
encountered it.
It's just a bug, plain and simple; there can be no good reason
whatsoever for this.
--
"Darmok and Jalad, at Tenagra"
|
|
| Back to top |
|
 |
Dan Barclay Guest
|
Posted: Mon Jul 25, 2005 7:42 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"Richard Grossman" <rgrossmanDELETE-THIS-PART (AT) techIII (DOT) com> wrote
| Quote: | Actually, it's even *funnier* if you have coded a lot in VB.
My favorite quote from the article was:
"Dim I, J, K, L As Integer
"Actually (haha got you!) this doesn't work. This declares I, J, and K as
variants and only L as an Integer. This almost never matters, except quite
often."
|
Actually, Bubba doesn't seem to understand that it *does* work, and it works
exactly as it's supposed to.
Yo-yo's like this make me chuckle. I'm a little surprised folks here latch
onto it though, some without trying to get a grip on what the defined
behavior is.
| Quote: | Because I know this and also could not belive it the first time I
encountered it.
It's just a bug, plain and simple; there can be no good reason whatsoever
for this.
|
Not a bug, any more than using ":=" for assignment (now *that's* weird<g>).
That statement performs exactly as it is designed.
Dim allows you to define multiple types in the same statement as in
Dim I as Integer, A as Double, etc.
In addition, declaring a variable without a type results in the default
type. I don't like defaults, but the default type is defined as Variant.
The statement above is exactly the same as:
Dim I
Dim J
Dim K
Dim L as integer
If you want to make language do strange things, you can do it nearly
anywhere particularly if you assume it should work in some way that is
different than it is defined.
Dan
|
|
| Back to top |
|
 |
Eric Grange Guest
|
Posted: Mon Jul 25, 2005 8:43 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
| Quote: | Yo-yo's like this make me chuckle. I'm a little surprised folks here latch
onto it though, some without trying to get a grip on what the defined
behavior is.
|
Well, don't be surprised, considering this behaviour to be anything but
a bug requires a peculiar way of thinking (or a particularly twisted
sense of humour), as it goes contrary to all language conventions, be
they for programming languages or for human (spoken/written) languages.
Eric
|
|
| Back to top |
|
 |
Oliver Townshend Guest
|
Posted: Mon Jul 25, 2005 8:46 am Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
Its actually not that hard. But obviously Basic is a bit too complex for
some.
Oliver
|
|
| Back to top |
|
 |
Kirk Halgren Guest
|
Posted: Mon Jul 25, 2005 12:33 pm Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"Dejan Stanic" <DS (AT) nospam (DOT) net> wrote
| Quote: | Erwien Saputra wrote:
IIRC, a variable or a sub can be declared as static, the value of
static variable will be persisted after the sub is executed. The next
call to that sub will retain the value from the previous call. I think
static sub means all variables in that sub are static vars.
Ah, pretty much the same as OP's
procedure ToggleSomething;
const
toggler : boolean = false;
begin
toggler := not toggler;
end;
|
You'll need {$J+} engaged for this to compile.
--
Kirk Halgren
"I'm out to make a living, not a killing."
-- Bob Wallace, Architect for Microsoft Pascal (circa mid 1980s),
popularizer of the term 'shareware'
|
|
| Back to top |
|
 |
somebody Guest
|
Posted: Mon Jul 25, 2005 12:46 pm Post subject: Re: OMG. I am glad I never had to dealt with it |
|
|
"Dan Barclay" <Dan (AT) MVPs (DOT) org> wrote
| Quote: | "somebody" <somebody (AT) somewhere (DOT) com> wrote
"Kostya" <thanks (AT) but_no_thanks (DOT) com> wrote
http://www.ddj.com/documents/s=1503/ddj0001vs/jan00.htm
Ok, I'm curious: What's up with c = Not Check1.Value ,
If he can't understand what this is doing, he simply is trying to ignore
the
syntax and behavior of the language. VB is not C, nor is it Pascal, or
FORTRAN. This fragment is completely predictable.
Checkbox.Value will return one of three values, 0, 1, or 2.
|
There you have it. Now it makes perfect sense, thanks (I was carrying my OP
baggage so I automatically assumed Value is a boolean property).
In light of this new info, I don't understand why the author was
complaining. It's ignorance coupled with wrong assumptions (being ignorant
of one's ignorance, as was in my case) that leads to such misuse/mistakes.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|