ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Negative number (https://www.excelbanter.com/excel-programming/291258-negative-number.html)

TJF[_3_]

Negative number
 
How can I recognize (in VB) a number is negative?

num1 = 5
num2 = 7
num3 = -4

If numx = "negative" then
......



Thanks Tom



Roger Whitehead[_4_]

Negative number
 
If numx < 0
?


--
HTH
Roger
Shaftesbury (UK)



"TJF" wrote in message
...
How can I recognize (in VB) a number is negative?

num1 = 5
num2 = 7
num3 = -4

If numx = "negative" then
.....



Thanks Tom





Rob van Gelder[_4_]

Negative number
 
Sgn(x) returns -1 when x is negative

1: Greater than zero
0: Equal to zero
-1: Less than zero


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"TJF" wrote in message
...
How can I recognize (in VB) a number is negative?

num1 = 5
num2 = 7
num3 = -4

If numx = "negative" then
.....



Thanks Tom





TJF[_3_]

Negative number
 
Thats it.

But there no way to use it like this:

If Sgn(num1) = -1 Or Sgn(num2) = -1 then
.....

only way is
If Sgn(num1) = -1 Then ....
If Sgn(num2) = -1 Then ....

thats terible


"Rob van Gelder" píše v diskusním
příspěvku ...
Sgn(x) returns -1 when x is negative

1: Greater than zero
0: Equal to zero
-1: Less than zero


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"TJF" wrote in message
...
How can I recognize (in VB) a number is negative?

num1 = 5
num2 = 7
num3 = -4

If numx = "negative" then
.....



Thanks Tom







Bob Phillips[_6_]

Negative number
 
This works fine

If Sgn(-1) = -1 Or Sgn(-2) - 1 Then
MsgBox "negatives"
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"TJF" wrote in message
...
Thats it.

But there no way to use it like this:

If Sgn(num1) = -1 Or Sgn(num2) = -1 then
....

only way is
If Sgn(num1) = -1 Then ....
If Sgn(num2) = -1 Then ....

thats terible


"Rob van Gelder" píše v diskusním
příspěvku ...
Sgn(x) returns -1 when x is negative

1: Greater than zero
0: Equal to zero
-1: Less than zero


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"TJF" wrote in message
...
How can I recognize (in VB) a number is negative?

num1 = 5
num2 = 7
num3 = -4

If numx = "negative" then
.....



Thanks Tom









Frank Kabel

Negative number
 
Hi
try
If (Sgn(num1) = -1) Or (Sgn(num2) = -1) then
....
end if

should work
Frank

TJF wrote:
Thats it.

But there no way to use it like this:

If Sgn(num1) = -1 Or Sgn(num2) = -1 then
....

only way is
If Sgn(num1) = -1 Then ....
If Sgn(num2) = -1 Then ....

thats terible


"Rob van Gelder" píše v
diskusním příspěvku ...
Sgn(x) returns -1 when x is negative

1: Greater than zero
0: Equal to zero
-1: Less than zero


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"TJF" wrote in message
...
How can I recognize (in VB) a number is negative?

num1 = 5
num2 = 7
num3 = -4

If numx = "negative" then
.....



Thanks Tom




TJF[_3_]

Negative number
 
Looks like I have problem with data declarations.

Do you know how can I change data declaration?
I know this

new = CDbl(old)

but I need something like this:

old = CDbl(old)
....but this of course dosnt work

is there something like this

old = set as double



Frank Kabel

Negative number
 
Hi
AFAIK it is not possible to change the variable's data type during
runtime

Frank

TJF wrote:
Looks like I have problem with data declarations.

Do you know how can I change data declaration?
I know this

new = CDbl(old)

but I need something like this:

old = CDbl(old)
...but this of course dosnt work

is there something like this

old = set as double




Bob Phillips[_6_]

Negative number
 
Declare old as Double, and Cast the variable when assigned, something like

old = CDbl(Range("A1").Value)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"TJF" wrote in message
...
Looks like I have problem with data declarations.

Do you know how can I change data declaration?
I know this

new = CDbl(old)

but I need something like this:

old = CDbl(old)
...but this of course dosnt work

is there something like this

old = set as double





TJF[_3_]

Negative number
 
What a shame
My problem is I have numx as Textbox and then this:

If Sgn(num1) = -1 Or Sgn(num2) = -1 then

dosnt work so only way for me is:

num1_new = CLng(num1)
num2_new = CLng(num2)

If Sgn(num1_new) = -1 Or Sgn(num2_new) = -1 then

is that?


"Frank Kabel" píse v diskusním príspevku
...
Hi
AFAIK it is not possible to change the variable's data type during
runtime

Frank

TJF wrote:
Looks like I have problem with data declarations.

Do you know how can I change data declaration?
I know this

new = CDbl(old)

but I need something like this:

old = CDbl(old)
...but this of course dosnt work

is there something like this

old = set as double






Bob Phillips[_6_]

Negative number
 
How about

Sgn(CDbl(TextBox1.Text))

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"TJF" wrote in message
...
What a shame
My problem is I have numx as Textbox and then this:

If Sgn(num1) = -1 Or Sgn(num2) = -1 then

dosnt work so only way for me is:

num1_new = CLng(num1)
num2_new = CLng(num2)

If Sgn(num1_new) = -1 Or Sgn(num2_new) = -1 then

is that?


"Frank Kabel" píse v diskusním príspevku
...
Hi
AFAIK it is not possible to change the variable's data type during
runtime

Frank

TJF wrote:
Looks like I have problem with data declarations.

Do you know how can I change data declaration?
I know this

new = CDbl(old)

but I need something like this:

old = CDbl(old)
...but this of course dosnt work

is there something like this

old = set as double








TJF[_3_]

Negative number
 
I tried this but VB said:

Type mismatch



Bob Phillips[_6_]

Negative number
 
It worked for me, so that means that I probably don't fully understand your
problem. Sorry.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"TJF" wrote in message
...
I tried this but VB said:

Type mismatch





Rob van Gelder[_4_]

Negative number
 
That should work. What is the content of TextBox1.Text? From the sounds of
things, it's not a number.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"TJF" wrote in message
...
I tried this but VB said:

Type mismatch






All times are GMT +1. The time now is 12:02 AM.

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