Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert negative integer to positive in vb

Status
Not open for further replies.

cm80

Technical User
May 3, 2001
85
US
Hi
I would apppreciate it if someone could show me the code to find the differrence between numbers adn then convert tht answer to a positive integer. Thanks
 
Hi,
To convert a negative to a positive you could use abs()statement(absolute value). To convert to Integer use to
Cint() statement
e.g.
Text1.Text = CInt(Abs(MyNum1 - MyNum2))

Jon
 
intA = -12
intB = -36
intC = ABS(inta - intB)

Is this what you are asking?
 
If isnumeric(x) then
if x<0 then
'x it's negative
x=abs(x) ' convert it
elseif x=0 then
'x it's 0
else
'x>0
endif
endif

if You want to sure the received value it's a number in the Validate event (or in the Exit) transform it:
me.txtX=Val(me.txtX)
 
I guess you could use something like
x=abs(x)
y=abs(y)
z=abs(x-y)
 
I guess you could use something like
x=abs(x)
y=abs(y)
z=abs(x-y)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top