ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What is True ?? (https://www.excelbanter.com/excel-programming/371930-what-true.html)

Jakobshavn Isbrae

What is True ??
 
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

Gary Keramidas

What is True ??
 
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" wrote in
message ...
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

What is True ??
 
Jakobshavn Isbrae wrote:
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?


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



moon[_6_]

What is True ??
 

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" schreef in
bericht ...
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




Ron Rosenfeld

What is True ??
 
On Thu, 31 Aug 2006 17:13:01 -0700, Jakobshavn Isbrae
wrote:

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?


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

What is True ??
 
Thank you Franz.

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

Thanks again
--
jake


"Franz Verga" wrote:

Jakobshavn Isbrae wrote:
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?


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





All times are GMT +1. The time now is 09:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com