Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Negative number

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

num1 = 5
num2 = 7
num3 = -4

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



Thanks Tom


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default 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



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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




  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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







  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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







  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Negative number

I tried this but VB said:

Type mismatch


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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




  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I subtract a negative number from a positive number? csanta Excel Discussion (Misc queries) 5 April 4th 23 10:15 AM
Change positive number to negative number Angie M. Excel Worksheet Functions 1 January 25th 10 05:49 AM
Converting Negative Number to Postive number Tedd Excel Worksheet Functions 7 September 2nd 09 04:34 PM
Converting a negative number to a positive number Barb Excel Discussion (Misc queries) 3 November 1st 07 02:20 AM
2003= negative number&2004= negative number How Do I Calculate gro Jason Excel Worksheet Functions 1 January 14th 05 05:24 PM


All times are GMT +1. The time now is 02:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright Š2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"