forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Negative number?

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
dmonckton
Contributor
Contributor


Joined: 09 Aug 2002
Posts: 117
Location: Lewes, U.K.

PostPosted: Tue Jul 08, 2008 2:56 pm    Post subject: Negative number? Reply with quote

Hi

Is this function the best way (resource efficient) to test for a negative number?
Code:
:negative
    if @greater(%1,0)
        exit
    elsif @zero(%1)
        exit
    else
        exit 1
    end
    exit


Thanks

David...
Back to top
View user's profile Send private message
attreus
Valued Newbie


Joined: 30 Jul 2002
Posts: 46
Location: Berlin/Germany

PostPosted: Tue Jul 08, 2008 4:14 pm    Post subject: Reply with quote

how about with this:


Code:



:negative
    if @numeric(@substr(%1,1))
        exit
    else
        exit 1
    end


or better


:negative
    if @less(%1,0)
        exit 1
    else
        exit
    end





edit:

here is one for the lazy


Code:



:negative
   exit @less(%1,0)





another way would be


Code:



while @less(0,%1)

  ... do useful things such as
  wait

wend




Last edited by attreus on Wed Jul 09, 2008 2:05 am; edited 1 time in total
Back to top
View user's profile Send private message
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue Jul 08, 2008 5:50 pm    Post subject: Reply with quote

IMHO you should do the following...

Code:

:negative
  %R =
  %A = @pos(-,%1)
  if @Greater(%A,0)
   %R = 1
  End
Exit %R


Thanks,
Dragonsphere

_________________
Home of

Give VDS a new purpose!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
vdsalchemist
Admin Team


Joined: 23 Oct 2001
Posts: 1448
Location: Florida, USA

PostPosted: Tue Jul 08, 2008 5:53 pm    Post subject: Reply with quote

IMHO I don't think it a good idea to break out of a IF with the Exit command.

Thanks,
Dragonsphere
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
uvedese
Contributor
Contributor


Joined: 21 Jan 2006
Posts: 169
Location: Spain

PostPosted: Tue Jul 08, 2008 8:29 pm    Post subject: Reply with quote

What about this? Wink

Code:
:Negative
  if @equal(@substr(%1,1),"-")
    exit 1
  else
    exit
  end


_____________________

uVeDeSe
http://www.uvedese.es
______________________
Back to top
View user's profile Send private message Visit poster's website
dmonckton
Contributor
Contributor


Joined: 09 Aug 2002
Posts: 117
Location: Lewes, U.K.

PostPosted: Tue Jul 22, 2008 11:34 am    Post subject: Reply with quote

Thanks for all the ideas. I assume @less() is a VDS6 function? I have not moved on to VDS6 yet and not to sure I will!

Thanks again

David.M
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group