Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Negative number
I tried this but VB said:
Type mismatch |
#13
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I subtract a negative number from a positive number? | Excel Discussion (Misc queries) | |||
Change positive number to negative number | Excel Worksheet Functions | |||
Converting Negative Number to Postive number | Excel Worksheet Functions | |||
Converting a negative number to a positive number | Excel Discussion (Misc queries) | |||
2003= negative number&2004= negative number How Do I Calculate gro | Excel Worksheet Functions |