Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is True ??

48 views
Skip to first unread message

Jakobshavn Isbrae

unread,
Aug 31, 2006, 8:13:01 PM8/31/06
to
I run this
Sub macro()
Dim t As Integer
Dim t2 As Integer
t = 1
t2 = (t = 1) * 7
MsgBox (t2)
End Sub

and it says -7, not 7

Why?

--
jake

Franz Verga

unread,
Aug 31, 2006, 8:25:12 PM8/31/06
to

Because in VBA TRUE = -1, while in Excel TRUE = 1, so when you write t=1 its
TRUE and than you multiply TRUE (i.e. -1) times 7...


--
Hope I helped you.

Thanks in advance for your feedback.

Ciao

Franz Verga from Italy


Gary Keramidas

unread,
Aug 31, 2006, 8:25:02 PM8/31/06
to
i'd guess and say the () change it to a negative number but i don't know why
you;re doing that anyway

t2 = (t * 7)

is all you need

--


Gary


"Jakobshavn Isbrae" <Jakobsha...@discussions.microsoft.com> wrote in
message news:7F12D31B-9960-405F...@microsoft.com...

moon

unread,
Aug 31, 2006, 8:26:42 PM8/31/06
to

Because you cannot assign a value to multiple variables in a oneliner like
in C++.
You already gave t a value of 1.
Why do you do that again in t2 = (t=1) * 7


This one gives 7.

Sub macro()
Dim t As Integer
Dim t2 As Integer
t = 1

t2 = t * 7
MsgBox (t2)
End Sub

"Jakobshavn Isbrae" <Jakobsha...@discussions.microsoft.com> schreef in
bericht news:7F12D31B-9960-405F...@microsoft.com...

Ron Rosenfeld

unread,
Aug 31, 2006, 8:27:22 PM8/31/06
to

From VBA HELP:

"When Boolean values are converted to other data types, False becomes 0 and
True becomes -1."

So your formula reduces to:

t2 = -1 * 7

t2 = -7


--ron

Jakobshavn Isbrae

unread,
Aug 31, 2006, 8:36:01 PM8/31/06
to
Thank you Franz.

I did not know the booleans had different number values in VBA.

Thanks again
--
jake

0 new messages